Skip to content

verify-worktree: don't accept a stale real dir as a valid link on POSIX#489

Merged
dsarno merged 2 commits into
mainfrom
fix/verify-worktree-stale-dir
May 30, 2026
Merged

verify-worktree: don't accept a stale real dir as a valid link on POSIX#489
dsarno merged 2 commits into
mainfrom
fix/verify-worktree-stale-dir

Conversation

@dsarno

@dsarno dsarno commented May 30, 2026

Copy link
Copy Markdown
Contributor

Problem

script/verify-worktree's Invariant-2 check has a macOS/Linux blind spot. The link test_project/addons/godot_ai should be a symlink into this worktree's plugin/addons/godot_ai (or, on Windows, a directory junction).

The elif [ -d "$link" ] fallback was meant only to accept genuine Windows directory junctions, which appear as plain dirs to bash. But on macOS/Linux it also matched a stale real directory — a full copy of an old plugin left behind by a self-update smoke test or a botched checkout. The script saw plugin.gd inside it, printed [ok], and exited 0 without repairing — so a developer/agent silently tested OUTDATED plugin source. Hit in practice: a stale copy lacked a branch's game_helper.gd fix while [ok] was printed.

Fix

Gate the -d fallback to Windows only, reusing the same ${OS}/${OSTYPE} detection the script already uses for link creation. On POSIX, a non-symlink directory now falls through to the existing rm -rf "$link" + recreate-symlink path. Windows junction support (junctions look like plain dirs to bash, matched via plugin.gd presence) is unchanged.

Tests

New tests/unit/test_verify_worktree_link.py drives the script against a throwaway sandbox repo (the real worktree's link is never touched), POSIX-only:

  • stale real dir → repaired to symlink (the regression; also asserts it now resolves to the canonical plugin.gd, not the stale copy)
  • healthy symlink left intact ([ok], idempotent)
  • missing link created
  • wrong-target symlink repaired

All 4 pass; ruff check clean; bash -n syntax-ok.

Manual repro

cd ~/godot-ai
rm -rf test_project/addons/godot_ai
mkdir -p test_project/addons/godot_ai
touch test_project/addons/godot_ai/plugin.gd
script/verify-worktree          # before: [ok] (BUG). after: recreates the symlink.
ls -ld test_project/addons/godot_ai   # confirms it's a symlink again

🤖 Generated with Claude Code

Invariant-2's `-d` fallback was meant only for Windows directory junctions
(which appear as plain dirs to bash). On macOS/Linux it also matched a stale
real directory at test_project/addons/godot_ai — a full copy of an old plugin
left by a self-update smoke test or botched checkout. The script saw plugin.gd
inside it, printed [ok], and exited 0 without repairing, so the developer/agent
silently tested OUTDATED plugin source.

Gate the `-d` fallback to Windows only (reusing the existing ${OS}/${OSTYPE}
detection). On POSIX a non-symlink directory now falls through to the existing
rm -rf + recreate-symlink path. Windows junction support is unchanged.

Add tests/unit/test_verify_worktree_link.py: drives the script against a
throwaway sandbox repo (real worktree untouched) covering stale-real-dir
repair, healthy-symlink pass-through, missing-link creation, and
wrong-target repair. POSIX-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…e test

Satisfies the issue #397 lint (test_read_text_encoding) that the initial
commit tripped in CI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens script/verify-worktree so POSIX worktrees no longer accept a stale real directory as a valid test_project/addons/godot_ai plugin link.

Changes:

  • Adds Windows-only gating for the directory fallback used to accept junctions.
  • Adds POSIX unit coverage for stale directory repair, healthy symlinks, missing links, and wrong-target symlinks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
script/verify-worktree Restricts plain-directory acceptance to Windows junction scenarios.
tests/unit/test_verify_worktree_link.py Adds sandboxed pytest coverage for link creation and repair behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dsarno dsarno merged commit 4b3f76d into main May 30, 2026
15 checks passed
@dsarno dsarno deleted the fix/verify-worktree-stale-dir branch May 30, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants