test_ltier_fetch_regression.py
python
sha256:4defb0407ee7fe26b1addb8df5cf3d31dae4ebf1ab92eeca1c05348b9d4c8458
merge: integrate R1 into the publishable #114 line (private…
Opus 5.5
minor
⚠ breaking
12 days ago
| 1 | """TDD — L-tier fetch regression (issue #60). |
| 2 | |
| 3 | wire_fetch_mpack returns mpack_id='' for 1000-commit repos. |
| 4 | WD-3 confirmed _walk_commit_delta works at 1000 commits. |
| 5 | These tests isolate the two remaining unknowns: |
| 6 | |
| 7 | LF-1 wire_refs returns the correct tip commit ID after 1000-commit chain, |
| 8 | AND that ID exists in musehub_commits. |
| 9 | |
| 10 | LF-2 wire_fetch_mpack(want=branch_heads.values(), have=[]) returns a |
| 11 | non-empty mpack for a 1000-commit repo — the exact path the bench uses. |
| 12 | |
| 13 | If LF-1 fails: branch head mismatch — want != stored commit_id. |
| 14 | If LF-2 fails with mpack_id='': _walk_commit_delta returns {} for want from wire_refs. |
| 15 | If both pass: the bug is outside the server (bench wiring, URL, repo slug mismatch). |
| 16 | """ |
| 17 | from __future__ import annotations |
| 18 | |
| 19 | import msgpack |
| 20 | import pytest |
| 21 | from datetime import datetime, timezone |
| 22 | from unittest.mock import AsyncMock |
| 23 | |
| 24 | from sqlalchemy.ext.asyncio import AsyncSession |
| 25 | from sqlalchemy import select |
| 26 | |
| 27 | from muse.core.types import fake_id, blob_id |
| 28 | from musehub.db import musehub_repo_models as db |
| 29 | from musehub.db.musehub_repo_models import MusehubMPackIndex |
| 30 | from tests.factories import create_repo |
| 31 | |
| 32 | type _ByteStore = dict[str, bytes] |
| 33 | |
| 34 | |
| 35 | def _now() -> datetime: |
| 36 | return datetime.now(tz=timezone.utc) |
| 37 | |
| 38 | |
| 39 | def _stub_backend(monkeypatch: pytest.MonkeyPatch) -> _ByteStore: |
| 40 | store: dict[str, bytes] = {} |
| 41 | |
| 42 | async def _put(oid: str, data: bytes, **_: typing.Any) -> str: |
| 43 | store[oid] = data |
| 44 | return f"mem://{oid}" |
| 45 | |
| 46 | async def _get(oid: str) -> bytes | None: |
| 47 | return store.get(oid) |
| 48 | |
| 49 | async def _exists(oid: str, **_: typing.Any) -> bool: |
| 50 | return oid in store |
| 51 | |
| 52 | backend = AsyncMock() |
| 53 | backend.put = _put |
| 54 | backend.get = _get |
| 55 | backend.exists = _exists |
| 56 | backend.supports_presign = False |
| 57 | backend.presign_get = AsyncMock(return_value="http://fake-minio/mpack") |
| 58 | # Phase 1: get_mpack must return None (not an AsyncMock) so the mpack-native |
| 59 | # path falls through to the per-object fallback, which reads from `store`. |
| 60 | backend.get_mpack = AsyncMock(return_value=None) |
| 61 | monkeypatch.setattr("musehub.services.musehub_wire.get_backend", lambda: backend) |
| 62 | return store |
| 63 | |
| 64 | |
| 65 | async def _build_chain_with_objects( |
| 66 | session: AsyncSession, repo_id: str, n: int, store: _ByteStore |
| 67 | ) -> list[str]: |
| 68 | """Insert N commits with one object each. Returns [root_id, ..., tip_id].""" |
| 69 | commit_ids: list[str] = [] |
| 70 | parent: list[str] = [] |
| 71 | for i in range(n): |
| 72 | raw = f"content-{i}".encode() |
| 73 | oid = blob_id(raw) |
| 74 | store[oid] = raw |
| 75 | |
| 76 | snap_id = fake_id(f"snap-lf-{i}") |
| 77 | snap = db.MusehubSnapshot( |
| 78 | snapshot_id=snap_id, |
| 79 | manifest_blob=msgpack.packb({f"file{i}.txt": oid}, use_bin_type=True), |
| 80 | directories=[], |
| 81 | entry_count=1, |
| 82 | created_at=_now(), |
| 83 | ) |
| 84 | session.add(snap) |
| 85 | |
| 86 | # Index the object so wire_fetch_mpack step 3 does not raise FetchNotIndexedError. |
| 87 | mpack_idx = MusehubMPackIndex( |
| 88 | entity_id=oid, |
| 89 | mpack_id=fake_id(f"mpack-lf-{i}"), |
| 90 | entity_type="object", |
| 91 | ) |
| 92 | session.add(mpack_idx) |
| 93 | |
| 94 | cid = fake_id(f"commit-lf-{i}") |
| 95 | commit = db.MusehubCommit( |
| 96 | commit_id=cid, |
| 97 | branch="main", |
| 98 | parent_ids=parent, |
| 99 | message=f"commit {i}", |
| 100 | author="gabriel", |
| 101 | timestamp=_now(), |
| 102 | snapshot_id=snap_id, |
| 103 | ) |
| 104 | session.add(commit) |
| 105 | # Real pushes always link a repo to its commits; fetch only serves linked commits. |
| 106 | session.add(db.MusehubCommitRef(repo_id=repo_id, commit_id=cid)) |
| 107 | # MusehubCommitGraph is required for _walk_commit_delta's generation-bounded fast path |
| 108 | graph = db.MusehubCommitGraph( |
| 109 | commit_id=cid, |
| 110 | parent_ids=parent, |
| 111 | generation=i, |
| 112 | snapshot_id=snap_id, |
| 113 | ) |
| 114 | session.add(graph) |
| 115 | commit_ids.append(cid) |
| 116 | parent = [cid] |
| 117 | |
| 118 | tip = commit_ids[-1] |
| 119 | # Set the branch head |
| 120 | branch_row = db.MusehubBranch( |
| 121 | branch_id=fake_id(f"branch-lf-{repo_id}"), |
| 122 | repo_id=repo_id, |
| 123 | name="main", |
| 124 | head_commit_id=tip, |
| 125 | ) |
| 126 | session.add(branch_row) |
| 127 | await session.commit() |
| 128 | return commit_ids |
| 129 | |
| 130 | |
| 131 | # ── LF-1 ────────────────────────────────────────────────────────────────────── |
| 132 | |
| 133 | @pytest.mark.asyncio |
| 134 | async def test_lf1_wire_refs_returns_correct_tip(db_session: AsyncSession) -> None: |
| 135 | """wire_refs must return the tip commit ID and that ID must exist in musehub_commits.""" |
| 136 | from musehub.services.musehub_wire import wire_refs |
| 137 | |
| 138 | repo = await create_repo(db_session, owner="gabriel", visibility="public") |
| 139 | store: _ByteStore = {} |
| 140 | ids = await _build_chain_with_objects(db_session, repo.repo_id, 1_000, store) |
| 141 | tip = ids[-1] |
| 142 | |
| 143 | result = await wire_refs(db_session, repo.repo_id) |
| 144 | |
| 145 | assert result is not None, "wire_refs returned None" |
| 146 | assert "main" in result.branch_heads, f"branch 'main' missing from branch_heads: {result.branch_heads}" |
| 147 | assert result.branch_heads["main"] == tip, ( |
| 148 | f"branch_heads['main'] = {result.branch_heads['main']!r} " |
| 149 | f"does not match stored tip {tip!r}" |
| 150 | ) |
| 151 | |
| 152 | # Confirm that ID actually exists in musehub_commits |
| 153 | row = await db_session.get(db.MusehubCommit, tip) |
| 154 | assert row is not None, ( |
| 155 | f"tip commit {tip!r} exists in MusehubBranch.head_commit_id " |
| 156 | f"but NOT in musehub_commits" |
| 157 | ) |
| 158 | |
| 159 | |
| 160 | # ── LF-2 ────────────────────────────────────────────────────────────────────── |
| 161 | |
| 162 | @pytest.mark.asyncio |
| 163 | async def test_lf2_wire_fetch_mpack_1000_commits( |
| 164 | db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch |
| 165 | ) -> None: |
| 166 | """wire_fetch_mpack with want=branch_heads.values() must return a non-empty mpack. |
| 167 | |
| 168 | This is the exact server-side call the bench makes during clone. |
| 169 | """ |
| 170 | from musehub.services.musehub_wire import wire_refs, wire_fetch_mpack |
| 171 | |
| 172 | store = _stub_backend(monkeypatch) |
| 173 | repo = await create_repo(db_session, owner="gabriel", visibility="public") |
| 174 | await _build_chain_with_objects(db_session, repo.repo_id, 1_000, store) |
| 175 | |
| 176 | refs = await wire_refs(db_session, repo.repo_id) |
| 177 | assert refs is not None |
| 178 | want = list(refs.branch_heads.values()) |
| 179 | |
| 180 | result = await wire_fetch_mpack(db_session, repo.repo_id, want=want, have=[], force_build=True) |
| 181 | |
| 182 | assert result["mpack_id"] is not None, ( |
| 183 | f"wire_fetch_mpack returned up-to-date (mpack_id=None) for 1000-commit repo. " |
| 184 | f"want={want!r}" |
| 185 | ) |
| 186 | assert result["mpack_id"].startswith("sha256:"), "mpack_id must be sha256-prefixed" |
| 187 | assert result["commit_count"] == 1_000, ( |
| 188 | f"expected 1000 commits in mpack, got {result['commit_count']}" |
| 189 | ) |
File History
13 commits
sha256:4defb0407ee7fe26b1addb8df5cf3d31dae4ebf1ab92eeca1c05348b9d4c8458
merge: integrate R1 into the publishable #114 line (private…
Opus 5.5
minor
⚠
12 days ago
sha256:83227647a82e1733a20b0b6d225df3d153769630d3c710d255e0c1b8aab8ae61
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Opus 5.5
minor
⚠
13 days ago
sha256:97c7eb42fab4fd882f88ce01cf6f18d999560962d504651a86c0a90ef0da6af1
feat: deprecate on-demand mpack build; cache miss → 503 MPa…
Sonnet 4.6
minor
⚠
149 days ago
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595
fix: typing audit — 0 violations, 0 untyped defs across all…
Sonnet 4.6
minor
⚠
172 days ago
sha256:1bb2b2331b696382042e1249385aafd0c7bdd17167b7b972be72b90ae625bd80
fix: repair 400+ failing tests, fix mpack integrity check, …
Sonnet 4.6
minor
⚠
173 days ago
sha256:56cbc136427d1e5cd1a711151b9bde9c8f7dbc65985a34761b4171a5d3ac4722
fix(phase1): decompress zstd objects from covering mpack be…
Sonnet 4.6
patch
184 days ago
sha256:d8b4340f6da72076c5e3f7f346f584117dc31d2c567af15ad772c5e3cb04273e
feat: Phase 2 fetch protocol — single presigned URL, 503 on…
Sonnet 4.6
minor
⚠
184 days ago
sha256:31703a39a7206c1ec8eca013a19c7538f84c60b48fdd019731f181103049de5e
refactor: replace wire-protocol bundle terminology with mpa…
Sonnet 4.6
minor
⚠
184 days ago
sha256:82935956475aaba0f64db9bfb2e8909d93642e6b7d852ef9f8571aad1ff4d768
test: fix entity_id column rename and missing CommitGraph r…
Sonnet 4.6
184 days ago
sha256:931e49567532561236ada9097864a0c484f101d6c25c50943af4ec2c1f5690f2
refactor: erase all streaming wire protocol traces — commen…
Sonnet 4.6
minor
⚠
184 days ago
sha256:1d31d001b6373c5e20bc74157da0c2af04d7172714213ce3a991ee2815b8458f
refactor: replace wire-artifact bundle refs with mpack in m…
Sonnet 4.6
minor
⚠
185 days ago
sha256:fa40a34564a4ce52fc62c8f422d17ff7964e5bdb91660a1a10e4e164ec18c892
refactor: rename bundle → mpack in all test files
Sonnet 4.6
185 days ago
sha256:1f14f134fcf51886ac48a35510f480bff446c032ae8cb1379197978cb63056e9
fix: init commit ID, walk delta repo_id, L-tier gates, ensu…
Sonnet 4.6
patch
185 days ago