refactor(lab): move execution to Worker and manage replay and transfer lifecycles
This commit is contained in:
+70
-10
@@ -454,7 +454,7 @@ def test_session_router_versions_capability_and_calculation_profile_projections(
|
||||
)
|
||||
|
||||
|
||||
def test_observatory_projection_api_renames_alias_and_deletes_only_projection(
|
||||
def test_observatory_projection_api_rename_and_delete_require_storage_service(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@@ -553,16 +553,16 @@ def test_observatory_projection_api_renames_alias_and_deletes_only_projection(
|
||||
assert store.get_session(projection.session_id).summary.display_name == "Маршрут у школы"
|
||||
|
||||
deleted = client.delete(url)
|
||||
assert deleted.status_code == 204
|
||||
assert deleted.content == b""
|
||||
assert client.delete(url).status_code == 404
|
||||
assert deleted.status_code == 503
|
||||
assert client.delete(url).status_code == 503
|
||||
assert store.get_lab_instance(projection.session_id) is not None
|
||||
assert store.get_session_with_catalog_snapshot(source.name)[1] == source_snapshot
|
||||
assert hashlib.sha256(source_payload.read_bytes()).hexdigest() == source_payload_sha256
|
||||
assert source.is_dir()
|
||||
assert cache_sentinel.read_bytes() == b"must-not-be-touched"
|
||||
|
||||
|
||||
def test_observatory_projection_api_rejects_source_and_legacy_lab(
|
||||
def test_observatory_projection_api_protects_source_and_supports_legacy_catalog(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
repository = tmp_path / "repo"
|
||||
@@ -588,14 +588,16 @@ def test_observatory_projection_api_rejects_source_and_legacy_lab(
|
||||
"display_name": "Нельзя изменить",
|
||||
}
|
||||
|
||||
for session_id in (source.name, legacy.session_id):
|
||||
url = f"/api/v1/observatory/lab-projections/{session_id}"
|
||||
assert client.patch(url, json=rename_document).status_code == 409
|
||||
assert client.delete(url).status_code == 409
|
||||
url = f"/api/v1/observatory/lab-projections/{source.name}"
|
||||
assert client.patch(url, json=rename_document).status_code == 409
|
||||
assert client.delete(url).status_code == 409
|
||||
legacy_url = f"/api/v1/observatory/lab-projections/{legacy.session_id}"
|
||||
assert client.patch(legacy_url, json=rename_document).status_code == 200
|
||||
assert client.delete(legacy_url).status_code == 503
|
||||
|
||||
assert source.is_dir()
|
||||
assert store.get_session(source.name).summary.session_id == source.name
|
||||
assert store.get_session(legacy.session_id).summary.display_name == "LAB E21 · legacy API row"
|
||||
assert store.get_session(legacy.session_id).summary.display_name == "Нельзя изменить"
|
||||
|
||||
|
||||
def test_delete_session_removes_evidence_and_cache_but_refuses_an_open_recording(
|
||||
@@ -3257,3 +3259,61 @@ def test_layout_get_migrates_legacy_tool_windows_out_of_the_contract(tmp_path: P
|
||||
|
||||
assert loaded["version"] == 2
|
||||
assert "tool_windows" not in loaded
|
||||
|
||||
|
||||
def test_worker_perception_preserves_playback_and_has_no_local_fallback(tmp_path):
|
||||
import httpx
|
||||
|
||||
from k1link.laboratory.worker_gateway import (
|
||||
LaboratoryGatewayConfiguration,
|
||||
LaboratoryWorkerGateway,
|
||||
)
|
||||
|
||||
repository = tmp_path / "repo"
|
||||
sessions = repository / "sessions"
|
||||
session = make_legacy_session(sessions, "20260716T205632Z_viewer_live")
|
||||
store = SessionStore(repository, data_dir=tmp_path / "data")
|
||||
store.reconcile_archive(xgrids_k1_archive_source(sessions))
|
||||
token = tmp_path / "token"
|
||||
token.write_text("b" * 48)
|
||||
calls = []
|
||||
|
||||
def remote(request):
|
||||
calls.append(request)
|
||||
if request.method == "POST":
|
||||
assert json.loads(request.content)["recording_id"] == "recording-001"
|
||||
return httpx.Response(200, content=b"RRF2complete-playback")
|
||||
assert request.headers["range"] == "bytes=4-8"
|
||||
return httpx.Response(206, content=b"movie", headers={"content-range": "bytes 4-8/50"})
|
||||
|
||||
class LocalMustNotRun:
|
||||
def render(self, *args, **kwargs):
|
||||
raise AssertionError("Operator attempted LAB execution")
|
||||
def video(self, *args, **kwargs):
|
||||
raise AssertionError("Operator opened working data")
|
||||
|
||||
gateway = LaboratoryWorkerGateway(
|
||||
LaboratoryGatewayConfiguration("http://127.0.0.1:19087", token),
|
||||
transport=httpx.MockTransport(remote),
|
||||
)
|
||||
app = FastAPI()
|
||||
app.include_router(build_session_router(
|
||||
store, laboratory_gateway=gateway, perception_overlay_provider=LocalMustNotRun(),
|
||||
perception_media_provider=LocalMustNotRun(),
|
||||
))
|
||||
with TestClient(app) as client:
|
||||
prefix = f"/api/v1/observation-sessions/{session.name}"
|
||||
r = client.post(prefix + "/perception.rrd", json={
|
||||
"application_id": "nodedc_mission_core_recorded", "recording_id": "recording-001"})
|
||||
assert r.status_code == 200 and r.content == b"RRF2complete-playback"
|
||||
r = client.get(prefix + "/perception-media/result-test/recording.mp4?generation=abc",
|
||||
headers={"Range": "bytes=4-8"})
|
||||
assert r.status_code == 206 and r.content == b"movie"
|
||||
assert calls[-1].url.path.endswith("/perception-media/result-test/recording.mp4")
|
||||
assert calls[-1].url.query == b"generation=abc"
|
||||
gateway.configuration = None
|
||||
response = client.post(prefix + "/perception.rrd", json={
|
||||
"application_id": "nodedc_mission_core_recorded", "recording_id": "recording-001",
|
||||
})
|
||||
assert response.status_code == 503
|
||||
assert len(calls) == 2
|
||||
|
||||
Reference in New Issue
Block a user