"""TDD — granular untracked-entry labels in muse status long-form output. UL-1 Untracked file shows "untracked file:" label UL-2 Untracked directory shows "untracked directory:" label UL-3 Untracked directory does NOT show "untracked file:" label UL-4 Mixed: both labels appear when file and dir are both untracked """ from __future__ import annotations import datetime import json import pathlib from collections.abc import Mapping import pytest from tests.cli_test_helper import CliRunner from muse.core.paths import muse_dir, ref_path from muse.core.object_store import write_object from muse.core.ids import hash_commit, hash_snapshot from muse.core.commits import CommitRecord, write_commit from muse.core.snapshots import SnapshotRecord, write_snapshot from muse.core.types import blob_id runner = CliRunner() def _init_repo(path: pathlib.Path) -> pathlib.Path: dot = muse_dir(path) for d in ("commits", "snapshots", "objects", "refs/heads", "code"): (dot / d).mkdir(parents=True, exist_ok=True) (dot / "HEAD").write_text("ref: refs/heads/main", encoding="utf-8") (dot / "repo.json").write_text( json.dumps({"repo_id": "ul-test", "domain": "code"}), encoding="utf-8" ) return path def _make_commit(root: pathlib.Path, files: Mapping[str, bytes]) -> str: manifest: dict[str, str] = {} for rel, content in files.items(): oid = blob_id(content) write_object(root, oid, content) manifest[rel] = oid snap_id = hash_snapshot(manifest) write_snapshot(root, SnapshotRecord(snapshot_id=snap_id, manifest=manifest)) committed_at = datetime.datetime.now(datetime.timezone.utc) commit_id = hash_commit( parent_ids=[], snapshot_id=snap_id, message="init", committed_at_iso=committed_at.isoformat(), ) write_commit(root, CommitRecord( commit_id=commit_id, branch="main", snapshot_id=snap_id, message="init", committed_at=committed_at, )) ref_path(root, "main").write_text(commit_id, encoding="utf-8") return commit_id def _env(root: pathlib.Path) -> Mapping[str, str]: return {"MUSE_REPO_ROOT": str(root)} def _status(root: pathlib.Path) -> str: return runner.invoke(None, ["status"], env=_env(root)).output # --------------------------------------------------------------------------- # UL-1 Untracked file shows "untracked file:" # --------------------------------------------------------------------------- class TestUntrackedFileLabel: def test_untracked_file_label( self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch ) -> None: root = _init_repo(tmp_path) _make_commit(root, {"readme.md": b"# hi\n"}) monkeypatch.chdir(root) (root / "new.py").write_text("# new\n") out = _status(root) assert "untracked file:" in out, f"Expected 'untracked file:' in:\n{out}" # --------------------------------------------------------------------------- # UL-2 Untracked directory shows "untracked directory:" # --------------------------------------------------------------------------- class TestUntrackedDirectoryLabel: def test_untracked_directory_label( self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch ) -> None: root = _init_repo(tmp_path) _make_commit(root, {"readme.md": b"# hi\n"}) monkeypatch.chdir(root) (root / "test").mkdir() out = _status(root) assert "untracked directory:" in out, f"Expected 'untracked directory:' in:\n{out}" # UL-3 def test_untracked_directory_not_labeled_as_file( self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch ) -> None: root = _init_repo(tmp_path) _make_commit(root, {"readme.md": b"# hi\n"}) monkeypatch.chdir(root) (root / "test").mkdir() out = _status(root) assert "untracked file:" not in out, ( f"Directory must not be labeled 'untracked file:' in:\n{out}" ) # --------------------------------------------------------------------------- # UL-4 Mixed: both labels when file and dir are untracked # --------------------------------------------------------------------------- class TestUntrackedMixed: def test_mixed_untracked_shows_both_labels( self, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch ) -> None: root = _init_repo(tmp_path) _make_commit(root, {"readme.md": b"# hi\n"}) monkeypatch.chdir(root) (root / "test").mkdir() (root / "new.py").write_text("# new\n") out = _status(root) assert "untracked file:" in out assert "untracked directory:" in out