Preserve installed operator workspace before consolidation

Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 09:59:51 +03:00
parent 97614742bb
commit d0e5f90952
368 changed files with 129172 additions and 1856 deletions
+107
View File
@@ -301,3 +301,110 @@ def test_windows_snapshot_sharing_retry_is_bounded(tmp_path, monkeypatch):
with pytest.raises(PermissionError):
module.sharing_retry(permanent)
assert len(attempts) == 8
def test_run_pins_selected_robot_and_rejects_report_from_another_world(
realtime, tmp_path, monkeypatch
):
import importlib
import json
from test_ai_polygon_reports import ADAPTERS, fixture_episode
from k1link.simulation.ai_polygon.contracts import SimulationReport
from k1link.simulation.ai_polygon.robots import select_robot
store, hello, row = realtime
robot = select_robot("dcd006-v020")
assert row["robot"] == robot
assert row["request"]["robot_id"] == robot["robot_id"]
monkeypatch.syspath_prepend(str(ADAPTERS))
fixture_episode(tmp_path)
original = json.loads((tmp_path / "run.json").read_text())
original.update(run_id=row["run_id"], world=row["world"], worker=row["worker"])
(tmp_path / "run.json").write_text(json.dumps(original))
report = SimulationReport.model_validate(
importlib.import_module("run_report").seal_episode(
tmp_path, {"mission_outcome": "operator-stop"}
)
)
with pytest.raises(ValueError, match="не соответствует"):
store.finish(
row["run_id"],
hello.instance_id,
"stopped",
"",
report.model_copy(update={"world_sha256": "f" * 64}),
)
assert store.active == row["run_id"]
done = store.finish(row["run_id"], hello.instance_id, "stopped", "", report)
assert done["report"]["manifest_sha256"] == report.manifest_sha256
assert store.finish(row["run_id"], hello.instance_id, "stopped", "", report) == done
with pytest.raises(ValueError, match="нельзя заменить"):
store.finish(
row["run_id"],
hello.instance_id,
"stopped",
"",
report.model_copy(update={"distance_m": 99}),
)
def test_stale_worker_robot_is_rejected_before_creating_or_reserving_run(realtime):
store, hello, row = realtime
store.finish(row["run_id"], hello.instance_id, "stopped", "")
store.register(hello.model_copy(update={"robots": {"dcd006-v020": "0" * 64}}))
prior = list(store.root.iterdir())
with pytest.raises(RuntimeError, match="ещё обновляется"):
store.start(
RunCreate(world_id=row["world"]["world_id"], clock="realtime"),
"test-stale-robot-01",
)
assert store.active is None
assert list(store.root.iterdir()) == prior
def test_operator_input_cannot_revert_camera_or_drive_and_ignores_duplicate_sequence(realtime):
from k1link.simulation.ai_polygon.contracts import ObserverInput
store, hello, row = realtime
value = ObserverInput(session="e" * 32, sequence=1, orbit=(0.1, 0.2), move=(0, 0, 0), zoom=0.5)
changed = store.view(row["run_id"], "follow", value)
assert changed["control"] == "pause"
assert changed["observer_input"]["sequence"] == 1
older = value.model_copy(update={"sequence": 0, "orbit": (0.8, 0.9)})
assert store.view(row["run_id"], "follow", older)["observer_input"]["orbit"] == [0.1, 0.2]
store.view(row["run_id"], "overview")
with pytest.raises(RuntimeError, match="изменён"):
store.view(row["run_id"], "follow", value)
def test_spatial_preview_is_bounded_run_owned_and_monotonic(realtime):
from k1link.simulation.ai_polygon.contracts import InferencePreview
store, hello, row = realtime
preview = InferencePreview(
frame_id=1,
simulation_time_ns=50,
composition_sha256="d" * 64,
environment="park",
layers=[
dict(
id="lidar",
label="LiDAR",
kind="points3d",
points=[[1, 0, 0]],
source_count=1,
frame="body-x-forward-y-left-z-up",
)
],
)
run_id = row["run_id"]
with pytest.raises((ValueError, RuntimeError)):
store.inference_preview(run_id, "f" * 32, preview)
assert store.inference_preview(run_id, hello.instance_id, preview) == {"accepted": True}
assert store.inference_preview(run_id)["layers"][0]["points"] == [(1, 0, 0)]
assert store.inference_preview(run_id, hello.instance_id, preview) == {"accepted": False}
store.active = None
with pytest.raises(RuntimeError, match="не запущена"):
store.inference_preview(run_id, hello.instance_id, preview)