fix(termux): resolve packed-refs and worktree refs in skill-sync fingerprint

The bundled-skill sync stamp added in the cherry-picked salvage commit
parsed .git/HEAD and looked for a loose ref file in the worktree gitdir
only, so two real cases hit the unresolved branch:

- repos after `git gc` where active refs live in packed-refs
- linked worktrees, whose branch ref lives in <commondir>/refs/heads/
  (verified on the worktree this salvage was built in)

Both fell back to a constant-string fingerprint, so post-commit launches
would never re-run the real skill sync. Now we resolve packed-refs and
check both the worktree gitdir and the common dir for loose refs.

Adds three tests covering: packed-refs resolution, worktree common-dir
packed lookup, worktree common-dir loose lookup, and the explicit
'unresolved' marker (still stable + version-fallback-safe).
This commit is contained in:
Teknium 2026-05-21 17:17:53 -07:00
parent 6dbbf20ff4
commit 2a474bcf72
2 changed files with 127 additions and 3 deletions

View file

@ -428,6 +428,88 @@ def test_termux_forced_bundled_skill_sync_runs(monkeypatch, tmp_path, main_mod):
assert calls == [True]
def test_read_git_revision_fingerprint_resolves_packed_refs(tmp_path, main_mod):
repo = tmp_path / "repo"
git_dir = repo / ".git"
git_dir.mkdir(parents=True)
(git_dir / "HEAD").write_text("ref: refs/heads/main\n", encoding="utf-8")
packed_sha = "1234567890abcdef1234567890abcdef12345678"
(git_dir / "packed-refs").write_text(
"# pack-refs with: peeled fully-peeled sorted\n"
f"{packed_sha} refs/heads/main\n"
"abcdef0000000000000000000000000000000000 refs/tags/v1.0\n"
"^99999999aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
encoding="utf-8",
)
fingerprint = main_mod._read_git_revision_fingerprint(repo)
assert fingerprint == f"git:refs/heads/main:{packed_sha}"
def test_read_git_revision_fingerprint_packed_refs_in_worktree_common_dir(
tmp_path, main_mod
):
main_repo = tmp_path / "repo"
common_git = main_repo / ".git"
common_git.mkdir(parents=True)
packed_sha = "fedcba9876543210fedcba9876543210fedcba98"
(common_git / "packed-refs").write_text(
f"{packed_sha} refs/heads/main\n",
encoding="utf-8",
)
worktree = tmp_path / "wt"
worktree.mkdir()
wt_gitdir = common_git / "worktrees" / "wt"
wt_gitdir.mkdir(parents=True)
(wt_gitdir / "HEAD").write_text("ref: refs/heads/main\n", encoding="utf-8")
(wt_gitdir / "commondir").write_text("../..\n", encoding="utf-8")
(worktree / ".git").write_text(f"gitdir: {wt_gitdir}\n", encoding="utf-8")
fingerprint = main_mod._read_git_revision_fingerprint(worktree)
assert fingerprint == f"git:refs/heads/main:{packed_sha}"
def test_read_git_revision_fingerprint_loose_ref_in_worktree_common_dir(
tmp_path, main_mod
):
"""`git worktree add -b NAME` writes the new branch ref to the common dir,
not the per-worktree gitdir. The fingerprint must still resolve it."""
main_repo = tmp_path / "repo"
common_git = main_repo / ".git"
common_git.mkdir(parents=True)
loose_sha = "0123456789abcdef0123456789abcdef01234567"
(common_git / "refs" / "heads").mkdir(parents=True)
(common_git / "refs" / "heads" / "feature").write_text(
loose_sha + "\n", encoding="utf-8"
)
worktree = tmp_path / "wt"
worktree.mkdir()
wt_gitdir = common_git / "worktrees" / "wt"
wt_gitdir.mkdir(parents=True)
(wt_gitdir / "HEAD").write_text("ref: refs/heads/feature\n", encoding="utf-8")
(wt_gitdir / "commondir").write_text("../..\n", encoding="utf-8")
(worktree / ".git").write_text(f"gitdir: {wt_gitdir}\n", encoding="utf-8")
fingerprint = main_mod._read_git_revision_fingerprint(worktree)
assert fingerprint == f"git:refs/heads/feature:{loose_sha}"
def test_read_git_revision_fingerprint_unresolved_ref_is_stable(tmp_path, main_mod):
repo = tmp_path / "repo"
git_dir = repo / ".git"
git_dir.mkdir(parents=True)
(git_dir / "HEAD").write_text("ref: refs/heads/missing\n", encoding="utf-8")
fingerprint = main_mod._read_git_revision_fingerprint(repo)
assert fingerprint == "git:refs/heads/missing:unresolved"
def test_main_top_level_oneshot_accepts_toolsets(monkeypatch, main_mod):
captured = {}