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(
+42
View File
@@ -55,6 +55,48 @@ def test_camera_replay_loads_segments_lazily_and_checks_each_digest(tmp_path: Pa
next(events)
def test_camera_replay_complete_recording_mode_has_no_duration_cutoff(
tmp_path: Path,
) -> None:
module = _module(
"e28_complete_source_replay_test",
"experiments/perception/run_e12_shadow_transport_replay.py",
)
epoch = tmp_path / "epoch-1"
segments = epoch / "segments"
segments.mkdir(parents=True)
(epoch / "init.mp4").write_bytes(b"init")
rows = []
for sequence, epoch_ns in ((1, 100_000_000), (2, 2_100_000_000)):
payload = f"frame-{sequence}".encode()
path = segments / f"{sequence}.m4s"
path.write_bytes(payload)
rows.append(
{
"host_epoch_ns": epoch_ns,
"host_monotonic_ns": epoch_ns,
"length": len(payload),
"path": f"segments/{sequence}.m4s",
"sequence": sequence,
"sha256": hashlib.sha256(payload).hexdigest(),
}
)
(epoch / "index.jsonl").write_text(
"".join(json.dumps(row) + "\n" for row in rows),
encoding="utf-8",
)
bounded = list(module._camera_events(epoch, 1.0))
complete = list(module._camera_events(epoch, None))
assert [event.modality for event in bounded] == ["camera-init", "camera-frame"]
assert [event.modality for event in complete] == [
"camera-init",
"camera-frame",
"camera-frame",
]
def test_e21_trend_reports_accumulating_age_and_stable_memory() -> None:
module = _module(
"e21_analyzer_test",
+2
View File
@@ -360,6 +360,8 @@ def test_k1_local_surface_shadow_matches_replay_and_stays_non_authoritative(
assert snapshot["queue"]["published"] == len(published)
assert snapshot["queue"]["consumed"] == len(published)
assert snapshot["queue"]["dropped_overflow"] == 0
assert snapshot["delivery"]["source_span_seconds"] > 0
assert snapshot["delivery"]["effective_fps"] > 0
assert snapshot["results"]["failed"] == 0
assert snapshot["occupancy_policy"]["absence_of_points_means_free"] is False
assert snapshot["authority"]["commands_enabled"] is False
+5 -3
View File
@@ -31,7 +31,7 @@ def test_live_ingress_keeps_modalities_separately_bounded_and_ordered() -> None:
received_monotonic_ns=200 + sequence,
payload=f"camera-{sequence}".encode(),
)
for sequence in range(3):
for sequence in range(9):
assert ingress.publish(
modality="lidar",
source_id="lixel/application/report/lio_pcl",
@@ -53,7 +53,7 @@ def test_live_ingress_keeps_modalities_separately_bounded_and_ordered() -> None:
snapshot = ingress.snapshot()
assert snapshot["queues"]["camera-frame"]["depth"] == 2
assert snapshot["queues"]["camera-frame"]["dropped_overflow"] == 3
assert snapshot["queues"]["lidar"]["depth"] == 2
assert snapshot["queues"]["lidar"]["depth"] == 8
assert snapshot["queues"]["lidar"]["dropped_overflow"] == 1
assert snapshot["queues"]["pose"]["depth"] == 16
assert snapshot["queues"]["pose"]["dropped_overflow"] == 4
@@ -69,7 +69,9 @@ def test_live_ingress_keeps_modalities_separately_bounded_and_ordered() -> None:
3,
4,
]
assert [event.source_sequence for event in events if event.modality == "lidar"] == [1, 2]
assert [event.source_sequence for event in events if event.modality == "lidar"] == list(
range(1, 9)
)
assert [event.source_sequence for event in events if event.modality == "pose"] == list(
range(4, 20)
)
+7 -1
View File
@@ -183,7 +183,11 @@ def test_local_surface_pose_binder_fails_closed_after_pose_deadline() -> None:
def test_local_surface_shadow_coordinator_closes_exact_accounting() -> None:
coordinator = K1LocalSurfaceShadowCoordinator(result_capacity=2)
observed = []
coordinator = K1LocalSurfaceShadowCoordinator(
result_capacity=2,
result_observer=observed.append,
)
coordinator.begin_session("physical-k1-shadow-test")
assert coordinator.publish_pose(_pose(1, 1_000_000_000)) == 0
assert coordinator.publish_point_cloud(_points(1, 1_010_000_000)) == 1
@@ -196,3 +200,5 @@ def test_local_surface_shadow_coordinator_closes_exact_accounting() -> None:
assert snapshot["runtime"]["queue"]["consumed"] == 1
assert snapshot["runtime"]["results"]["failed"] == 0
assert snapshot["authority"]["navigation_or_safety_accepted"] is False
assert len(observed) == 1
assert observed[0].frame_index == 1