feat(lab): publish E39 refinement result

This commit is contained in:
DCCONSTRUCTIONS
2026-07-28 10:06:57 +03:00
parent 6e5124bd9c
commit 1f20e0d7d9
9 changed files with 770 additions and 9 deletions
+153 -3
View File
@@ -26,7 +26,7 @@ def _endpoint(router: APIRouter, path: str) -> object:
def test_advanced_catalogs_are_empty_when_not_configured() -> None:
router = build_advanced_laboratory_router()
for name in ("e31", "e32", "e33", "e34", "e35", "e37", "e38"):
for name in ("e31", "e32", "e33", "e34", "e35", "e37", "e38", "e39"):
route = _endpoint(router, f"/api/v1/laboratory/{name}/results")
catalog = route(limit=1) # type: ignore[operator]
assert catalog == {
@@ -49,7 +49,8 @@ def test_advanced_catalogs_fail_closed_on_incomplete_results(
e35 = tmp_path / "e35"
e37 = tmp_path / "e37"
e38 = tmp_path / "e38"
for root in (e31, e32, e33, e34, e35, e37, e38):
e39 = tmp_path / "e39"
for root in (e31, e32, e33, e34, e35, e37, e38, e39):
root.mkdir()
(e31 / f"e31-source-qualification-{'1' * 64}").mkdir()
(e32 / f"e32-track-geometry-{'2' * 64}").mkdir()
@@ -58,6 +59,7 @@ def test_advanced_catalogs_fail_closed_on_incomplete_results(
(e35 / f"e35-degradation-recovery-{'5' * 64}").mkdir()
(e37 / f"e37-ravnoves-acceptance-{'7' * 64}").mkdir()
(e38 / f"e38-perception-baseline-{'8' * 64}").mkdir()
(e39 / f"e39-perception-refinement-{'9' * 64}").mkdir()
router = build_advanced_laboratory_router(
e31_root_provider=lambda: e31,
e32_root_provider=lambda: e32,
@@ -66,9 +68,10 @@ def test_advanced_catalogs_fail_closed_on_incomplete_results(
e35_root_provider=lambda: e35,
e37_root_provider=lambda: e37,
e38_root_provider=lambda: e38,
e39_root_provider=lambda: e39,
)
for name in ("e31", "e32", "e33", "e34", "e35", "e37", "e38"):
for name in ("e31", "e32", "e33", "e34", "e35", "e37", "e38", "e39"):
route = _endpoint(router, f"/api/v1/laboratory/{name}/results")
catalog = route(limit=1) # type: ignore[operator]
assert catalog["configured"] is True
@@ -220,6 +223,153 @@ def test_e34_catalog_projects_only_accepted_read_only_evidence(
assert item["access"] == "read-only"
def test_e39_catalog_projects_development_cv_and_sealed_validation(
tmp_path: Path,
monkeypatch: MonkeyPatch,
) -> None:
result_id = f"e39-perception-refinement-{'9' * 64}"
root = tmp_path / "e39"
candidate = root / result_id
candidate.mkdir(parents=True)
(candidate / "manifest.json").write_text("{}", encoding="utf-8")
authority = {
"commands_enabled": False,
"navigation_or_safety_accepted": False,
}
dimension = {
"correct": 124,
"incorrect": 22,
"total": 146,
"accuracy": 0.849315,
"target": 0.9,
"passed": False,
"confusion": [],
"by_stratum": {},
}
result = SimpleNamespace(
result_id=result_id,
manifest={
"created_at_utc": "2026-07-28T06:29:42.847Z",
"identity": {
"source": {
"session_id": "20260720T065719Z_viewer_live",
"display_name": "RAVNOVES00",
},
"profile": {
"profile_id": "e39-ravnoves00-r1-development-knn/v1",
},
"execution": {
"worker_node": "DESKTOP-OPJ8J04",
},
},
},
report={
"status": "measured-r1-source-scoped-refinement",
"development_cross_validation": {
"strategy": "deterministic-item-hash-five-fold",
"seed": "e39-dev-cv",
"folds": 5,
"items": 340,
"validation_labels_used": False,
"passed": True,
"dimensions": {
"presence": {
"correct": 307,
"incorrect": 33,
"total": 340,
"accuracy": 0.902941,
"target": 0.9,
"passed": True,
},
"geometry_association": {
"correct": 308,
"incorrect": 32,
"total": 340,
"accuracy": 0.905882,
"target": 0.9,
"passed": True,
},
"freshness": {
"correct": 328,
"incorrect": 12,
"total": 340,
"accuracy": 0.964706,
"target": 0.9,
"passed": True,
},
},
},
"metrics": {
"development_items": 340,
"validation_items": 146,
"terminal_outcomes": 146,
"accounting_fraction": 1.0,
"false_free_claims": 0,
"high_severity_failures": 8,
"dimensions": {
"presence": dimension,
"geometry_association": dimension,
"freshness": {
**dimension,
"correct": 136,
"incorrect": 10,
"accuracy": 0.931507,
"passed": True,
},
},
},
"quality_gate": {
"passed": False,
"blocking_checks": [
"presence_target_reached",
"geometry_association_target_reached",
"high_severity_failures_zero",
],
},
"method": {
"summary": "robust-scaled 3-neighbour classification",
"selection": "development-only five-fold cross-validation",
"dimension_projection": "presence plus immutable stratum",
},
"decision": {
"r1_refinement_measured": True,
"accepted_for_release": False,
},
"limitations": ["source-scoped"],
"authority": authority,
},
)
def fake_read(
root_text: str,
signature: tuple[int, ...],
) -> SimpleNamespace:
assert root_text == str(candidate.resolve())
assert signature
return result
monkeypatch.setattr(advanced_api, "_read_e39_cached", fake_read)
router = build_advanced_laboratory_router(
e39_root_provider=lambda: root,
)
route = _endpoint(router, "/api/v1/laboratory/e39/results")
catalog = route(limit=1) # type: ignore[operator]
assert catalog["candidate_total"] == 1
assert catalog["invalid_total"] == 0
item = catalog["items"][0]
assert item["development_cross_validation"]["passed"] is True
assert (
item["development_cross_validation"]["validation_labels_used"]
is False
)
assert item["metrics"]["dimensions"]["presence"]["accuracy"] == 0.849315
assert item["metrics"]["high_severity_failures"] == 8
assert item["quality_gate_passed"] is False
assert item["authority"] == authority
assert item["access"] == "read-only"
def test_e35_catalog_projects_recovery_and_review(
tmp_path: Path,
monkeypatch: MonkeyPatch,