feat(lab): publish E31 through E33 results
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.routing import APIRoute
|
||||
|
||||
from k1link.web.advanced_laboratory_api import build_advanced_laboratory_router
|
||||
|
||||
|
||||
def _endpoint(router: APIRouter, path: str) -> object:
|
||||
for route in router.routes:
|
||||
if (
|
||||
isinstance(route, APIRoute)
|
||||
and route.path == path
|
||||
and route.methods is not None
|
||||
and "GET" in route.methods
|
||||
):
|
||||
return route.endpoint
|
||||
raise AssertionError(f"GET {path} route is missing")
|
||||
|
||||
|
||||
def test_advanced_catalogs_are_empty_when_not_configured() -> None:
|
||||
router = build_advanced_laboratory_router()
|
||||
|
||||
for name in ("e31", "e32", "e33"):
|
||||
route = _endpoint(router, f"/api/v1/laboratory/{name}/results")
|
||||
catalog = route(limit=1) # type: ignore[operator]
|
||||
assert catalog == {
|
||||
"schema_version": "missioncore.laboratory-advanced-catalog/v1",
|
||||
"configured": False,
|
||||
"items": [],
|
||||
"candidate_total": 0,
|
||||
"invalid_total": 0,
|
||||
"access": "read-only",
|
||||
}
|
||||
|
||||
|
||||
def test_advanced_catalogs_fail_closed_on_incomplete_results(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
e31 = tmp_path / "e31"
|
||||
e32 = tmp_path / "e32"
|
||||
e33 = tmp_path / "e33"
|
||||
for root in (e31, e32, e33):
|
||||
root.mkdir()
|
||||
(e31 / f"e31-source-qualification-{'1' * 64}").mkdir()
|
||||
(e32 / f"e32-track-geometry-{'2' * 64}").mkdir()
|
||||
(e33 / f"e33-worker-shadow-{'3' * 64}").mkdir()
|
||||
router = build_advanced_laboratory_router(
|
||||
e31_root_provider=lambda: e31,
|
||||
e32_root_provider=lambda: e32,
|
||||
e33_root_provider=lambda: e33,
|
||||
)
|
||||
|
||||
for name in ("e31", "e32", "e33"):
|
||||
route = _endpoint(router, f"/api/v1/laboratory/{name}/results")
|
||||
catalog = route(limit=1) # type: ignore[operator]
|
||||
assert catalog["configured"] is True
|
||||
assert catalog["candidate_total"] == 1
|
||||
assert catalog["invalid_total"] == 1
|
||||
assert catalog["items"] == []
|
||||
|
||||
|
||||
def test_advanced_catalog_does_not_follow_a_configured_symlink(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
actual = tmp_path / "actual"
|
||||
actual.mkdir()
|
||||
linked = tmp_path / "linked"
|
||||
linked.symlink_to(actual, target_is_directory=True)
|
||||
router = build_advanced_laboratory_router(
|
||||
e31_root_provider=lambda: linked,
|
||||
)
|
||||
|
||||
route = _endpoint(router, "/api/v1/laboratory/e31/results")
|
||||
catalog = route(limit=1) # type: ignore[operator]
|
||||
|
||||
assert catalog["configured"] is False
|
||||
Reference in New Issue
Block a user