fix(tests): 修复 P1-4/P1-7 改动引发的 2 个测试失败
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled

1. test_backup_workflow: JWT secret 从 'secret'(6字符) 改为 32+ 字符
   - 原因: P1-4 /health readiness 修复后,短 JWT → settings_valid=false → 503
   - backup smoke 脚本启动 admin 时 /health 返回 503 导致测试失败
   - 修复: 使用足够长的测试 JWT secret

2. test_score_range_fullchain_100_script: default_output_path 断言更新
   - 原因: P1-7 把产物路径从 reports/ 改为 /tmp/,但 default_output_path 函数仍指向旧路径
   - 修复: default_output_path 统一用 /tmp/ + 去掉日期后缀

验证: pytest 1306 passed, 3 skipped, 0 failed
This commit is contained in:
Hermes Agent
2026-06-27 19:54:37 +08:00
parent 34dd51fa31
commit e1fd92975b
3 changed files with 120 additions and 4 deletions

View File

@@ -102,7 +102,7 @@ def select_cases(cases: list[dict[str, Any]], batch: str) -> list[dict[str, Any]
def default_output_path(batch: str) -> Path:
if batch == "all":
return OUT
return ROOT / "reports" / f"score_range_fullchain_100_e2e_{batch}_2026_06_26.json"
return Path(f"/tmp/score_range_fullchain_100_e2e_{batch}.json")
def request(

View File

@@ -87,7 +87,9 @@ def _prepare_backup_sources(settings, tmp_path: Path) -> dict[str, str]:
secrets_dir = tmp_path / "secrets"
secrets_dir.mkdir(parents=True, exist_ok=True)
(secrets_dir / "jwt_secret").write_text("secret", encoding="utf-8")
(secrets_dir / "jwt_secret").write_text(
"backup-restore-smoke-jwt-secret-32chars!!", encoding="utf-8"
)
(secrets_dir / "orders_fernet_key").write_text("secret-fernet", encoding="utf-8")
(secrets_dir / "admin_pass").write_text("secret-admin-pass", encoding="utf-8")
@@ -145,10 +147,12 @@ def test_backup_snapshot_creates_manifest_and_prunes_old_backups(settings, tmp_p
assert "files/portal_uploads/ORDER-1/score.pdf" in manifest_paths
assert any(
path.startswith("files/order_artifacts/ORDER-1/audit_report/") for path in manifest_paths
path.startswith("files/order_artifacts/ORDER-1/audit_report/")
for path in manifest_paths
)
assert any(
path.startswith("files/order_artifacts/ORDER-1/pdf_path/") for path in manifest_paths
path.startswith("files/order_artifacts/ORDER-1/pdf_path/")
for path in manifest_paths
)
assert any(path.startswith("files/examples/") for path in manifest_paths)

View File

@@ -0,0 +1,112 @@
from __future__ import annotations
import importlib.util
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
SCRIPT_PATH = PROJECT_ROOT / "scripts" / "score_range_fullchain_100_e2e.py"
def _load_module():
assert SCRIPT_PATH.exists(), f"missing script: {SCRIPT_PATH}"
spec = importlib.util.spec_from_file_location(
"score_range_fullchain_100_e2e", SCRIPT_PATH
)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_build_batch_plan_marks_smoke_fullchain_and_boundary_memberships() -> None:
mod = _load_module()
cases = [
{
"id": 2,
"province": "北京",
"expected_path": "fullchain",
"public_supported": True,
},
{
"id": 7,
"province": "广西",
"expected_path": "contract_boundary",
"public_supported": False,
},
{
"id": 40,
"province": "海南",
"expected_path": "fullchain",
"public_supported": True,
},
{
"id": 50,
"province": "内蒙古",
"expected_path": "contract_boundary",
"public_supported": False,
},
]
plan = mod.build_batch_plan(cases)
memberships = {entry["id"]: entry["batches"] for entry in plan["cases"]}
assert memberships[2] == ["smoke", "fullchain"]
assert memberships[7] == ["smoke", "boundary"]
assert memberships[40] == ["fullchain"]
assert memberships[50] == ["boundary"]
assert plan["summary"] == {
"case_count": 4,
"smoke_case_count": 2,
"fullchain_case_count": 2,
"boundary_case_count": 2,
}
def test_select_cases_filters_batch_without_duplicates() -> None:
mod = _load_module()
cases = [
{
"id": 2,
"province": "北京",
"expected_path": "fullchain",
"public_supported": True,
},
{
"id": 7,
"province": "广西",
"expected_path": "contract_boundary",
"public_supported": False,
},
{
"id": 40,
"province": "海南",
"expected_path": "fullchain",
"public_supported": True,
},
{
"id": 50,
"province": "内蒙古",
"expected_path": "contract_boundary",
"public_supported": False,
},
]
planned = mod.build_batch_plan(cases)["cases"]
assert [row["id"] for row in mod.select_cases(planned, "smoke")] == [2, 7]
assert [row["id"] for row in mod.select_cases(planned, "fullchain")] == [2, 40]
assert [row["id"] for row in mod.select_cases(planned, "boundary")] == [7, 50]
assert [row["id"] for row in mod.select_cases(planned, "all")] == [2, 7, 40, 50]
def test_default_output_path_is_batch_specific() -> None:
mod = _load_module()
smoke = mod.default_output_path("smoke")
fullchain = mod.default_output_path("all")
boundary = mod.default_output_path("boundary")
# P1-7 修复后默认写入 /tmp不再带日期后缀
assert smoke.name == "score_range_fullchain_100_e2e_smoke.json"
assert fullchain.name == "score_range_fullchain_100_e2e.json"
assert boundary.name == "score_range_fullchain_100_e2e_boundary.json"
assert smoke != fullchain