perf(observatory): bound source destination planning

This commit is contained in:
DCCONSTRUCTIONS
2026-08-31 18:19:04 +03:00
parent 7e59176581
commit def8c71410
2 changed files with 142 additions and 2 deletions
@@ -11,6 +11,7 @@ from pathlib import Path
import httpx
import pytest
import k1link.observatory.worker_http_transport as worker_http_transport_module
from k1link.observatory.portable_artifact_transport import (
PORTABLE_CAMERA_EPOCH_ARCHIVE_ID_HEADER,
PORTABLE_CAMERA_EPOCH_ARCHIVE_MEDIA_TYPE,
@@ -498,6 +499,67 @@ def test_artifact_get_rejects_non_identity_content_encoding(
gateway.materialize(job)
def test_large_camera_inventory_has_bounded_secure_destination_planning(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
job = _job(
bundle_sha256=hashlib.sha256(b"source-bundle").hexdigest(),
capability_sha256=hashlib.sha256(b"source-capability").hexdigest(),
)
manifest, _payloads = _source_contract(job, camera_segment_count=2048)
rows = manifest["members"]
assert isinstance(rows, list)
for ordinal in range(128):
row, _payload = _source_member(
job,
kind="spatial-replay",
payload=f"secondary-spatial-{ordinal}".encode("ascii"),
artifact_id=f"secondary-spatial-{ordinal}",
media_type="application/x-nodedc-k1mqtt",
)
rows.append(row)
rows.sort(key=lambda row: str(row["member_id"]))
archive_requested = False
def handler(request: httpx.Request) -> httpx.Response:
nonlocal archive_requested
if request.url.path.endswith("/claims"):
return _claim_response()
if request.url.path.endswith("/source-materialization"):
return httpx.Response(200, json=manifest)
if request.url.path.endswith("/source-camera-epoch-archive"):
archive_requested = True
return httpx.Response(503)
pytest.fail("destination planning must finish before member fallback")
with ObservatoryWorkerHttpGateway(
base_url="http://127.0.0.1:18080",
bearer_token=BEARER_TOKEN,
work_root=tmp_path / "worker",
transport=httpx.MockTransport(handler),
) as gateway:
_cache_claim(gateway)
secure_directory_calls: list[Path] = []
original_secure_directory = worker_http_transport_module._secure_directory
def counting_secure_directory(path: Path) -> Path:
secure_directory_calls.append(path)
return original_secure_directory(path)
monkeypatch.setattr(
worker_http_transport_module,
"_secure_directory",
counting_secure_directory,
)
with pytest.raises(ObservatoryWorkerHttpError, match="HTTP 503"):
gateway.materialize(job)
assert archive_requested is True
assert len(secure_directory_calls) <= 7
assert sum(path.name == "spatial" for path in secure_directory_calls) == 1
def test_http_gateway_packed_camera_epoch_bounds_requests_and_header_timeout(
tmp_path: Path,
) -> None: