test(workspace): fail any test that leaves a skill sync running

Merged
RA
1mo ago
+155-43

Issue for this PR

Closes #1398

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Follow-up to #1391. Stops workspace tests from leaving skill syncs running after they end, and adds a check that catches the next one. Test-only.

  • Preload guard. After every test, test/preload.ts fails the test if a workspace skill sync it started is still running, and names the directory. It reads skill-sync's store through its process-global key rather than importing the module, so module load order is unchanged, and it never waits: a waiting version hung the next test.
  • Leaking tests fixed at the source. Every recordApprovedBinding call under test/ now passes awaitBackfill: true. create-then-rebind flushes the TUI path's deliberately detached sync in its afterEach, bounded at 5 s.
  • Awaited syncs stay offline. A shared fixture answers a fake host's skill-list request with an empty page; the four files whose syncs could reach the network use it, restored per test.

Claims (for review)

  • C1: No test in this package ends with a skill sync it started still in flight. A test that does fails with the directory named; a sync already running when a test started is reported as inherited, not as that test's.
  • C2: The guard neither imports skill-sync nor waits.
  • C3: (Moved to main) The identity-section test that passed only because of a leaked sync was corrected on main in #1397; this PR now only adds awaitBackfill to it.
  • C4: No production behavior changes; skill-sync.ts gains only a comment noting the preload reads its store key.
  • C5: None of the changed test files sends a workspace or skill request to the real network, whether the workspace feature is on or off. (routing-pin still fetches models.dev, as on main.)

Residuals (known, out of scope):

  • R1: The guard sees a leak only if the sync is still running when the test ends, so a new un-awaited call can pass locally and fail on a slower runner, and a sync whose start is deferred past its own test lands on the next one. The message says both; exact ownership would need skill-sync to tag each sync, a production change.
  • R2: Memory mirrors are not checked. None leaked in any of the 7 files.
  • R3: If skill-sync's store key is renamed, the guard finds no store and passes silently.
  • R4: The guard has no self-test; own, inherited and blame-once reporting were checked by hand.

How did you verify your code works?

  • Leak inventory (main): 27 tests in 7 files leave syncs, some never settling. On this branch the guard passes in all of them.
  • Zombie cost: identity-section then skill-sync took 43.7 s on main ("would abandon" fails at the default 5 s timeout); 13.5 s here, all passing.
  • Guard: removing awaitBackfill from routing-pin fails a routing-pin test with the guard's message.
  • C5: a preload hook logging real-network requests saw none from the changed files, flag set or unset. launch-resolve against a listener that never answers: 92.3 s before the stub, 2.3 s after.
  • Full suite as CI's main pass runs it, merged with current main: the guard never fired across 793 files; the other failures are local-only (they fail on main here, or pass when rerun alone).
  • Typecheck and Marker Guard clean.

Screenshots / recordings

N/A, test-only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Appendix — complexity delta

✅ No touched function changed in complexity (0 touched, 0 new, all under 10).

🤖 Generated with Claude Code

https://claude.ai/code/session_0174HUYiaceApqHP7EKMNgnb


Summary by cubic

Fixes test pollution where workspace tests left skill syncs running past their end, and adds a guard that fails any test that leaks one. Test-only, plus a comment in skill-sync.ts; no production behavior changes. Closes #1398.

Bug Fixes

  • Added a post-test guard in test/preload.ts that fails a test leaving a skill sync running, naming the leaked directory; it reads the store via its process-global key, never waits, and reports syncs already running at test start as inherited rather than the test's own.
  • All recordApprovedBinding calls now pass awaitBackfill: true, including the skill-sync negative-cache test and the new isApprovedRow tests; create-then-rebind flushes its deliberately detached TUI sync in afterEach, bounded at 5s.
  • Corrected identity-section's "a step arriving after an unlink" test, which hung on main and only passed because of a sync leaked from another test; it now asserts the unlinked step renders unbound without making its own request.
  • Added a shared stubEmptySkillList fixture that answers the awaited syncs' skill-list requests offline in launch-resolve, state-account-scope, plugin cache, and routing-pin tests, so they don't hit the real network.

Summary by CodeRabbit

  • Tests
    • Updated workspace tests to wait for background synchronization and backfill before checking results.
    • Added detection and reporting for skill-sync operations that remain unfinished at the end of a test.
    • Improved isolation of skill-list requests and fetch cleanup across tests.
    • Updated workspace binding tests covering identity, memory synchronization, routing, account scoping, permissions, and credentials to use controlled synchronization behavior.