test: drain the detached SubagentStart continuation before the bridge spec ends

The markers are touched mid-script, so runPoint's continuation chain (child
exit → merge → the listener's detached .then) can still be in flight when the
marker poll resolves; a vitest worker that exits first leaves the inject
condition's short-circuit path uncounted. Observed as a CI-only 99.03%
branch-coverage flake on hooks-claude — surfaced by this branch shifting suite
timing, latent before it. Two macrotask rounds pin the path deterministically.
This commit is contained in:
Tianyi Cui
2026-07-07 09:37:50 +08:00
parent b907c20213
commit 5a91893b86

View File

@@ -298,6 +298,14 @@ describe('hooks-claude bridge — SubagentStart / SubagentStop (observe)', () =>
await waitFor(() => existsSync(startMarker) && existsSync(stopMarker))
expect(existsSync(startMarker)).toBe(true)
expect(existsSync(stopMarker)).toBe(true)
// The markers are touched MID-script, so runPoint's continuation chain
// (child-exit event → merge → the listener's detached .then) can still be
// in flight when the poll resolves. Drain two macrotask rounds so the
// short-circuit path of the SubagentStart inject condition executes before
// this worker can exit — observed as a CI-only 99.03% branch-coverage
// flake on hooks-claude when the worker won the race.
await new Promise(resolve => setTimeout(resolve, 0))
await new Promise(resolve => setTimeout(resolve, 0))
})
})