refactor(platform): freeze laboratory and telemetry boundaries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
@@ -8,6 +9,7 @@ from types import ModuleType, SimpleNamespace
|
||||
import pytest
|
||||
|
||||
from k1link.compute.pipeline_telemetry import (
|
||||
MAX_PAYLOAD_BYTES,
|
||||
JsonlPipelineTelemetrySink,
|
||||
MqttPipelineTelemetrySink,
|
||||
PipelineTelemetryEmitter,
|
||||
@@ -231,6 +233,40 @@ def test_jsonl_sink_records_topic_bound_documents(tmp_path: Path) -> None:
|
||||
assert path.stat().st_mode & 0o077 == 0
|
||||
|
||||
|
||||
def test_jsonl_sink_rotates_to_content_addressed_segment(tmp_path: Path) -> None:
|
||||
path = tmp_path / "pipeline-telemetry.jsonl"
|
||||
maximum = MAX_PAYLOAD_BYTES + 4096
|
||||
existing = (b"{}\n" * (maximum // 3))[: maximum - 32]
|
||||
path.write_bytes(existing)
|
||||
sink = JsonlPipelineTelemetrySink(path, max_bytes=maximum, max_segments=2)
|
||||
|
||||
sink.publish(_identity().topic, b"{}")
|
||||
|
||||
segments = tuple(tmp_path.glob("pipeline-telemetry.*.jsonl"))
|
||||
assert len(segments) == 1
|
||||
assert segments[0].read_bytes() == existing
|
||||
assert segments[0].stem.split(".")[-1] == hashlib.sha256(existing).hexdigest()
|
||||
assert json.loads(path.read_text())["payload"] == {}
|
||||
|
||||
|
||||
def test_jsonl_sink_refuses_to_delete_unacknowledged_segment_at_bound(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
path = tmp_path / "pipeline-telemetry.jsonl"
|
||||
maximum = MAX_PAYLOAD_BYTES + 4096
|
||||
active = b"x" * maximum
|
||||
path.write_bytes(active)
|
||||
retained = tmp_path / f"pipeline-telemetry.{'a' * 64}.jsonl"
|
||||
retained.write_bytes(b"retained")
|
||||
sink = JsonlPipelineTelemetrySink(path, max_bytes=maximum, max_segments=1)
|
||||
|
||||
with pytest.raises(PipelineTelemetryError, match="segment bound reached"):
|
||||
sink.publish(_identity().topic, b"{}")
|
||||
|
||||
assert path.read_bytes() == active
|
||||
assert retained.read_bytes() == b"retained"
|
||||
|
||||
|
||||
def test_mqtt_sink_uses_qos_one_without_retention() -> None:
|
||||
calls: list[tuple[str, bytes, int, bool]] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user