"""TDD -- muse#52: `muse reflog` human text output must use long_id, not short_id. Deliverables: LI_01 _fmt_entry uses long_id for new_id; output is sha256:<64-hex> LI_02 _fmt_entry uses long_id for old_id; "initial" sentinel unchanged LI_03 Unused `short: int = 12` parameter removed from _fmt_entry signature LI_04 _fmt_entry docstring updated -- no stale short-ID / false-consistency claim LI_05 Module-level format spec (``) updated to reflect full IDs LI_06 muse reflog human text output contains the full 64-hex ID of the most recent entry, not a 12-char prefix """ from __future__ import annotations import datetime import inspect from muse.core.types import NULL_COMMIT_ID, long_id def _entry(new_id: str, old_id: str = NULL_COMMIT_ID, operation: str = "commit: test"): from muse.core.reflog import ReflogEntry return ReflogEntry( old_id=old_id, new_id=new_id, author="user", timestamp=datetime.datetime(2026, 6, 28, 14, 22, 11, tzinfo=datetime.timezone.utc), operation=operation, ) # --------------------------------------------------------------------------- # LI_01 -- new_id rendered as the full long_id # --------------------------------------------------------------------------- def test_li_01_new_id_rendered_as_long_id() -> None: from muse.cli.commands.reflog import _fmt_entry new_id = long_id("a" * 64) entry = _entry(new_id=new_id, old_id=long_id("b" * 64)) result = _fmt_entry(0, entry) assert new_id in result assert new_id.split(":", 1)[1] == "a" * 64 # sanity: this really is the 64-hex form # --------------------------------------------------------------------------- # LI_02 -- old_id rendered as the full long_id; "initial" sentinel unchanged # --------------------------------------------------------------------------- def test_li_02_old_id_rendered_as_long_id() -> None: from muse.cli.commands.reflog import _fmt_entry old_id = long_id("c" * 64) entry = _entry(new_id=long_id("d" * 64), old_id=old_id) result = _fmt_entry(0, entry) assert old_id in result def test_li_02b_initial_sentinel_unchanged_for_null_old_id() -> None: from muse.cli.commands.reflog import _fmt_entry entry = _entry(new_id=long_id("e" * 64), old_id=NULL_COMMIT_ID) result = _fmt_entry(0, entry) assert "initial" in result assert NULL_COMMIT_ID not in result # --------------------------------------------------------------------------- # LI_03 -- the unused `short` parameter is gone # --------------------------------------------------------------------------- def test_li_03_short_parameter_removed() -> None: from muse.cli.commands.reflog import _fmt_entry params = inspect.signature(_fmt_entry).parameters assert "short" not in params # --------------------------------------------------------------------------- # LI_04 -- docstring no longer makes the false "short IDs for consistency" claim # --------------------------------------------------------------------------- def test_li_04_docstring_no_stale_short_id_claim() -> None: from muse.cli.commands.reflog import _fmt_entry doc = (_fmt_entry.__doc__ or "").lower() assert "short" not in doc # --------------------------------------------------------------------------- # LI_05 -- module format-spec comment reflects full IDs, not # --------------------------------------------------------------------------- def test_li_05_module_docstring_format_spec_updated() -> None: import muse.cli.commands.reflog as reflog_module doc = reflog_module.__doc__ or "" assert "sha12" not in doc # --------------------------------------------------------------------------- # LI_06 -- end-to-end: human text output contains the full 64-hex commit ID # --------------------------------------------------------------------------- def test_li_06_fmt_entry_output_has_no_12_char_short_form() -> None: import re from muse.cli.commands.reflog import _fmt_entry new_id = long_id("f" * 64) old_id = long_id("1" * 64) entry = _entry(new_id=new_id, old_id=old_id) result = _fmt_entry(0, entry) assert new_id in result assert old_id in result hex_tokens = re.findall(r"sha256:([0-9a-f]+)", result) assert hex_tokens, "expected at least one sha256: token in the output" for token in hex_tokens: assert len(token) == 64, ( f"found a non-64-hex commit ID token ({len(token)} chars) -- " f"the short-ID bug is back: {token!r}" )