feat: qualify complete K1 replay on worker

This commit is contained in:
DCCONSTRUCTIONS
2026-07-26 10:11:56 +03:00
parent a1e2cb523f
commit 36ea7ea3d8
17 changed files with 1212 additions and 118 deletions
+101 -8
View File
@@ -30,6 +30,28 @@ def _module() -> object:
sys.path.pop(0)
def _e28_module() -> object:
worker = (
Path(__file__).resolve().parents[1]
/ "experiments"
/ "perception"
/ "worker"
)
sys.path.insert(0, str(worker))
try:
spec = importlib.util.spec_from_file_location(
"e28_local_surface_wire_test",
worker / "run_e28_local_surface_wire.py",
)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
finally:
sys.path.pop(0)
def test_e15_profile_pins_replay_shadow_authority_and_bounded_runtime() -> None:
module = _module()
profile_path = (
@@ -84,20 +106,31 @@ def test_e15_profile_rejects_command_authority(tmp_path: Path) -> None:
module.read_live_profile(changed)
def test_e28_profile_pins_physical_k1_local_surface_gate() -> None:
def test_e28_profile_pins_complete_recording_worker_local_surface_gate() -> None:
module = _module()
profile_path = (
Path(__file__).resolve().parents[1]
/ "experiments"
/ "perception"
/ "worker"
/ "e28_physical_k1_local_surface_profile.json"
/ "e28_worker_replay_local_surface_profile.json"
)
profile, digest = module.read_live_profile(profile_path)
assert len(digest) == 64
assert profile["mode"] == "physical-shadow-gate"
assert profile["mode"] == "worker-replay-gate"
assert profile["replay_source"] == {
"session_id": "20260720T065719Z_viewer_live",
"display_name": "RAVNOVES00",
"selection": "complete-recording",
"speed": 1.0,
"minimum_source_span_seconds": 450.0,
"expected_camera_frames": 4489,
"expected_lidar_events": 4570,
"expected_pose_events": 4598,
"look_ahead": False,
}
assert profile["local_surface"] == {
"enabled": True,
"profile_id": "k1-vendor-map-dynamic-local-surface/v1",
@@ -110,11 +143,12 @@ def test_e28_profile_pins_physical_k1_local_surface_gate() -> None:
"retention_seconds": 3.0,
"result_capacity": 8,
"acceptance": {
"minimum_bound_frames": 100,
"minimum_bound_frames": 4500,
"minimum_effective_fps": 9.0,
"maximum_pose_miss_fraction": 0.05,
"maximum_point_drop_fraction": 0.01,
"maximum_runtime_drop_fraction": 0.01,
"maximum_p95_result_age_ms": 80.0,
"maximum_runtime_drop_fraction": 0.08,
"maximum_p95_result_age_ms": 100.0,
},
}
assert profile["authority"] == {
@@ -130,17 +164,63 @@ def test_e28_profile_rejects_unpinned_local_surface(tmp_path: Path) -> None:
/ "experiments"
/ "perception"
/ "worker"
/ "e28_physical_k1_local_surface_profile.json"
/ "e28_worker_replay_local_surface_profile.json"
)
value = json.loads(source.read_text())
value["local_surface"]["profile_sha256"] = "0" * 64
changed = tmp_path / "unpinned-local-surface.json"
changed.write_text(json.dumps(value))
with pytest.raises(RuntimeError, match="E28 physical local-surface"):
with pytest.raises(RuntimeError, match="E28 worker local-surface"):
module.read_live_profile(changed)
def test_e28_wire_runner_accepts_the_same_complete_recording_profile() -> None:
module = _e28_module()
profile_path = (
Path(__file__).resolve().parents[1]
/ "experiments"
/ "perception"
/ "worker"
/ "e28_worker_replay_local_surface_profile.json"
)
profile, digest = module._read_profile(profile_path)
assert len(digest) == 64
assert profile["mode"] == "worker-replay-gate"
assert profile["replay_source"]["selection"] == "complete-recording"
assert profile["replay_source"]["expected_lidar_events"] == 4570
assert profile["local_surface"]["point_queue_capacity"] == 2
assert profile["authority"]["commands_enabled"] is False
def test_e28_wire_distribution_uses_the_complete_sample() -> None:
module = _e28_module()
assert module._distribution([]) == {
"sample_count": 0,
"p50": None,
"p95": None,
"maximum": None,
}
assert module._distribution([10.0, 20.0, 30.0, 40.0]) == {
"sample_count": 4,
"p50": 25.0,
"p95": 38.5,
"maximum": 40.0,
}
def test_e28_wire_reads_the_private_token_from_a_file(tmp_path: Path) -> None:
module = _e28_module()
token_root = tmp_path / ".runtime" / "live-perception"
token_root.mkdir(parents=True)
(token_root / "shadow-worker.token").write_text(f"{'a' * 43}\n")
assert module._read_shadow_token(tmp_path) == "a" * 43
def test_e28_local_surface_acceptance_requires_exact_bounded_accounting() -> None:
module = _module()
config = {
@@ -149,6 +229,7 @@ def test_e28_local_surface_acceptance_requires_exact_bounded_accounting() -> Non
"pose_buffer_capacity": 16,
"acceptance": {
"minimum_bound_frames": 100,
"minimum_effective_fps": 9.0,
"maximum_pose_miss_fraction": 0.05,
"maximum_point_drop_fraction": 0.01,
"maximum_runtime_drop_fraction": 0.01,
@@ -179,6 +260,10 @@ def test_e28_local_surface_acceptance_requires_exact_bounded_accounting() -> Non
},
"runtime": {
"closed": True,
"delivery": {
"source_span_seconds": 10.0,
"effective_fps": 10.0,
},
"profile": {
"profile_id": "k1-vendor-map-dynamic-local-surface/v1",
},
@@ -214,6 +299,14 @@ def test_e28_local_surface_acceptance_requires_exact_bounded_accounting() -> Non
]
is False
)
snapshot["runtime"]["results"]["result_age_ms"]["p95"] = 40.0
snapshot["runtime"]["delivery"]["effective_fps"] = 8.99
assert (
module._local_surface_acceptance_checks(snapshot, config)[
"local_surface_minimum_effective_fps"
]
is False
)
def test_persistent_worker_request_is_single_run_d_backed_and_token_bounded(