fix(observatory): preserve source identity on unchanged reindex
This commit is contained in:
@@ -186,6 +186,62 @@ def test_evidence_root_is_private_and_configurable(
|
||||
assert resolve_missioncore_evidence_dir(repository) == configured.resolve()
|
||||
|
||||
|
||||
def test_unchanged_archive_preserves_exact_snapshot_across_reopen(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
repository = tmp_path / "repo"
|
||||
sessions = repository / "sessions"
|
||||
session = make_legacy_session(sessions, "20260716T205632Z_viewer_live")
|
||||
monkeypatch.setattr("k1link.sessions.store.utc_now_iso", lambda: "2026-09-03T08:00:00.000Z")
|
||||
store = SessionStore(repository, data_dir=tmp_path / "data")
|
||||
archive = xgrids_k1_archive_source(sessions)
|
||||
store.reconcile_archive(archive)
|
||||
before = store.get_session_with_catalog_snapshot(session.name)
|
||||
with sqlite3.connect(store.database_path) as connection:
|
||||
rows = tuple(connection.iterdump())
|
||||
|
||||
monkeypatch.setattr("k1link.sessions.store.utc_now_iso", lambda: "2026-09-03T09:00:00.000Z")
|
||||
reopened = SessionStore(repository, data_dir=store.data_dir)
|
||||
for _ in range(2):
|
||||
assert reopened.reconcile_archive(archive) == (session.name,)
|
||||
assert reopened.get_session_with_catalog_snapshot(session.name) == before
|
||||
with sqlite3.connect(store.database_path) as connection:
|
||||
assert tuple(connection.iterdump()) == rows
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,assignment", [
|
||||
("observation_sessions", "total_bytes = total_bytes + 1"),
|
||||
("observation_sessions", "duration_seconds = duration_seconds + 1"),
|
||||
("observation_session_sources", "seekable = 0"),
|
||||
("observation_session_artifacts", "byte_length = byte_length + 1"),
|
||||
("observation_session_artifacts", "sha256 = NULL"),
|
||||
])
|
||||
def test_reconcile_retains_clock_change_for_real_catalog_differences(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, table: str, assignment: str,
|
||||
) -> None:
|
||||
repository = tmp_path / "repo"
|
||||
sessions = repository / "sessions"
|
||||
session = make_legacy_session(sessions, "20260716T205632Z_viewer_live")
|
||||
monkeypatch.setattr("k1link.sessions.store.utc_now_iso", lambda: "2026-09-03T08:00:00.000Z")
|
||||
store = SessionStore(repository, data_dir=tmp_path / "data")
|
||||
archive = xgrids_k1_archive_source(sessions)
|
||||
store.reconcile_archive(archive)
|
||||
original = store.get_session_with_catalog_snapshot(session.name)
|
||||
with sqlite3.connect(store.database_path) as connection:
|
||||
connection.execute(f"UPDATE {table} SET {assignment}") # noqa: S608 - fixed test cases
|
||||
changed = store.get_session_with_catalog_snapshot(session.name)
|
||||
assert changed[1] != original[1]
|
||||
monkeypatch.setattr("k1link.sessions.store.utc_now_iso", lambda: "2026-09-03T09:00:00.000Z")
|
||||
store.reconcile_archive(archive)
|
||||
after = store.get_session_with_catalog_snapshot(session.name)
|
||||
assert after[1] not in (original[1], changed[1])
|
||||
with sqlite3.connect(store.database_path) as connection:
|
||||
assert connection.execute(
|
||||
"SELECT updated_at_utc FROM observation_sessions WHERE session_id = ?",
|
||||
(session.name,),
|
||||
).fetchone()[0] == "2026-09-03T09:00:00.000Z"
|
||||
|
||||
|
||||
def test_catalog_reconciles_sessions_removed_from_one_evidence_root(tmp_path: Path) -> None:
|
||||
repository = tmp_path / "repo"
|
||||
sessions = repository / "sessions"
|
||||
|
||||
Reference in New Issue
Block a user