gabriel / muse public
test_status_untracked_labels.py python
136 lines 4.6 KB
Raw
sha256:a154bc65916614c833d5a40a10d81ba3eae0d0495b0afddd34dc34f18d5e91b8 fix: test suite alignment and typing audit — zero violations Sonnet 4.6 minor ⚠ breaking 22 days ago
1 """TDD — granular untracked-entry labels in muse status long-form output.
2
3 UL-1 Untracked file shows "untracked file:" label
4 UL-2 Untracked directory shows "untracked directory:" label
5 UL-3 Untracked directory does NOT show "untracked file:" label
6 UL-4 Mixed: both labels appear when file and dir are both untracked
7 """
8 from __future__ import annotations
9
10 import datetime
11 import json
12 import pathlib
13 from collections.abc import Mapping
14
15 import pytest
16
17 from tests.cli_test_helper import CliRunner
18 from muse.core.paths import muse_dir, ref_path
19 from muse.core.object_store import write_object
20 from muse.core.ids import hash_commit, hash_snapshot
21 from muse.core.commits import CommitRecord, write_commit
22 from muse.core.snapshots import SnapshotRecord, write_snapshot
23 from muse.core.types import blob_id
24
25 runner = CliRunner()
26
27
28 def _init_repo(path: pathlib.Path) -> pathlib.Path:
29 dot = muse_dir(path)
30 for d in ("commits", "snapshots", "objects", "refs/heads", "code"):
31 (dot / d).mkdir(parents=True, exist_ok=True)
32 (dot / "HEAD").write_text("ref: refs/heads/main", encoding="utf-8")
33 (dot / "repo.json").write_text(
34 json.dumps({"repo_id": "ul-test", "domain": "code"}), encoding="utf-8"
35 )
36 return path
37
38
39 def _make_commit(root: pathlib.Path, files: Mapping[str, bytes]) -> str:
40 manifest: dict[str, str] = {}
41 for rel, content in files.items():
42 oid = blob_id(content)
43 write_object(root, oid, content)
44 manifest[rel] = oid
45 snap_id = hash_snapshot(manifest)
46 write_snapshot(root, SnapshotRecord(snapshot_id=snap_id, manifest=manifest))
47 committed_at = datetime.datetime.now(datetime.timezone.utc)
48 commit_id = hash_commit(
49 parent_ids=[], snapshot_id=snap_id,
50 message="init", committed_at_iso=committed_at.isoformat(),
51 )
52 write_commit(root, CommitRecord(
53 commit_id=commit_id, branch="main", snapshot_id=snap_id,
54 message="init", committed_at=committed_at,
55 ))
56 ref_path(root, "main").write_text(commit_id, encoding="utf-8")
57 return commit_id
58
59
60 def _env(root: pathlib.Path) -> Mapping[str, str]:
61 return {"MUSE_REPO_ROOT": str(root)}
62
63
64 def _status(root: pathlib.Path) -> str:
65 return runner.invoke(None, ["status"], env=_env(root)).output
66
67
68 # ---------------------------------------------------------------------------
69 # UL-1 Untracked file shows "untracked file:"
70 # ---------------------------------------------------------------------------
71
72 class TestUntrackedFileLabel:
73 def test_untracked_file_label(
74 self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
75 ) -> None:
76 root = _init_repo(tmp_path)
77 _make_commit(root, {"readme.md": b"# hi\n"})
78 monkeypatch.chdir(root)
79 (root / "new.py").write_text("# new\n")
80
81 out = _status(root)
82
83 assert "untracked file:" in out, f"Expected 'untracked file:' in:\n{out}"
84
85
86 # ---------------------------------------------------------------------------
87 # UL-2 Untracked directory shows "untracked directory:"
88 # ---------------------------------------------------------------------------
89
90 class TestUntrackedDirectoryLabel:
91 def test_untracked_directory_label(
92 self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
93 ) -> None:
94 root = _init_repo(tmp_path)
95 _make_commit(root, {"readme.md": b"# hi\n"})
96 monkeypatch.chdir(root)
97 (root / "test").mkdir()
98
99 out = _status(root)
100
101 assert "untracked directory:" in out, f"Expected 'untracked directory:' in:\n{out}"
102
103 # UL-3
104 def test_untracked_directory_not_labeled_as_file(
105 self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
106 ) -> None:
107 root = _init_repo(tmp_path)
108 _make_commit(root, {"readme.md": b"# hi\n"})
109 monkeypatch.chdir(root)
110 (root / "test").mkdir()
111
112 out = _status(root)
113
114 assert "untracked file:" not in out, (
115 f"Directory must not be labeled 'untracked file:' in:\n{out}"
116 )
117
118
119 # ---------------------------------------------------------------------------
120 # UL-4 Mixed: both labels when file and dir are untracked
121 # ---------------------------------------------------------------------------
122
123 class TestUntrackedMixed:
124 def test_mixed_untracked_shows_both_labels(
125 self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
126 ) -> None:
127 root = _init_repo(tmp_path)
128 _make_commit(root, {"readme.md": b"# hi\n"})
129 monkeypatch.chdir(root)
130 (root / "test").mkdir()
131 (root / "new.py").write_text("# new\n")
132
133 out = _status(root)
134
135 assert "untracked file:" in out
136 assert "untracked directory:" in out
File History 2 commits
sha256:a154bc65916614c833d5a40a10d81ba3eae0d0495b0afddd34dc34f18d5e91b8 fix: test suite alignment and typing audit — zero violations Sonnet 4.6 minor 22 days ago
sha256:3767afb72520f9b56053bb98fd83d323f738ee4cad16e306e8cf6862608380e4 feat: first-class directory tracking across status, diff, r… Sonnet 4.6 minor 22 days ago