test_snapshot_manifests_batch_delta.py
python
sha256:9e7fb25b45eb883646cdd15c4c6ed27f0ca88cf6259a90d3067cfaba744f0ea3
fix(objects): review of a0c73d55 — fetch/sync read concurre…
Opus 5.5
minor
⚠ breaking
2 days ago
| 1 | """``get_snapshot_manifests_batch`` must resolve delta-encoded snapshots, not return them as empty manifests. |
| 2 | |
| 3 | Demonstrated defect (local hub, 2026-11-14): 1,820 of 4,071 snapshots are delta-encoded (``manifest_blob`` NULL, ``delta_blob`` against the parent); |
| 4 | the batch reader decoded only ``manifest_blob`` and returned ``{}`` for every one of them, so blame, file history and last-commit attribution |
| 5 | (including the table materialized at push time) saw roughly half of all snapshots as containing no files. |
| 6 | """ |
| 7 | from __future__ import annotations |
| 8 | |
| 9 | import msgpack |
| 10 | import pytest |
| 11 | from sqlalchemy.ext.asyncio import AsyncSession |
| 12 | |
| 13 | from musehub.db.musehub_repo_models import MusehubSnapshot |
| 14 | from musehub.services.musehub_snapshot import get_snapshot_manifests_batch |
| 15 | from musehub.services.musehub_wire_shared import _reconstruct_manifest |
| 16 | |
| 17 | BASE = {"a.py": "sha256:" + "1" * 64, "b.py": "sha256:" + "2" * 64} |
| 18 | |
| 19 | |
| 20 | def _sid(n: int) -> str: |
| 21 | return "sha256:" + f"{n:064x}" |
| 22 | |
| 23 | |
| 24 | async def _chain(db: AsyncSession) -> list[str]: |
| 25 | """full(1) <- delta(2: add c, rm a) <- delta(3: legacy plain-dict delta updates b).""" |
| 26 | db.add(MusehubSnapshot(snapshot_id=_sid(1), manifest_blob=msgpack.packb(BASE))) |
| 27 | db.add(MusehubSnapshot(snapshot_id=_sid(2), manifest_blob=None, parent_snapshot_id=_sid(1), |
| 28 | delta_blob=msgpack.packb({"add": {"c.py": "sha256:" + "3" * 64}, "rm": ["a.py"]}))) |
| 29 | db.add(MusehubSnapshot(snapshot_id=_sid(3), manifest_blob=None, parent_snapshot_id=_sid(2), |
| 30 | delta_blob=msgpack.packb({"b.py": "sha256:" + "4" * 64}))) |
| 31 | await db.commit() |
| 32 | return [_sid(1), _sid(2), _sid(3)] |
| 33 | |
| 34 | |
| 35 | @pytest.mark.asyncio |
| 36 | async def test_batch_resolves_delta_snapshots_with_parents_in_the_batch(db_session: AsyncSession) -> None: |
| 37 | ids = await _chain(db_session) |
| 38 | got = await get_snapshot_manifests_batch(db_session, ids) |
| 39 | assert got[_sid(2)] == {"b.py": "sha256:" + "2" * 64, "c.py": "sha256:" + "3" * 64} |
| 40 | assert got[_sid(3)] == {"b.py": "sha256:" + "4" * 64, "c.py": "sha256:" + "3" * 64} |
| 41 | for sid in ids: |
| 42 | assert got[sid] == await _reconstruct_manifest(db_session, sid) |
| 43 | |
| 44 | |
| 45 | @pytest.mark.asyncio |
| 46 | async def test_batch_resolves_delta_snapshots_whose_parent_is_not_requested(db_session: AsyncSession) -> None: |
| 47 | await _chain(db_session) |
| 48 | got = await get_snapshot_manifests_batch(db_session, [_sid(3)]) |
| 49 | assert got[_sid(3)] == await _reconstruct_manifest(db_session, _sid(3)) and got[_sid(3)] |
| 50 | |
| 51 | |
| 52 | @pytest.mark.asyncio |
| 53 | async def test_unknown_ids_stay_empty(db_session: AsyncSession) -> None: |
| 54 | got = await get_snapshot_manifests_batch(db_session, [_sid(99)]) |
| 55 | assert got == {_sid(99): {}} |
| 56 | |
| 57 | |
| 58 | @pytest.mark.asyncio |
| 59 | async def test_empty_manifest_blob_with_a_delta_is_reconstructed_like_null(db_session: AsyncSession) -> None: |
| 60 | db_session.add(MusehubSnapshot(snapshot_id=_sid(10), manifest_blob=msgpack.packb(BASE))) |
| 61 | db_session.add(MusehubSnapshot(snapshot_id=_sid(11), manifest_blob=b"", parent_snapshot_id=_sid(10), |
| 62 | delta_blob=msgpack.packb({"add": {"z.py": "sha256:" + "9" * 64}, "rm": []}))) |
| 63 | await db_session.commit() |
| 64 | expected = {**BASE, "z.py": "sha256:" + "9" * 64} |
| 65 | assert (await get_snapshot_manifests_batch(db_session, [_sid(11)]))[_sid(11)] == expected |
| 66 | assert (await get_snapshot_manifests_batch(db_session, [_sid(10), _sid(11)]))[_sid(11)] == expected |
| 67 | assert await _reconstruct_manifest(db_session, _sid(11)) == expected |
File History
2 commits
sha256:9e7fb25b45eb883646cdd15c4c6ed27f0ca88cf6259a90d3067cfaba744f0ea3
fix(objects): review of a0c73d55 — fetch/sync read concurre…
Opus 5.5
minor
⚠
2 days ago
sha256:69161439990eeb42a0502d2417d8492b076c88e5ca0fb842dbb1bfb1ef8fca7c
fix(objects): P0 object availability — serve mpack-stored o…
Opus 5.5
minor
⚠
2 days ago