perf(data): bound lidar readers and lab session loading
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
@@ -26,6 +27,7 @@ from k1link.compute.lidar_local_surface_geometry import (
|
||||
DEFAULT_K1_LOCAL_SURFACE_PROFILE as WORKER_LOCAL_SURFACE_PROFILE,
|
||||
)
|
||||
from k1link.web.lidar_api import build_lidar_router
|
||||
from k1link.web.lidar_local_surface_service import K1LocalSurfaceReadService
|
||||
|
||||
|
||||
def _canonical_json(value: object) -> bytes:
|
||||
@@ -139,6 +141,7 @@ def _endpoint(router: APIRouter, path: str) -> object:
|
||||
|
||||
def test_k1_local_surface_is_dynamic_source_bound_and_read_only(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
source_path = _source_pack(tmp_path / "source")
|
||||
source_artifact = source_path / "lidar-pack.npz"
|
||||
@@ -217,12 +220,14 @@ def test_k1_local_surface_is_dynamic_source_bound_and_read_only(
|
||||
source.close()
|
||||
model.close()
|
||||
|
||||
read_service = K1LocalSurfaceReadService(tmp_path / "validation-cache")
|
||||
router = build_lidar_router(
|
||||
root_provider=lambda: None,
|
||||
ground_root_provider=lambda: None,
|
||||
field_review_root_provider=lambda: None,
|
||||
local_surface_root_provider=lambda: output.parent,
|
||||
e10_source_root_provider=lambda: source_path.parent,
|
||||
local_surface_read_service=read_service,
|
||||
)
|
||||
catalog_route = _endpoint(router, "/api/v1/lidar/local-surfaces")
|
||||
frame_route = _endpoint(
|
||||
@@ -252,6 +257,86 @@ def test_k1_local_surface_is_dynamic_source_bound_and_read_only(
|
||||
assert review["review_profile_id"] == "missioncore-local-surface-attention/v1"
|
||||
assert review["access"] == "read-only"
|
||||
assert str(tmp_path) not in repr(review)
|
||||
read_service.close()
|
||||
|
||||
def forbidden_strict_open(*_args: object, **_kwargs: object) -> None:
|
||||
raise AssertionError("an unchanged admitted generation must restore without strict scan")
|
||||
|
||||
monkeypatch.setattr(K1LocalSurfaceV1, "__init__", forbidden_strict_open)
|
||||
monkeypatch.setattr(E10LidarFieldSource, "__init__", forbidden_strict_open)
|
||||
restored_service = K1LocalSurfaceReadService(tmp_path / "validation-cache")
|
||||
restored_router = build_lidar_router(
|
||||
root_provider=lambda: None,
|
||||
ground_root_provider=lambda: None,
|
||||
field_review_root_provider=lambda: None,
|
||||
local_surface_root_provider=lambda: output.parent,
|
||||
e10_source_root_provider=lambda: source_path.parent,
|
||||
local_surface_read_service=restored_service,
|
||||
)
|
||||
restored_catalog = _endpoint(restored_router, "/api/v1/lidar/local-surfaces")
|
||||
restored_timeline = _endpoint(
|
||||
restored_router,
|
||||
"/api/v1/lidar/local-surfaces/{model_id}/timeline",
|
||||
)
|
||||
try:
|
||||
assert restored_catalog(limit=1)["items"][0]["model_id"] == output.name
|
||||
assert restored_timeline(model_id=output.name)["frame_count"] == 8
|
||||
finally:
|
||||
restored_service.close()
|
||||
|
||||
source_arrays = source_path / "lidar-pack.npz"
|
||||
source_metadata = source_arrays.stat()
|
||||
os.utime(
|
||||
source_arrays,
|
||||
ns=(source_metadata.st_atime_ns, source_metadata.st_mtime_ns + 1),
|
||||
)
|
||||
invalidated_source_service = K1LocalSurfaceReadService(
|
||||
tmp_path / "validation-cache"
|
||||
)
|
||||
invalidated_source_router = build_lidar_router(
|
||||
root_provider=lambda: None,
|
||||
ground_root_provider=lambda: None,
|
||||
field_review_root_provider=lambda: None,
|
||||
local_surface_root_provider=lambda: output.parent,
|
||||
e10_source_root_provider=lambda: source_path.parent,
|
||||
local_surface_read_service=invalidated_source_service,
|
||||
)
|
||||
invalidated_timeline = _endpoint(
|
||||
invalidated_source_router,
|
||||
"/api/v1/lidar/local-surfaces/{model_id}/timeline",
|
||||
)
|
||||
try:
|
||||
with pytest.raises(AssertionError, match="strict scan"):
|
||||
invalidated_timeline(model_id=output.name)
|
||||
finally:
|
||||
invalidated_source_service.close()
|
||||
|
||||
model_manifest = output / "manifest.json"
|
||||
model_metadata = model_manifest.stat()
|
||||
os.utime(
|
||||
model_manifest,
|
||||
ns=(model_metadata.st_atime_ns, model_metadata.st_mtime_ns + 1),
|
||||
)
|
||||
invalidated_model_service = K1LocalSurfaceReadService(
|
||||
tmp_path / "validation-cache"
|
||||
)
|
||||
invalidated_model_router = build_lidar_router(
|
||||
root_provider=lambda: None,
|
||||
ground_root_provider=lambda: None,
|
||||
field_review_root_provider=lambda: None,
|
||||
local_surface_root_provider=lambda: output.parent,
|
||||
e10_source_root_provider=lambda: source_path.parent,
|
||||
local_surface_read_service=invalidated_model_service,
|
||||
)
|
||||
invalidated_catalog = _endpoint(
|
||||
invalidated_model_router,
|
||||
"/api/v1/lidar/local-surfaces",
|
||||
)
|
||||
try:
|
||||
with pytest.raises(AssertionError, match="strict scan"):
|
||||
invalidated_catalog(limit=1)
|
||||
finally:
|
||||
invalidated_model_service.close()
|
||||
|
||||
|
||||
def _shadow_input(
|
||||
|
||||
@@ -851,7 +851,10 @@ def test_replay_post_retries_terminal_camera_finalization_failure(
|
||||
manager.close()
|
||||
|
||||
|
||||
def test_catalog_read_never_prepares_a_cold_historical_session(tmp_path: Path) -> None:
|
||||
def test_catalog_read_never_prepares_a_cold_historical_session(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
repository = tmp_path / "repo"
|
||||
sessions = repository / "sessions"
|
||||
session = make_legacy_session(sessions, "20260716T205632Z_viewer_live")
|
||||
@@ -866,6 +869,11 @@ def test_catalog_read_never_prepares_a_cold_historical_session(tmp_path: Path) -
|
||||
|
||||
materializer = SessionRecordingMaterializer(store.data_dir, exporter=exporter)
|
||||
manager = SessionRecordingPreparationManager(materializer)
|
||||
|
||||
def forbidden_restore(*_args: object, **_kwargs: object) -> None:
|
||||
raise AssertionError("catalog reads must not restore published recordings")
|
||||
|
||||
monkeypatch.setattr(manager, "restore_published", forbidden_restore)
|
||||
router = build_session_router(
|
||||
store,
|
||||
recording_materializer=materializer,
|
||||
|
||||
Reference in New Issue
Block a user