feat(device-plugins): add profiled K1 lifecycle and canonical data plane

This commit is contained in:
DCCONSTRUCTIONS
2026-07-16 19:44:06 +03:00
parent 19ab973110
commit e6f7648b84
45 changed files with 6401 additions and 440 deletions
+30 -8
View File
@@ -10,7 +10,9 @@ from pathlib import Path
import numpy as np
import pytest
from k1link.data_plane import DecodedDataPlaneView, NormalizationError
from k1link.mqtt.capture import FRAME_HEADER, RAW_MAGIC
from k1link.protocol.normalizer import normalize_k1_message
from k1link.viewer.messages import StreamMessage
from k1link.viewer.rerun_bridge import RerunBridge, RerunSceneSettings, _point_colors
from k1link.viewer.runtime import VisualizationRuntime
@@ -53,6 +55,15 @@ def _message(topic: str, payload: bytes, *, sequence: int = 7) -> StreamMessage:
)
def _envelope(topic: str, payload: bytes, *, sequence: int = 7) -> DecodedDataPlaneView:
envelope = normalize_k1_message(
_message(topic, payload, sequence=sequence),
processing_started_monotonic_ns=time.monotonic_ns(),
)
assert envelope is not None
return envelope
def test_legacy_points_and_pose_are_logged_to_rerun() -> None:
recording = FakeRecording()
bridge = RerunBridge(recording_factory=lambda _: recording) # type: ignore[arg-type]
@@ -61,8 +72,8 @@ def test_legacy_points_and_pose_are_logged_to_rerun() -> None:
"<fffBBBB", 1.0, -2.0, 3.0, 10, 20, 30, 40
)
pose_payload = struct.pack("<ffffffff", 1.0, 2.0, 3.0, 99.0, 0.9, 0.1, 0.2, 0.3)
bridge.process(_message("RealtimePointcloud", point_payload))
bridge.process(_message("RealtimePath", pose_payload, sequence=8))
bridge.process(_envelope("RealtimePointcloud", point_payload))
bridge.process(_envelope("RealtimePath", pose_payload, sequence=8))
paths = [path for path, _, _ in recording.logs]
snapshot = bridge.metrics.snapshot()
@@ -83,15 +94,19 @@ def test_legacy_points_and_pose_are_logged_to_rerun() -> None:
assert recording.disconnected is True
def test_bad_frame_is_counted_without_publishing() -> None:
def test_bad_frame_is_rejected_before_rerun_without_publishing() -> None:
recording = FakeRecording()
bridge = RerunBridge(recording_factory=lambda _: recording) # type: ignore[arg-type]
bridge.process(_message("RealtimePointcloud", b"short"))
with pytest.raises(NormalizationError):
normalize_k1_message(
_message("RealtimePointcloud", b"short"),
processing_started_monotonic_ns=time.monotonic_ns(),
)
snapshot = bridge.metrics.snapshot()
assert snapshot["messages_received"] == 1
assert snapshot["decode_errors"] == 1
assert snapshot["messages_received"] == 0
assert snapshot["decode_errors"] == 0
assert not any(path == "/world/points" for path, _, _ in recording.logs)
@@ -193,6 +208,7 @@ def test_runtime_exposes_rerun_url_and_stops_cleanly(tmp_path: Path) -> None:
runtime = VisualizationRuntime(
bridge_factory=bridge_factory,
normalizer=normalize_k1_message,
)
runtime.start_replay(capture, speed=1.0)
deadline = time.monotonic() + 5.0
@@ -258,7 +274,10 @@ def test_close_during_blocked_factory_closes_the_late_bridge(tmp_path: Path) ->
**kwargs, # type: ignore[arg-type]
)
runtime = VisualizationRuntime(bridge_factory=blocked_factory)
runtime = VisualizationRuntime(
bridge_factory=blocked_factory,
normalizer=normalize_k1_message,
)
runtime.start_replay(capture, speed=0.0)
assert factory_entered.wait(timeout=2.0)
@@ -306,7 +325,10 @@ def test_stop_fails_closed_when_runtime_thread_misses_deadline(tmp_path: Path) -
**kwargs, # type: ignore[arg-type]
)
runtime = VisualizationRuntime(bridge_factory=blocked_factory)
runtime = VisualizationRuntime(
bridge_factory=blocked_factory,
normalizer=normalize_k1_message,
)
runtime.start_replay(capture, speed=0.0)
assert factory_entered.wait(timeout=2.0)