gabriel / muse public
test_cmd_reflog_long_ids.py python
133 lines 4.5 KB
Raw
sha256:37af4ab271a64f11d7bf14b4871ebaaf5dd68fb0247521007c6b034d35aa01be Merge branch 'fix/hub-user-read-update-path' into dev Human 10 days ago
1 """TDD -- muse#52: `muse reflog` human text output must use long_id, not short_id.
2
3 Deliverables:
4 LI_01 _fmt_entry uses long_id for new_id; output is sha256:<64-hex>
5 LI_02 _fmt_entry uses long_id for old_id; "initial" sentinel unchanged
6 LI_03 Unused `short: int = 12` parameter removed from _fmt_entry signature
7 LI_04 _fmt_entry docstring updated -- no stale short-ID / false-consistency claim
8 LI_05 Module-level format spec (`<new_sha12>`) updated to reflect full IDs
9 LI_06 muse reflog human text output contains the full 64-hex ID of the most
10 recent entry, not a 12-char prefix
11 """
12 from __future__ import annotations
13
14 import datetime
15 import inspect
16
17 from muse.core.types import NULL_COMMIT_ID, long_id
18
19
20 def _entry(new_id: str, old_id: str = NULL_COMMIT_ID, operation: str = "commit: test"):
21 from muse.core.reflog import ReflogEntry
22
23 return ReflogEntry(
24 old_id=old_id,
25 new_id=new_id,
26 author="user",
27 timestamp=datetime.datetime(2026, 6, 28, 14, 22, 11, tzinfo=datetime.timezone.utc),
28 operation=operation,
29 )
30
31
32 # ---------------------------------------------------------------------------
33 # LI_01 -- new_id rendered as the full long_id
34 # ---------------------------------------------------------------------------
35
36
37 def test_li_01_new_id_rendered_as_long_id() -> None:
38 from muse.cli.commands.reflog import _fmt_entry
39
40 new_id = long_id("a" * 64)
41 entry = _entry(new_id=new_id, old_id=long_id("b" * 64))
42 result = _fmt_entry(0, entry)
43
44 assert new_id in result
45 assert new_id.split(":", 1)[1] == "a" * 64 # sanity: this really is the 64-hex form
46
47
48 # ---------------------------------------------------------------------------
49 # LI_02 -- old_id rendered as the full long_id; "initial" sentinel unchanged
50 # ---------------------------------------------------------------------------
51
52
53 def test_li_02_old_id_rendered_as_long_id() -> None:
54 from muse.cli.commands.reflog import _fmt_entry
55
56 old_id = long_id("c" * 64)
57 entry = _entry(new_id=long_id("d" * 64), old_id=old_id)
58 result = _fmt_entry(0, entry)
59
60 assert old_id in result
61
62
63 def test_li_02b_initial_sentinel_unchanged_for_null_old_id() -> None:
64 from muse.cli.commands.reflog import _fmt_entry
65
66 entry = _entry(new_id=long_id("e" * 64), old_id=NULL_COMMIT_ID)
67 result = _fmt_entry(0, entry)
68
69 assert "initial" in result
70 assert NULL_COMMIT_ID not in result
71
72
73 # ---------------------------------------------------------------------------
74 # LI_03 -- the unused `short` parameter is gone
75 # ---------------------------------------------------------------------------
76
77
78 def test_li_03_short_parameter_removed() -> None:
79 from muse.cli.commands.reflog import _fmt_entry
80
81 params = inspect.signature(_fmt_entry).parameters
82 assert "short" not in params
83
84
85 # ---------------------------------------------------------------------------
86 # LI_04 -- docstring no longer makes the false "short IDs for consistency" claim
87 # ---------------------------------------------------------------------------
88
89
90 def test_li_04_docstring_no_stale_short_id_claim() -> None:
91 from muse.cli.commands.reflog import _fmt_entry
92
93 doc = (_fmt_entry.__doc__ or "").lower()
94 assert "short" not in doc
95
96
97 # ---------------------------------------------------------------------------
98 # LI_05 -- module format-spec comment reflects full IDs, not <new_sha12>
99 # ---------------------------------------------------------------------------
100
101
102 def test_li_05_module_docstring_format_spec_updated() -> None:
103 import muse.cli.commands.reflog as reflog_module
104
105 doc = reflog_module.__doc__ or ""
106 assert "sha12" not in doc
107
108
109 # ---------------------------------------------------------------------------
110 # LI_06 -- end-to-end: human text output contains the full 64-hex commit ID
111 # ---------------------------------------------------------------------------
112
113
114 def test_li_06_fmt_entry_output_has_no_12_char_short_form() -> None:
115 import re
116
117 from muse.cli.commands.reflog import _fmt_entry
118
119 new_id = long_id("f" * 64)
120 old_id = long_id("1" * 64)
121 entry = _entry(new_id=new_id, old_id=old_id)
122 result = _fmt_entry(0, entry)
123
124 assert new_id in result
125 assert old_id in result
126
127 hex_tokens = re.findall(r"sha256:([0-9a-f]+)", result)
128 assert hex_tokens, "expected at least one sha256:<hex> token in the output"
129 for token in hex_tokens:
130 assert len(token) == 64, (
131 f"found a non-64-hex commit ID token ({len(token)} chars) -- "
132 f"the short-ID bug is back: {token!r}"
133 )
File History 1 commit
sha256:37af4ab271a64f11d7bf14b4871ebaaf5dd68fb0247521007c6b034d35aa01be Merge branch 'fix/hub-user-read-update-path' into dev Human 10 days ago