65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def _path_from_stdout(stdout: str, label: str) -> Path:
|
|
for line in stdout.splitlines():
|
|
if line.startswith(label):
|
|
raw_path = line.split(":", 1)[1].strip()
|
|
if raw_path.startswith("/mnt/") and len(raw_path) > 6 and raw_path[6] == "/":
|
|
drive = raw_path[5].upper()
|
|
return Path(f"{drive}:{raw_path[6:]}")
|
|
return Path(raw_path)
|
|
raise AssertionError(f"Missing {label!r} path in smoke output:\n{stdout}")
|
|
|
|
|
|
def test_browser_calibration_evidence_bundle_smoke_runs_with_mocked_api(tmp_path) -> None:
|
|
script_path = ROOT / "scripts" / "smoke_detection_calibration_evidence_bundle.sh"
|
|
readiness_path = ROOT / "scripts" / "run_readiness_check.sh"
|
|
|
|
assert script_path.exists()
|
|
assert "bash -n scripts/smoke_detection_calibration_evidence_bundle.sh" in readiness_path.read_text(
|
|
encoding="utf-8"
|
|
)
|
|
|
|
env = os.environ.copy()
|
|
env["CALIBRATION_EVIDENCE_SMOKE_DIR"] = str(tmp_path)
|
|
result = subprocess.run(
|
|
["bash", "scripts/smoke_detection_calibration_evidence_bundle.sh"],
|
|
cwd=ROOT,
|
|
env=env,
|
|
check=True,
|
|
text=True,
|
|
capture_output=True,
|
|
)
|
|
|
|
assert "Detection calibration evidence smoke passed" in result.stdout
|
|
assert "mocked canonical evidence endpoint" in result.stdout
|
|
|
|
summary = json.loads(_path_from_stdout(result.stdout, "Evidence summary").read_text(encoding="utf-8"))
|
|
geojson = json.loads(_path_from_stdout(result.stdout, "Evidence GeoJSON").read_text(encoding="utf-8"))
|
|
html = _path_from_stdout(result.stdout, "Evidence review").read_text(encoding="utf-8")
|
|
|
|
assert summary["mode"] == "all"
|
|
assert summary["feature_count"] == 4
|
|
assert summary["role_counts"] == {
|
|
"false_negative": 1,
|
|
"false_positive": 1,
|
|
"match_candidate": 1,
|
|
"match_reference": 1,
|
|
}
|
|
assert len(summary["runs"]) == 2
|
|
assert {run["quality_check_id"] for run in summary["runs"]} == {"qc-low", "qc-high"}
|
|
assert len(geojson["features"]) == 4
|
|
assert {feature["properties"]["calibration_threshold"] for feature in geojson["features"]} == {
|
|
0.15,
|
|
0.35,
|
|
}
|
|
assert "Detection calibration evidence review" in html
|
|
assert "false_positive" in html
|