"""Status polls stay independent of retained, potentially huge report evidence.""" import copy import json import time from fastapi import FastAPI from fastapi.testclient import TestClient from test_planning_live import fixture_service from k1link.web.planning_live_api import build_planning_live_router class UnvisitedEvidence: def __deepcopy__(self, memo): raise AssertionError("status traversed full calculation evidence") def run_document(draft): return {"id": "1", "schema_version": "missioncore.planning-live-test/v1", "profile": "planning", "plugin_id": "test-plugin", "draft": draft, "state": "waiting", "query_session_id": None, "distance_m": 0, "message": "Ожидаем запись", "result": None, "vehicle_control": False} def test_status_copies_only_presentation_fields_and_tracks_transitions(tmp_path, monkeypatch): service, source, lock, draft = fixture_service(tmp_path, monkeypatch) assert service.get_status() is None service.run = run_document(draft) service.run["calculation_history"] = UnvisitedEvidence() service.run["draft"]["route"]["points"] = UnvisitedEvidence() service.run["result"] = {"status": "candidate", "overlap": .9, "inlier_rmse_m": .1, "reasons": [], "matched_query_indices": UnvisitedEvidence(), "initialization": UnvisitedEvidence()} first = service.get_status() assert first["schema_version"] == "missioncore.planning-live-status/v1" assert len(json.dumps(first)) < 2500 assert first["query_session_id"] is None and first["state"] == "waiting" assert first["draft"]["route"]["length_m"] == 20 assert "points" not in first["draft"]["route"] assert "matched_query_indices" not in first["result"] first["result"]["reasons"].append("only caller's copy") first["draft"]["zone"]["label"] = "only caller's copy" assert service.run["result"]["reasons"] == [] assert "label" not in service.run["draft"]["zone"] service.run.update(state="running", query_session_id="B", query_generation=1, planning_phase="collecting", tracking_state="acquiring") service.last_frame_ns = time.monotonic_ns() second = service.get_status() assert second["state"] == "running" and second["query_session_id"] == "B" assert second["planning_phase"] == "collecting" and not second["stale"] assert second["frame_age_s"] >= 0 service.run.update(state="completed", planning_phase="ended") assert service.get_status()["state"] == "completed" assert not lock.locked() and source.owner is None def test_status_api_does_not_read_report_and_report_remains_complete(tmp_path, monkeypatch): service, _, _, draft = fixture_service(tmp_path, monkeypatch) service.run = run_document(draft) service.run["calculation_history"] = [{"synthetic": list(range(10))}] original = copy.deepcopy(service.run) app = FastAPI() app.include_router(build_planning_live_router(service)) with TestClient(app) as client: status = client.get("/api/v1/mission-planner/live-tests/status") report = client.get("/api/v1/mission-planner/live-tests/active") assert status.status_code == report.status_code == 200 assert status.headers["cache-control"] == "no-store" assert "calculation_history" not in status.json() assert report.json()["calculation_history"] == original["calculation_history"] assert report.json()["draft"]["route"]["points"] == draft["route"]["points"] assert service.run == original service.run = None assert client.get("/api/v1/mission-planner/live-tests/status").json() is None