Skip to content

test(#1322): state.test.ts idempotency and state-utils discoverUntrackedWorktrees cases fail under full-suite load, pass alone - #1395

Merged
admarble merged 3 commits into
mainfrom
feature/1322-test-state-test-ts-idempotency-and-state-utils-dis
Oct 10, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/1322-test-state-test-ts-idempotency-and-state-utils-dis

Conversation

@admarble

@admarble admarble commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

What was wrong. discoverUntrackedWorktrees read the real git worktree list and ran one gh issue view per issue worktree, each with a 10 s timeout. Each failing test called discovery twice. On CI there are no issue worktrees, so the if (discovered.length > 0) branches never ran and the tests asserted nothing.

Fix (test-only, no production change):

  • New src/lib/workflow/__fixtures__/worktree-discovery.fixture.ts: stands in for spawnSync and answers by command and arguments, not call order:
    • git worktree list --porcelain returns a fixed list as a Buffer: main, a detached HEAD, chore/tidy-docs, and three issue worktrees (9001, 9002, 9003).
    • gh issue view <N> --json title returns a canned title.
    • Any other command runs the real spawnSync.
  • src/lib/workflow/state-utils.test.ts: sets up the fixture in beforeEach of the discovery describe and resets it in afterEach. The if/else fallback is gone. The test now checks that exactly the tracked worktree drops out and that alreadyTracked === 1. The 30 s timeout is removed.
  • src/commands/state.test.ts: fakes child_process the same way and sets up the fixture. The idempotency test now asserts every time. The "clear output" test now requires at least one discovered and one skipped worktree, so its loops actually check something. Both 30 s timeouts are removed; every test now runs in under 20 ms.

Pre-PR AC Verification

AC Source Status Evidence
AC-1 Original ✅ Shared-state interference (corrected runner comment on #1322). The tests ran discovery against the checkout's real git worktree list, with one gh issue view per issue worktree. Run time grew with the worktree count, and assertions failed when a concurrent run changed the list (exec's before-run: state.test.ts:58, state-utils.test.ts:320). The runner's first classification, load-induced timeout, was wrong.
AC-2 Original ✅ The cause is shared state, so AC-2 applies. The fixture gives both tests a fixed worktree list and canned gh titles, and they already used a mkdtemp statePath. Neither reads the real worktree list or the checkout's .sequant/state.json.
AC-3 Original ✅ Setup cost removed: no gh calls and no real git worktree list. The 30 s timeouts are dropped rather than raised.
AC-4 Original ✅ Three consecutive full-suite runs on f5fe3054, run by the runner. Both tests passed in all three (see below).
AC-5 Derived ✅ Every discovery test is under 1 s alone (table below).
AC-6 Derived ✅ Mutation record below.

Per-test durations, both files run alone:

Test Before After
state.test.ts › state init should be idempotent 11378 ms (failed on assertion) 16 ms
state.test.ts › discoverUntrackedWorktrees returns structured data 10313 ms 3 ms
state-utils.test.ts › should return success when called 11170 ms 2 ms
state-utils.test.ts › should not discover worktrees that are already tracked 20028 ms (failed on assertion) 3 ms
Whole run of both files 39.12 s 6.15 s

Mutation-verified: AC-6 — commented out the continue after alreadyTracked++ in worktree-discovery.ts. src/lib/workflow/state-utils.test.ts > state-utils > discoverUntrackedWorktrees > should not discover worktrees that are already tracked failed, along with src/commands/state.test.ts > state command > idempotency (AC-4) > state init should be idempotent - running twice yields same result. Only those two failed (2 failed, 39 passed). Restored.

parseMutationMarkers reads the marker back correctly.

Checks

  • Build: npm run build passed.
  • Lint: npm run lint passed with 0 warnings.
  • Tests: `npx vitest run src/commands/state.test.ts src/lib/workflow/state-utils.test.ts scripts/qa/tautology-detector-cli.test.ts src/commands/state-e

AC-4: three consecutive full-suite runs (runner, f5fe3054, npx vitest run --project unit --project integration)

Run Summary state init should be idempotent should not discover worktrees that are already tracked
1 Tests 1 failed | 9091 passed | 1 expected fail | 3 skipped (9096) passed, 17 ms passed, 2 ms
2 Tests 1 failed | 9091 passed | 1 expected fail | 3 skipped (9096) passed, 24 ms passed, 3 ms
3 Tests 1 failed | 9091 passed | 1 expected fail | 3 skipped (9096) passed, 17 ms passed, 4 ms

The single failure in each run is driver-conformance.test.ts > codex commit: git add and git commit succeed inside the driver's default sandbox (git exit 128). It fails the same way on main (c8762a2c) on this machine and passes in CI. It comes from the local codex sandbox and is unrelated to this diff.

Plugin freeze (I-1): git diff --name-only origin/main...HEAD | grep -E '^(plugin|\.claude/skills|templates/skills)/' is empty.

Fixes #1322

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


🤖 Generated by sequant run; runner sections added with Claude Code

… tests

The state.test.ts idempotency and state-utils discovery tests ran against the real checkout: one gh issue view per issue worktree (10-20 s per test, load-sensitive) and a git worktree list that other sessions change mid-test. On CI they asserted nothing. A spawnSync fixture keyed on command + args answers git worktree list and gh issue view; the conditional assertions are now unconditional and the 30 s describe timeouts are gone.

Entire-Checkpoint: 5e3a2c5cf92a
@admarble
admarble merged commit afc37bd into main Oct 10, 2026
8 checks passed
@admarble
admarble deleted the feature/1322-test-state-test-ts-idempotency-and-state-utils-dis branch October 10, 2026 14:00
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.

test: state.test.ts idempotency and state-utils discoverUntrackedWorktrees cases fail under full-suite load, pass alone

1 participant