Files
gaokao-volunteer-system/tests/test_rules_cli_phase1.py
Hermes Agent 8a61b8fe4a
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
fix(rules): close phase15 verify and legacy checker migration
2026-06-17 09:01:43 +08:00

62 lines
1.9 KiB
Python

from __future__ import annotations
import importlib.util
import json
import subprocess
import sys
from importlib.machinery import SourceFileLoader
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
SCRIPT_PATH = PROJECT_ROOT / "scripts" / "gaokao-cli"
def _load_migrate_module():
loader = SourceFileLoader(
"migrate_province_rules_to_truth",
str(PROJECT_ROOT / "scripts" / "migrate_province_rules_to_truth.py"),
)
spec = importlib.util.spec_from_loader(loader.name, loader)
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 _run_cli(*args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(SCRIPT_PATH), *args],
cwd=PROJECT_ROOT,
capture_output=True,
text=True,
)
def test_rules_status_cli_reports_truth_root_summary(tmp_path: Path) -> None:
migrate = _load_migrate_module()
migrate.migrate_legacy_rules_to_truth(output_root=tmp_path)
result = _run_cli("rules", "status", "--truth-root", str(tmp_path), "--json")
assert result.returncode == 0, result.stderr
payload = json.loads(result.stdout)
assert payload["province_count"] == 27
assert payload["national_rule_count"] == 1
assert "湖南" in payload["active_provinces"]
def test_rules_verify_cli_confirms_truth_tree_is_valid(tmp_path: Path) -> None:
migrate = _load_migrate_module()
migrate.migrate_legacy_rules_to_truth(output_root=tmp_path)
result = _run_cli("rules", "verify", "--truth-root", str(tmp_path), "--json")
assert result.returncode == 0, result.stderr
payload = json.loads(result.stdout)
assert payload["ok"] is True
assert payload["province_count"] == 27
assert payload["missing_required_files"] == []