gabriel / muse public

test_store_branch_heads.py file-level

at sha256:8 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:4 Merge branch 'dev' into main · gabriel · Jun 17, 2026
1 """Unit tests for get_all_branch_heads — store utility added with local transport."""
2
3 from __future__ import annotations
4
5 import pathlib
6
7 from muse.core.refs import get_all_branch_heads
8 from muse.core.types import long_id
9 from muse.core.paths import heads_dir
10
11
12 def _heads_dir(root: pathlib.Path) -> pathlib.Path:
13 d = heads_dir(root)
14 d.mkdir(parents=True, exist_ok=True)
15 return d
16
17
18 class TestGetAllBranchHeads:
19 def test_empty_heads_dir_returns_empty_dict(self, tmp_path: pathlib.Path) -> None:
20 _heads_dir(tmp_path)
21 result = get_all_branch_heads(tmp_path)
22 assert result == {}
23
24 def test_missing_heads_dir_returns_empty_dict(self, tmp_path: pathlib.Path) -> None:
25 # No .muse/ directory at all.
26 result = get_all_branch_heads(tmp_path)
27 assert result == {}
28
29 def test_single_branch(self, tmp_path: pathlib.Path) -> None:
30 heads = _heads_dir(tmp_path)
31 (heads / "main").write_text(long_id("a" * 64))
32 result = get_all_branch_heads(tmp_path)
33 assert result == {"main": long_id("a" * 64)}
34
35 def test_multiple_branches(self, tmp_path: pathlib.Path) -> None:
36 heads = _heads_dir(tmp_path)
37 (heads / "main").write_text(long_id("a" * 64))
38 (heads / "dev").write_text(long_id("b" * 64))
39 (heads / "feature").write_text(long_id("c" * 64))
40 result = get_all_branch_heads(tmp_path)
41 assert result == {
42 "main": long_id("a" * 64),
43 "dev": long_id("b" * 64),
44 "feature": long_id("c" * 64),
45 }
46
47 def test_whitespace_trimmed_from_ref_content(self, tmp_path: pathlib.Path) -> None:
48 heads = _heads_dir(tmp_path)
49 (heads / "main").write_text(f" {long_id('a' * 64)}\n")
50 result = get_all_branch_heads(tmp_path)
51 assert result["main"] == long_id("a" * 64)
52
53 def test_empty_ref_file_excluded(self, tmp_path: pathlib.Path) -> None:
54 heads = _heads_dir(tmp_path)
55 (heads / "main").write_text("")
56 result = get_all_branch_heads(tmp_path)
57 assert "main" not in result
58
59 def test_subdirectory_in_heads_is_skipped(self, tmp_path: pathlib.Path) -> None:
60 """Namespaced branches (feature/foo) are represented as subdirs — only
61 files are branch heads; subdirs are namespace containers."""
62 heads = _heads_dir(tmp_path)
63 (heads / "main").write_text(long_id("a" * 64))
64 sub = heads / "feature"
65 sub.mkdir()
66 (sub / "my-branch").write_text(long_id("b" * 64))
67 result = get_all_branch_heads(tmp_path)
68 # Only the flat file is returned (subdirs need recursive handling
69 # which is not the current contract — flat heads only).
70 assert "main" in result
71 assert "feature" not in result # the dir itself is not a head
72
73 def test_returns_dict_type(self, tmp_path: pathlib.Path) -> None:
74 _heads_dir(tmp_path)
75 result = get_all_branch_heads(tmp_path)
76 assert isinstance(result, dict)
77
78 def test_values_are_stripped_strings(self, tmp_path: pathlib.Path) -> None:
79 heads = _heads_dir(tmp_path)
80 cid = long_id("f" * 64)
81 (heads / "release").write_text(cid + "\n")
82 result = get_all_branch_heads(tmp_path)
83 assert result["release"] == cid
84 assert isinstance(result["release"], str)