From 2e7673aa994f1f0227cfd2fc8953606962db127a Mon Sep 17 00:00:00 2001 From: shy3130 Date: Sun, 23 Aug 2026 19:36:00 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=20PR=20#193=20?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=90=8E=E7=9A=84=2012=20=E4=B8=AA=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20(alerts=20=E5=8F=82=E6=95=B0/None=20=E8=AF=AD?= =?UTF-8?q?=E4=B9=89/=E8=87=AA=E5=8C=85=E5=90=AB=E6=8F=92=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_ai_provider.py | 14 +++++++++---- backend/tests/test_custom_loader_install.py | 21 ++++++++++++++++--- .../tests/test_strategy_required_history.py | 1 - 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/backend/tests/test_ai_provider.py b/backend/tests/test_ai_provider.py index 656a03a..fcdc0b8 100644 --- a/backend/tests/test_ai_provider.py +++ b/backend/tests/test_ai_provider.py @@ -281,9 +281,10 @@ def test_ai_settings_keep_provider_models_separate(monkeypatch): # ── 输出上限 / 上下文窗口配置 ───────────────────────────────── -def test_resolve_max_tokens_defaults_to_config_cap(monkeypatch): +def test_resolve_max_tokens_none_stays_unlimited(monkeypatch): + """None = 不传上限(推理模型放开) — 不能被映射成配置上限, 见 main 语义。""" monkeypatch.setattr(ai_provider, "current_ai_max_output_tokens", lambda: 8192) - assert ai_provider._resolve_max_tokens(None) == 8192 + assert ai_provider._resolve_max_tokens(None) is None def test_resolve_max_tokens_clamps_above_cap(monkeypatch): @@ -339,7 +340,8 @@ async def test_generate_ai_text_clamps_max_tokens_to_config_cap(monkeypatch): @pytest.mark.asyncio -async def test_generate_ai_text_defaults_to_config_cap(monkeypatch): +async def test_generate_ai_text_default_cap_and_none_passthrough(monkeypatch): + """默认 3000 且被钳制; 显式 None 贯穿为不限制。""" captured: dict = {} monkeypatch.setattr(ai_provider, "is_codex_cli_provider", lambda: False) monkeypatch.setattr(ai_provider, "current_ai_max_output_tokens", lambda: 4000) @@ -351,7 +353,11 @@ async def test_generate_ai_text_defaults_to_config_cap(monkeypatch): monkeypatch.setattr(ai_provider, "_run_openai_once", fake_run) await ai_provider.generate_ai_text([{"role": "user", "content": "hi"}]) - assert captured["max_tokens"] == 4000 + assert captured["max_tokens"] == 3000 # 默认值, 未超 cap 原样下发 + await ai_provider.generate_ai_text( + [{"role": "user", "content": "hi"}], max_tokens=None, + ) + assert captured["max_tokens"] is None # None = 推理模型放开, 不钳制 def test_save_ai_settings_persists_token_sizes(monkeypatch): diff --git a/backend/tests/test_custom_loader_install.py b/backend/tests/test_custom_loader_install.py index b037326..9784079 100644 --- a/backend/tests/test_custom_loader_install.py +++ b/backend/tests/test_custom_loader_install.py @@ -31,8 +31,21 @@ def _patch_uv_install(monkeypatch, returncodes): return calls -def test_install_plugin_uv_targets_running_interpreter(monkeypatch): +def _fake_python_plugin(monkeypatch, tmp_path): + """在临时目录铺设最小 python 插件, 并把 plugins_dir 指过去 (自包含)。""" + pdir = tmp_path / "baostock" + pdir.mkdir() + (pdir / "plugin.yaml").write_text( + "name: baostock\nruntime: python\nentry: p:provider\n", encoding="utf-8", + ) + (pdir / "requirements.txt").write_text("baostock\n", encoding="utf-8") + monkeypatch.setattr(loader, "plugins_dir", lambda: tmp_path) + return pdir + + +def test_install_plugin_uv_targets_running_interpreter(monkeypatch, tmp_path): """uv 分支必须传 --python sys.executable, 不能留给 uv 自动探测。""" + _fake_python_plugin(monkeypatch, tmp_path) calls = _patch_uv_install(monkeypatch, [0]) ok, msg = loader.install_plugin("baostock") @@ -45,8 +58,9 @@ def test_install_plugin_uv_targets_running_interpreter(monkeypatch): assert uv_cmd[idx + 1] == sys.executable -def test_install_plugin_uv_retry_keeps_python_target(monkeypatch): +def test_install_plugin_uv_retry_keeps_python_target(monkeypatch, tmp_path): """exit 2 → --no-config 重试时也必须保持 --python 目标。""" + _fake_python_plugin(monkeypatch, tmp_path) calls = _patch_uv_install(monkeypatch, [2, 0]) ok, msg = loader.install_plugin("baostock") @@ -58,7 +72,7 @@ def test_install_plugin_uv_retry_keeps_python_target(monkeypatch): assert cmd[idx + 1] == sys.executable -def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch): +def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch, tmp_path): """uv 卸载同样必须传 --python sys.executable, 否则会动到基础解释器。""" calls: list[list[str]] = [] @@ -69,6 +83,7 @@ def test_uninstall_plugin_uv_targets_running_interpreter(monkeypatch): calls.append(list(cmd)) return subprocess.CompletedProcess(cmd, 0) + _fake_python_plugin(monkeypatch, tmp_path) monkeypatch.setattr(loader.shutil, "which", fake_which) monkeypatch.setattr(loader.subprocess, "run", fake_run) diff --git a/backend/tests/test_strategy_required_history.py b/backend/tests/test_strategy_required_history.py index aa4813c..41be524 100644 --- a/backend/tests/test_strategy_required_history.py +++ b/backend/tests/test_strategy_required_history.py @@ -36,7 +36,6 @@ def _filter_history_strategy( trailing_take_profit_activate=None, trailing_take_profit_drawdown=None, max_hold_days=None, - alerts=[], filter_fn=None, filter_history_fn=lambda df, params: df, lookback_days=lookback_days,