commit_fixtures.py
python
sha256:c62240d36e803460a80726fd25ffe9b5c51d9e0193c1f77753e157dc8d5d1d39
fix(wire): bind every pushed commit's snapshot and the bran…
Opus 5.5
minor
⚠ breaking
3 days ago
| 1 | """Wire commit records whose commit_id reproduces from their own fields. |
| 2 | |
| 3 | Push ingest refuses a commit whose id does not reproduce, so tests that push |
| 4 | commits must build ids the way a client does, not from an arbitrary hash. |
| 5 | """ |
| 6 | from __future__ import annotations |
| 7 | |
| 8 | from muse.core.ids import hash_commit |
| 9 | from musehub.types.json_types import JSONObject |
| 10 | |
| 11 | |
| 12 | def with_reproducible_id(record: JSONObject) -> JSONObject: |
| 13 | """Return *record* with ``commit_id`` set to the id its fields hash to.""" |
| 14 | text = lambda key: str(record.get(key) or "") |
| 15 | parents = [text(k) for k in ("parent_commit_id", "parent2_commit_id") if record.get(k)] |
| 16 | commit_id = hash_commit( |
| 17 | parent_ids=parents, |
| 18 | snapshot_id=text("snapshot_id"), |
| 19 | message=text("message"), |
| 20 | committed_at_iso=text("committed_at"), |
| 21 | author=text("author"), |
| 22 | signer_public_key=text("signer_public_key"), |
| 23 | ) |
| 24 | return {**record, "commit_id": commit_id} |
| 25 | |
| 26 | |
| 27 | async def seed_linked_commit(session, repo_id: str, commit_id: str) -> None: |
| 28 | """Make *commit_id* a commit this repository already holds (row + commit ref), idempotently. |
| 29 | |
| 30 | Push admission only lets a branch tip name a commit carried by the push or |
| 31 | already linked to the destination repository. Tests whose subject is not the |
| 32 | commit itself (object refs, branch rows, cache invalidation) push a pack with |
| 33 | no commits, so their tip must be seeded this way. |
| 34 | """ |
| 35 | import datetime |
| 36 | from sqlalchemy.dialects.postgresql import insert |
| 37 | from muse.core.types import blob_id |
| 38 | from musehub.db.musehub_repo_models import MusehubCommit, MusehubCommitRef |
| 39 | |
| 40 | await session.execute(insert(MusehubCommit).values( |
| 41 | commit_id=commit_id, branch="main", parent_ids=[], message="seeded tip", author="gabriel", |
| 42 | timestamp=datetime.datetime(2026, 1, 1, tzinfo=datetime.timezone.utc), |
| 43 | snapshot_id=blob_id(f"snap-{commit_id}".encode()), signature="", |
| 44 | ).on_conflict_do_nothing(index_elements=["commit_id"])) |
| 45 | await session.execute(insert(MusehubCommitRef).values( |
| 46 | repo_id=repo_id, commit_id=commit_id, |
| 47 | ).on_conflict_do_nothing(index_elements=["repo_id", "commit_id"])) |
| 48 | await session.commit() |
File History
3 commits
sha256:c62240d36e803460a80726fd25ffe9b5c51d9e0193c1f77753e157dc8d5d1d39
fix(wire): bind every pushed commit's snapshot and the bran…
Opus 5.5
minor
⚠
3 days ago
sha256:383b9b15b1a7c18348bf797dbec252b8842199567b4b04371578fedd5f7891d4
merge: integrate push-ingest commit verification into dev
Opus 5.5
minor
⚠
11 days ago
sha256:a4d6b38221ff81ce17b43d47240f441c45140d63c575f98273c66c0df132c388
fix(push): verify commit records at ingest and reconcile du…
Opus 5.5
minor
⚠
11 days ago