perf(observatory): avoid duplicate camera verification

This commit is contained in:
DCCONSTRUCTIONS
2026-08-31 18:25:09 +03:00
parent def8c71410
commit 1ff527b264
2 changed files with 79 additions and 33 deletions
@@ -562,6 +562,7 @@ def test_large_camera_inventory_has_bounded_secure_destination_planning(
def test_http_gateway_packed_camera_epoch_bounds_requests_and_header_timeout(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
job = _job(
bundle_sha256=hashlib.sha256(b"source-bundle").hexdigest(),
@@ -576,6 +577,35 @@ def test_http_gateway_packed_camera_epoch_bounds_requests_and_header_timeout(
artifact_requests: list[httpx.Request] = []
camera_member_requests: list[str] = []
archive_read_timeouts: list[float] = []
secure_directory_calls: list[Path] = []
existing_hash_paths: list[Path] = []
original_secure_directory = worker_http_transport_module._secure_directory
original_hash_local_regular_file = (
worker_http_transport_module._hash_local_regular_file
)
def counting_secure_directory(path: Path) -> Path:
secure_directory_calls.append(path)
return original_secure_directory(path)
def counting_hash_local_regular_file(
path: Path,
maximum_bytes: int,
) -> tuple[str, int]:
if path.exists():
existing_hash_paths.append(path)
return original_hash_local_regular_file(path, maximum_bytes)
monkeypatch.setattr(
worker_http_transport_module,
"_secure_directory",
counting_secure_directory,
)
monkeypatch.setattr(
worker_http_transport_module,
"_hash_local_regular_file",
counting_hash_local_regular_file,
)
rows = manifest["members"]
assert isinstance(rows, list)
camera_member_ids = {
@@ -627,12 +657,43 @@ def test_http_gateway_packed_camera_epoch_bounds_requests_and_header_timeout(
) as gateway:
_cache_claim(gateway)
stage = gateway.materialize(job)
first_materialization_secure_calls = tuple(secure_directory_calls)
assert existing_hash_paths == []
existing_hash_paths.clear()
resumed_stage = gateway.materialize(job)
assert resumed_stage == stage
assert archive_read_timeouts == [
WORKER_HTTP_CAMERA_ARCHIVE_READ_TIMEOUT_SECONDS
]
assert camera_member_requests == []
assert len(artifact_requests) == 6
assert len(artifact_requests) == 7
camera_root = stage.root / "camera"
camera_hash_paths = [
path for path in existing_hash_paths if path.is_relative_to(camera_root)
]
assert len(camera_hash_paths) == 102
assert set(camera_hash_paths) == {
stage.root / "camera/epoch-1/init.mp4",
*(
stage.root / f"camera/epoch-1/segments/{sequence}.m4s"
for sequence in range(1, 102)
),
}
assert (
sum(
path == stage.root / "camera/epoch-1"
for path in first_materialization_secure_calls
)
== 1
)
assert (
sum(
path == stage.root / "camera/epoch-1/segments"
for path in first_materialization_secure_calls
)
== 1
)
assert (
stage.root / "camera/epoch-1/segments/101.m4s"
).read_bytes() == b"sealed-camera-segment-101"