feat(B-0191): add orchestrator state check script + close B-0191#2250
feat(B-0191): add orchestrator state check script + close B-0191#2250
Conversation
All primary acceptance criteria are now met: - AC1: tools/orchestrator-checks/verify-branch.ts (PR #1585) - AC2: .claude/settings.json hook wiring (PR #2151) - AC3: .claude/rules/zeta-expected-branch.md + CLAUDE.md pointer (PR #2239) - AC4: unit tests in verify-branch.test.ts - AC5: tools/orchestrator-checks/check-orchestrator-state.ts (this PR) The state-check script (Rule 0: TS not bash) emits structured JSON with currentBranch, expectedBranch, branchMatch, dirtyFiles, worktrees, and driftedWorktrees — the last field flags the CWD-bleed-over hazard when another worktree is on the same branch as ZETA_EXPECTED_BRANCH. Tests: 12 pass / 0 fail across both orchestrator-checks files. Build: 0 warnings / 0 errors. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65a0aa3e0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Fixed the worktree drift logic per Codex review (48c98fd): caller worktree now matched by CWD path prefix instead of positional slice(1). This handles linked-worktree invocations correctly when ZETA_EXPECTED_BRANCH is set. Tests pass, pushed. Will resolve thread. |
There was a problem hiding this comment.
Pull request overview
Adds the missing AC5 “worktree state” diagnostic for the orchestrator branch-verify mechanization (B-0191), with a Bun/TypeScript implementation that emits structured JSON, plus a small Bun test suite, and updates the backlog row to reflect completion.
Changes:
- Add
check-orchestrator-state.tsto report current branch, dirty files, andgit worktree list --porcelain(with an exit code indicating mismatch/drift). - Add Bun tests for
parseWorktreeListandcheckOrchestratorState. - Update the B-0191 backlog row metadata/content to mark the work as complete.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tools/orchestrator-checks/check-orchestrator-state.ts | New orchestrator “state check” script emitting JSON with branch/status/worktree info. |
| tools/orchestrator-checks/check-orchestrator-state.test.ts | Bun tests for parsing and state computation. |
| docs/backlog/P1/B-0191-orchestrator-branch-verify-mechanization-design-aaron-2026-05-04.md | Marks B-0191 as completed and updates the “remaining work” section. |
| // Own worktree is the first entry; exclude it from drift check. | ||
| const driftedWorktrees = | ||
| expectedBranch && worktrees.length > 1 | ||
| ? worktrees.slice(1).filter((w) => w.branch === expectedBranch) | ||
| : []; |
| function run(cmd: string, args: string[]): string { | ||
| const r = spawnSync(cmd, args, { encoding: "utf8" }); | ||
| if (r.status !== 0) { | ||
| throw new Error(`${cmd} ${args.join(" ")} failed: ${r.stderr}`); | ||
| } | ||
| return r.stdout; |
| test("parses a single bare worktree block", () => { | ||
| const raw = `worktree /repo\nHEAD abc123\nbranch refs/heads/main\n\n`; | ||
| const entries = parseWorktreeList(raw); | ||
| expect(entries).toHaveLength(1); | ||
| expect(entries[0].path).toBe("/repo"); | ||
| expect(entries[0].head).toBe("abc123"); | ||
| expect(entries[0].branch).toBe("main"); | ||
| expect(entries[0].bare).toBe(false); | ||
| }); |
| id: B-0191 | ||
| priority: P1 | ||
| status: open | ||
| status: done |
| ask: Aaron 2026-05-04 verbatim *"for humans this is why oh my zsh reminds us of many things like this it has branch name in the ui"* + same-tick *"maybe a deliberate design/redesign on the backlog?"* | ||
| created: 2026-05-04 | ||
| last_updated: 2026-05-09 | ||
| closed: 2026-05-09 |
| test("no expectation set -> branchMatch=true regardless of current branch", () => { | ||
| const state = checkOrchestratorState({}); | ||
| expect(state.branchMatch).toBe(true); | ||
| expect(state.expectedBranch).toBe(""); | ||
| expect(typeof state.currentBranch).toBe("string"); |
…2253) Follow-up to #2250 — the squash-merge window closed before these non-required CI fixes landed on the branch. - Replace entries[0]/[1]/[2] with entries[0]!/[1]!/[2]! and const [entry] destructuring with const entry = ...[0]! to satisfy noUncheckedIndexedAccess (TS2532 / TS18048) - Regenerate docs/BACKLOG.md so B-0076 (status: closed since commit 0a5af0c) renders as [x] rather than [ ] Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
tools/orchestrator-checks/check-orchestrator-state.ts— the AC5 worktree status diagnostic for B-0191 (Rule 0: TS not bash; original body spec'd.sh)tools/orchestrator-checks/check-orchestrator-state.test.ts— 8 unit tests coveringparseWorktreeListandcheckOrchestratorStateAcceptance criteria met
tools/orchestrator-checks/verify-branch.ts.claude/settings.json.claude/rules/zeta-expected-branch.mdWhat the script does
check-orchestrator-state.tsemits structured JSON:currentBranch/expectedBranch/branchMatch(same as verify-branch)dirtyFiles—git status --shortlinesworktrees— parsedgit worktree list --porcelainblocksdriftedWorktrees— worktrees (other than the caller's own) onZETA_EXPECTED_BRANCH— flags the CWD-bleed-over hazardExit 0 = clean; exit 1 = branch mismatch or drifted worktrees.
Test plan
bun test tools/orchestrator-checks/→ 12 pass / 0 faildotnet build -c Release→ 0 warnings / 0 errorsstatus: doneoperative-authorization: aaron 2026-05-04: "it**, not just the output. Grinding through failures + recoveries"
🤖 Generated with Claude Code