feat(storage): add portable session artifact gateway
This commit is contained in:
@@ -13,6 +13,11 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
|
||||
import k1link.sessions.recording as recording_module
|
||||
from k1link.artifact_gateway import (
|
||||
ArtifactGateway,
|
||||
CentralArtifactStore,
|
||||
LocalArtifactCache,
|
||||
)
|
||||
from k1link.sessions.models import ReplayArtifact, ReplayCommand
|
||||
from k1link.sessions.recording import (
|
||||
CACHE_SCHEMA,
|
||||
@@ -131,6 +136,54 @@ def test_materializer_reuses_only_a_digest_validated_private_cache(tmp_path: Pat
|
||||
assert exporter.calls == 1
|
||||
|
||||
|
||||
def test_materializer_restores_exact_central_recording_without_export(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
command = _command(tmp_path / "source")
|
||||
central_recording = tmp_path / "central.rrd"
|
||||
central_recording.write_bytes(b"RRF2centrally-prepared-recording")
|
||||
gateway = ArtifactGateway(
|
||||
CentralArtifactStore(tmp_path / "central-store", create=True),
|
||||
LocalArtifactCache(
|
||||
tmp_path / "artifact-cache",
|
||||
max_bytes=1024 * 1024,
|
||||
free_space_reserve_bytes=0,
|
||||
),
|
||||
)
|
||||
gateway.publish(
|
||||
namespace="sessions",
|
||||
key=command.session_id,
|
||||
artifact_type="recorded-session",
|
||||
subject_id=command.session_id,
|
||||
sources=(
|
||||
("base-rrd", RERUN_RECORDING_MEDIA_TYPE, central_recording),
|
||||
),
|
||||
metadata={
|
||||
"base-source-sha256": _sha256(command.primary_artifact.path),
|
||||
"base-timeline": "session_time",
|
||||
"base-timeline-start-ns": "0",
|
||||
"base-timeline-end-ns": "2500000000",
|
||||
},
|
||||
)
|
||||
exporter = FakeExporter()
|
||||
materializer = SessionRecordingMaterializer(
|
||||
tmp_path / "private",
|
||||
exporter=exporter,
|
||||
artifact_gateway=gateway,
|
||||
)
|
||||
|
||||
restored = materializer.materialize(command)
|
||||
|
||||
assert exporter.calls == 0
|
||||
assert restored.path.is_relative_to(materializer.recordings_root)
|
||||
assert restored.path.read_bytes() == central_recording.read_bytes()
|
||||
assert restored.sha256 == _sha256(central_recording)
|
||||
assert restored.source_sha256 == _sha256(command.primary_artifact.path)
|
||||
assert restored.timeline_end_ns == 2_500_000_000
|
||||
assert materializer.materialize(command) == restored
|
||||
assert exporter.calls == 0
|
||||
|
||||
|
||||
def test_default_recording_cache_has_no_application_byte_quota(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
||||
Reference in New Issue
Block a user