Skip to content

fix(#909): resolveLocksDir resolves against the shared git checkout root, not cwd - #918

Merged
admarble merged 2 commits into
mainfrom
feature/909-fix-locks-locks-dir-is-cwd-relative-while-the-
Aug 8, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/909-fix-locks-locks-dir-is-cwd-relative-while-the-

Conversation

@admarble

@admarble admarble commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolveLocksDir resolved .sequant/locks against process.cwd(), while pre-tool.sh's checkout guard reads it from the command's git toplevel — the two only agreed when the CLI ran from the repository root, so acquiring a lock from a subdirectory was a silent no-op with zero protection.
  • Fix resolves via git rev-parse --path-format=absolute --git-common-dir, which also unifies a linked worktree with the main checkout's locks dir (deliberately chosen over the issue's own --show-toplevel fix sketch — see rationale in the CHANGELOG entry and QA notes). Falls back to today's cwd-relative behavior outside a git repository.
  • No call-site changes needed — every consumer (status, merge, resume, run-orchestrator, locks) already routes through this one function.

AC Coverage

  • AC-1: resolveLocksDir resolves against the shared git checkout root, not process.cwd()
  • AC-2: A linked worktree resolves to the main checkout's locks directory, not its own
  • AC-3: Non-git cwd falls back to today's cwd-relative behavior
  • AC-4: SEQUANT_LOCKS_DIR and the explicit locksDir option keep top priority

Test plan

  • npm run build — clean
  • npm run lint — clean
  • npx vitest run src/lib/locks/ — 155 passed (58 unit + 4 new AC tests + checkout-lock + other integration)
  • Mutation-verified: reverting the fix makes the new AC-1/AC-2 tests fail exactly as expected, then restored
  • Targeted regression run across all LockManager/CheckoutLock consumers (status, resume, run-orchestrator, locks CLI integration) — 211 passed total

Closes #909

🤖 Generated with Claude Code

…oot, not cwd

acquiring a lock from a subdirectory (or a linked worktree) was a silent
no-op: pre-tool.sh's checkout guard reads .sequant/locks from the command's
git toplevel, while resolveLocksDir resolved it against process.cwd(). The
two only agreed when the CLI ran from the repository root.

Resolves via `git rev-parse --path-format=absolute --git-common-dir`, which
also unifies a linked worktree with the main checkout's locks dir (both lock
types need to be visible from any worktree). Falls back to today's
cwd-relative behavior outside a git repository. SEQUANT_LOCKS_DIR and an
explicit locksDir option keep top priority, unchanged.

No call-site changes needed -- LockManager/CheckoutLock construction is the
single choke point every consumer (status, merge, resume, run-orchestrator,
locks) already goes through.
…, class coverage

- Drop the --path-format=absolute dependency (Git >=2.31): plain
  --git-common-dir (Git >=2.5) resolved by hand via resolve(cwd, out)
  works identically and doesn't silently re-open the bug on an older
  git, where the flag would fail into the same catch as "not a repo".

- Add an end-to-end integration test that drives the real built CLI to
  acquire the checkout lock from a subdirectory with no
  SEQUANT_LOCKS_DIR override, then runs the real pre-tool.sh hook
  against it -- the literal scenario from the bug report, not just the
  unit that fixes it. Mutation-verified: fails against the pre-fix
  behavior, passes against the fix.

- Add LockManager/CheckoutLock class-level tests (not just the bare
  resolveLocksDir function) so CheckoutLock's use of the fix is
  exercised directly instead of relying on "it imports the same
  function" by inspection.
@admarble
admarble merged commit 5ddeba1 into main Aug 8, 2026
5 checks passed
@admarble
admarble deleted the feature/909-fix-locks-locks-dir-is-cwd-relative-while-the- branch August 8, 2026 09:17
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.

fix(locks): locks dir is cwd-relative while the hook reads the git toplevel — acquiring from a subdirectory silently protects nothing

1 participant