Skip to content

refactor(#1475): worktreeStatus tri-state replaces both isWorktreeDirty copies; one formatSignalLine - #1563

Merged
admarble merged 4 commits into
mainfrom
feature/1475-refactor-workflow-locks-worktreestatus-tri-state-r
Oct 20, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/1475-refactor-workflow-locks-worktreestatus-tri-state-r

Conversation

@admarble

@admarble admarble commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • worktreeStatus(path) (src/lib/workflow/worktree-manager.ts) returns "clean", "dirty" or "unknown". It is now the only place in src/lib/workflow that runs git status --porcelain to decide whether a worktree is dirty. It replaces both isWorktreeDirty copies and the freshness check's own call. It returns unknown when git cannot run or exits non-zero.
  • Each caller keeps its existing behaviour for unknown:
    • Signal-shutdown cleanup still keeps the worktree, but the log now says preserved (worktree status unreadable) instead of claiming uncommitted changes. This check runs before the commits-ahead check, which would otherwise mislabel the reason as "commits ahead of base".
    • The chain-resume resolver still treats unknown as not dirty.
    • checkWorktreeFreshness still treats it as not dirty.
  • formatSignalLine(issue, pid, result, { indent }) is now in src/lib/locks/signal-line.ts and exported from src/lib/locks/index.ts. sequant locks calls it with no indent; the orchestrator calls it with two spaces. Each reason has one text. For a stale PID, sequant run now prints the longer sequant locks wording.
  • The hand-written copy of the check in chain-resume.integration.test.ts now calls the real worktreeStatus.
  • The three porcelain parsers named in AC-1 (-z checkpoint, phase-executor.ts, qa-stagnation.ts) are untouched.

AC verification

AC Status Evidence
AC-1 ✅ rg -n '"status", "--porcelain"\]' src/lib/workflow -g '!*.test.ts' | wc -l → 1; the three parsers show no diff
AC-2 ✅ -t "worktreeStatus" → 8 passed, 0 failed. Covers clean, dirty, a held index.lock (still reads clean, then dirty), a non-existent path, a folder that is not a repo, and a worktree whose admin directory was removed (the last three read unknown)
AC-3 ✅ 6 passed, 0 failed. worktreePreserveReason(abort, "/nonexistent") returns "worktree status unreadable". A ready_for_merge link whose worktree folder is gone but whose branch is intact resumes on the branch tip with no failFast
AC-4 ✅ src/lib/locks/signal-line.test.ts → 4 passed
AC-5 ✅ The accretion-audit dups command prints none, exit 0
Derived: existing behaviour kept ✅ The checkWorktreeFreshness tests in run.test.ts and the #1222 tests are green and unchanged
Derived: a git spawn error becomes unknown ✅ result.error || result.status !== 0 → "unknown"

Note on AC-3: as /spec warned, the AC-3 filter also matches one unrelated isAutomatedPRBody test. There are still 5 new matching tests, so ≥ 2 passes on new tests alone.

Mutation-verified: AC-2 — non-zero exit mapped to clean; src/lib/workflow/worktree-manager.test.ts > worktreeStatus > a non-existent path is unknown failed, along with 3 other unknown cases; restored.

Mutation-verified: AC-3 — deleted the unknown reason line; only ...worktreePreserveReason keeps a status-unknown path without claiming uncommitted changes failed; restored.

Mutation-verified: AC-4 — dropped the indent prefix; the indented line is the unindented line with the prefix failed, along with the stale-PID text case; restored.

All three markers parse

Fixes #1475

QA verdict: NEEDS_VERIFICATION — acceptance criteria met, pending external verification (e.g. CI or a manual test). See the QA review comment.

Runner verification (2026-10-20)

After merging main (through #1509), the runner re-ran AC-1..AC-5 verbatim at 80e63c3:

  • AC-1: 1
  • AC-2: 8 passed
  • AC-3: 6 passed
  • AC-4: 4 passed
  • AC-5: none
  • run-orchestrator.test.ts: 15 passed
  • Lint green; build exit 0.

The baseline records unusedExports 339 (from 341).

The runner repeated the AC-2 mutation: mapping a non-zero git status exit to clean fails a non-existent path is unknown plus 3 sibling cases. Restored.

QA's dropped finding stays dropped: the SignalOtherResult re-export is advisory, and knip's count fell overall.


🤖 Generated with Claude Code

@admarble
admarble merged commit 2e041f0 into main Oct 20, 2026
9 of 10 checks passed
@admarble
admarble deleted the feature/1475-refactor-workflow-locks-worktreestatus-tri-state-r branch October 20, 2026 02:53
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.

refactor(workflow,locks): worktreeStatus tri-state replaces both isWorktreeDirty copies; one formatSignalLine

1 participant