gabriel / muse public
test_store_branch_heads.py python
84 lines 3.3 KB
Raw
sha256:81ae324db5ad375fbfe4834c6fcb378312cafad3cc92dec5d3e5c427306621a2 fix: remove commit_exists filter from have anchors — server… Sonnet 4.6 patch 21 days ago
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)
File History 4 commits
sha256:81ae324db5ad375fbfe4834c6fcb378312cafad3cc92dec5d3e5c427306621a2 fix: remove commit_exists filter from have anchors — server… Sonnet 4.6 patch 21 days ago
sha256:36c3cb3e76619d4c30a6d9bf81b5ec4ff148e30dcfed913e3114ca7b43b81c7e fix: rename objects→blobs in push client and all stale test… Sonnet 4.6 patch 22 days ago
sha256:c06a9b9b9fee26c68ea725b44d54b2c0a171301ce9de746d5b656617b4463a9a fix: repair four test failures from post-migration audit Sonnet 4.6 patch 28 days ago
sha256:1900655993c83c4107067375548a7be823e471d2515830842f1a12cba4bd3cdf fix: unified object store migration — idempotent writes, JS… Sonnet 4.6 minor 29 days ago