|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +REPO_ROOT = Path(__file__).resolve().parents[1] |
| 9 | + |
| 10 | + |
| 11 | +def test_twm_runtime_benchmark_blocks_current_facade_without_simulator_trace(tmp_path): |
| 12 | + from data_agent.benchmarks.twm_runtime_v1.runner import run_twm_runtime_benchmark |
| 13 | + |
| 14 | + output = tmp_path / "twm_runtime_benchmark_v1.json" |
| 15 | + markdown_output = tmp_path / "twm_runtime_benchmark_v1.md" |
| 16 | + |
| 17 | + report = run_twm_runtime_benchmark( |
| 18 | + output_path=output, |
| 19 | + markdown_output_path=markdown_output, |
| 20 | + fail_on_failed=False, |
| 21 | + ) |
| 22 | + |
| 23 | + assert report["schema"] == "territory_world_model.twm_runtime_benchmark.v1" |
| 24 | + assert report["suite_id"] == "twm_runtime_v1" |
| 25 | + assert report["status"] == "fail" |
| 26 | + assert "simulator_gate" in report["failed_gates"] |
| 27 | + assert "planner_gate" in report["failed_gates"] |
| 28 | + |
| 29 | + simulator_gate = report["gates"]["simulator_gate"] |
| 30 | + assert simulator_gate["status"] == "fail" |
| 31 | + assert "simulator_trace" in simulator_gate["missing"] |
| 32 | + assert simulator_gate["checks"]["facade_backend_forbidden"]["status"] == "fail" |
| 33 | + assert simulator_gate["checks"]["facade_backend_forbidden"]["observed"] == "deterministic_planner_facade" |
| 34 | + |
| 35 | + planner_gate = report["gates"]["planner_gate"] |
| 36 | + assert planner_gate["status"] == "fail" |
| 37 | + assert "planner_consumes_simulator_trace" in planner_gate["missing"] |
| 38 | + |
| 39 | + claim_boundary = report["claim_boundary"] |
| 40 | + assert claim_boundary["production_decision"] == "blocked_without_real_observed_history" |
| 41 | + assert claim_boundary["production_accuracy"] == "not_supported" |
| 42 | + assert claim_boundary["flus_superiority"] == "not_evaluated_by_this_benchmark" |
| 43 | + assert claim_boundary["not_for_production_boundary_preserved"] is True |
| 44 | + |
| 45 | + assert output.exists() |
| 46 | + assert markdown_output.exists() |
| 47 | + |
| 48 | + |
| 49 | +def test_twm_runtime_benchmark_cli_writes_outputs_and_exits_nonzero_on_failed(tmp_path): |
| 50 | + output = tmp_path / "cli_report.json" |
| 51 | + markdown_output = tmp_path / "cli_report.md" |
| 52 | + |
| 53 | + completed = subprocess.run( |
| 54 | + [ |
| 55 | + sys.executable, |
| 56 | + str(REPO_ROOT / "scripts/run_twm_runtime_benchmark.py"), |
| 57 | + "--suite", |
| 58 | + "twm_runtime_v1", |
| 59 | + "--output", |
| 60 | + str(output), |
| 61 | + "--markdown-output", |
| 62 | + str(markdown_output), |
| 63 | + "--fail-on-failed", |
| 64 | + ], |
| 65 | + cwd=REPO_ROOT, |
| 66 | + text=True, |
| 67 | + capture_output=True, |
| 68 | + check=False, |
| 69 | + ) |
| 70 | + |
| 71 | + assert completed.returncode == 1 |
| 72 | + assert output.exists() |
| 73 | + assert markdown_output.exists() |
| 74 | + assert "status=fail" in completed.stdout |
| 75 | + |
| 76 | + |
| 77 | +def test_twm_runtime_benchmark_requires_explicit_leakage_guard_contract(tmp_path): |
| 78 | + from data_agent.benchmarks.twm_runtime_v1.runner import run_twm_runtime_benchmark |
| 79 | + |
| 80 | + report = run_twm_runtime_benchmark( |
| 81 | + output_path=tmp_path / "report.json", |
| 82 | + markdown_output_path=tmp_path / "report.md", |
| 83 | + ) |
| 84 | + |
| 85 | + leakage_gate = report["gates"]["leakage_guard_gate"] |
| 86 | + assert leakage_gate["status"] == "fail" |
| 87 | + assert "feature_vector_contract" in leakage_gate["missing"] |
| 88 | + assert leakage_gate["checks"]["target_feature_columns_present_in_source"]["status"] == "review" |
| 89 | + assert "leakage_guard_gate" in report["failed_gates"] |
0 commit comments