gabriel / muse public
test_transport_coerce_commit_dict.py python
84 lines 3.5 KB
Raw
sha256:ce542c4d0f6dacc9520c02d0e3378bf96bc377d118a7402f2bbc8af1749b08e0 feat(code-test): audit cache internals, add cache_hit/--cac… Sonnet 5 minor ⚠ breaking 5 hours ago
1 """TDD — ``_coerce_commit_dict`` must preserve ``structured_delta`` from the wire.
2
3 Root cause (found while debugging a real staging clone / `muse verify` failure
4 report): every field in ``_coerce_commit_dict`` reads from the incoming wire
5 dict via ``raw.get(...)`` *except* ``structured_delta``, which was hardcoded
6 to ``None`` -- discarding whatever the server actually sent. The function's
7 own docstring claims "structured_delta is preserved as-is", which was false.
8
9 Effect: every ``muse fetch`` / ``muse clone`` / ``muse pull`` permanently
10 loses structured_delta for every commit, even though the server sends it
11 correctly (confirmed separately via a live push+fetch round trip against
12 staging.musehub.ai). This is unrelated to a separate, historical-only
13 signature-corruption issue found in the same investigation (~1179 pre-existing
14 commits with invalid signatures) -- that one does not reproduce on a fresh
15 push+fetch cycle and needs its own data-repair investigation, not a code fix.
16 """
17 from __future__ import annotations
18
19 from muse.core.transport import _coerce_commit_dict
20
21
22 def _raw_wire_commit(**overrides: object) -> dict[str, object]:
23 base: dict[str, object] = {
24 "commit_id": "sha256:" + "a" * 64,
25 "repo_id": "sha256:" + "b" * 64,
26 "branch": "main",
27 "snapshot_id": "sha256:" + "c" * 64,
28 "message": "a commit",
29 "committed_at": "2026-05-20T14:43:25.290457+00:00",
30 "parent_commit_id": None,
31 "parent2_commit_id": None,
32 "author": "gabriel",
33 "metadata": {},
34 "structured_delta": {
35 "domain": "code",
36 "ops": [{"op": "patch", "address": "src/foo.py"}],
37 "summary": "1 modified file",
38 },
39 "sem_ver_bump": "patch",
40 "breaking_changes": [],
41 "agent_id": "claude-code",
42 "model_id": "claude-sonnet-5",
43 "toolchain_id": "",
44 "prompt_hash": "",
45 "signature": "ed25519:" + "d" * 86,
46 "signer_public_key": "ed25519:" + "e" * 43,
47 "signer_key_id": "sha256:" + "f" * 64,
48 "reviewed_by": [],
49 "test_runs": 0,
50 }
51 base.update(overrides)
52 return base
53
54
55 class TestCoerceCommitDictStructuredDelta:
56 def test_real_structured_delta_is_preserved(self) -> None:
57 raw = _raw_wire_commit()
58 result = _coerce_commit_dict(raw)
59 assert result["structured_delta"] == raw["structured_delta"]
60
61 def test_missing_structured_delta_stays_none(self) -> None:
62 raw = _raw_wire_commit()
63 del raw["structured_delta"]
64 result = _coerce_commit_dict(raw)
65 assert result["structured_delta"] is None
66
67 def test_non_dict_structured_delta_is_rejected_not_passed_through(self) -> None:
68 """A malformed wire value (e.g. a string or list) must not be trusted
69 as structured_delta -- coerce to None rather than propagate garbage."""
70 raw = _raw_wire_commit(structured_delta="not-a-dict")
71 result = _coerce_commit_dict(raw)
72 assert result["structured_delta"] is None
73
74 def test_other_fields_unaffected(self) -> None:
75 """Regression guard: every other field this function handles must
76 keep working exactly as before -- this bug only ever affected
77 structured_delta."""
78 raw = _raw_wire_commit()
79 result = _coerce_commit_dict(raw)
80 assert result["commit_id"] == raw["commit_id"]
81 assert result["signature"] == raw["signature"]
82 assert result["signer_public_key"] == raw["signer_public_key"]
83 assert result["agent_id"] == raw["agent_id"]
84 assert result["sem_ver_bump"] == "patch"
File History 1 commit
sha256:ce542c4d0f6dacc9520c02d0e3378bf96bc377d118a7402f2bbc8af1749b08e0 feat(code-test): audit cache internals, add cache_hit/--cac… Sonnet 5 minor ⚠ 5 hours ago