gabriel / musehub public
test_init_commit_id.py python
119 lines 4.9 KB
Raw
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 8 days ago
1 """TDD — init commit ID must be sha256:... not init-sha256:... (issue #60).
2
3 IC-1 create_repo(initialize=True) produces a commit_id starting with 'sha256:'.
4 IC-2 The init commit_id exists as a real row in musehub_commits.
5 IC-3 wire_refs for a freshly initialized repo returns a branch head starting with 'sha256:'.
6 IC-4 ensure_hub_seed must detect a never-pushed seed as stale (structural check).
7 """
8 from __future__ import annotations
9
10 import pytest
11 from sqlalchemy.ext.asyncio import AsyncSession
12 from sqlalchemy import select
13 from musehub.db import musehub_repo_models as db
14 from musehub.core.genesis import compute_identity_id
15
16
17 def _owner_user_id(handle: str) -> str:
18 return compute_identity_id(handle.encode())
19
20
21 # ── IC-1 ──────────────────────────────────────────────────────────────────────
22
23 @pytest.mark.asyncio
24 async def test_ic1_init_commit_id_is_sha256(db_session: AsyncSession) -> None:
25 """create_repo(initialize=True) must produce a sha256:... commit_id, not init-sha256:..."""
26 from musehub.services.musehub_repository import create_repo
27
28 repo = await create_repo(
29 db_session,
30 name="ic-test-1",
31 owner="gabriel",
32 owner_user_id=_owner_user_id("gabriel"),
33 visibility="public",
34 initialize=True,
35 )
36
37 branch_q = await db_session.execute(
38 select(db.MusehubBranch).where(db.MusehubBranch.repo_id == repo.repo_id)
39 )
40 branch = branch_q.scalar_one_or_none()
41 assert branch is not None, "branch not created"
42 cid = branch.head_commit_id
43 assert cid is not None, "head_commit_id is None"
44 assert cid.startswith("sha256:"), f"got {cid!r} — must be sha256:..."
45 assert not cid.startswith("init-"), f"got {cid!r} — init- prefix is not an algorithm"
46
47
48 # ── IC-2 ──────────────────────────────────────────────────────────────────────
49
50 @pytest.mark.asyncio
51 async def test_ic2_init_commit_exists_in_musehub_commits(db_session: AsyncSession) -> None:
52 """The init commit_id must exist as a real row in musehub_commits."""
53 from musehub.services.musehub_repository import create_repo
54
55 repo = await create_repo(
56 db_session,
57 name="ic-test-2",
58 owner="gabriel",
59 owner_user_id=_owner_user_id("gabriel"),
60 visibility="public",
61 initialize=True,
62 )
63
64 branch_q = await db_session.execute(
65 select(db.MusehubBranch).where(db.MusehubBranch.repo_id == repo.repo_id)
66 )
67 branch = branch_q.scalar_one()
68 row = await db_session.get(db.MusehubCommit, branch.head_commit_id)
69 assert row is not None, (
70 f"init commit {branch.head_commit_id!r} not found in musehub_commits"
71 )
72
73
74 # ── IC-3 ──────────────────────────────────────────────────────────────────────
75
76 @pytest.mark.asyncio
77 async def test_ic3_wire_refs_head_is_valid_sha256(db_session: AsyncSession) -> None:
78 """wire_refs for a freshly initialized repo returns a sha256:... branch head."""
79 from musehub.services.musehub_repository import create_repo
80 from musehub.services.musehub_wire import wire_refs
81
82 repo = await create_repo(
83 db_session,
84 name="ic-test-3",
85 owner="gabriel",
86 owner_user_id=_owner_user_id("gabriel"),
87 visibility="public",
88 initialize=True,
89 )
90
91 result = await wire_refs(db_session, repo.repo_id)
92 assert result is not None
93 for branch_name, head in result.branch_heads.items():
94 assert head.startswith("sha256:"), (
95 f"branch {branch_name!r} head {head!r} is not a valid sha256: commit ID"
96 )
97 assert not head.startswith("init-"), (
98 f"branch {branch_name!r} head {head!r} still uses the invalid init- prefix"
99 )
100
101
102 # ── IC-4 ──────────────────────────────────────────────────────────────────────
103
104 def test_ic4_ensure_hub_seed_checks_branch_head() -> None:
105 """ensure_hub_seed must reject a seed whose branch head is the init placeholder.
106
107 A repo created via wizard but never pushed to has head = sha256:<init-hash>.
108 The bench must detect this and force a re-push, not silently reuse the empty repo.
109 """
110 import inspect
111 import sys
112 sys.path.insert(0, "/Users/gabriel/ecosystem/musehub/tests")
113 import bench_cli
114
115 src = inspect.getsource(bench_cli.ensure_hub_seed)
116 assert "branch_heads" in src or "head_commit" in src, (
117 "ensure_hub_seed must verify branch heads are real pushed commits — "
118 "not just check repo existence and wire_hash"
119 )
File History 14 commits
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 8 days ago
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 8 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454 chore: bump version to 0.2.0.dev2 — nightly.2, matching muse Sonnet 4.6 patch 11 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 14 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 29 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 33 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 35 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 35 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago