test(orchestration): fail loudly on an unexpected second detection call

The mock overwrote resolveDetection on every call, so a second invocation would
strand the first promise and hang to a 30s timeout instead of naming what
changed. A test that hangs rather than fails is how a real bug gets mistaken for
infrastructure noise.
This commit is contained in:
Neil
2026-09-01 18:22:59 -07:00
parent 4efc86a33c
commit 894c5fe36a
@@ -656,9 +656,21 @@ describe('legacy coordinator takeover races', () => {
const detectionStarted = new Promise<void>((resolve) => {
signalDetectionStarted = resolve
})
let detectionCalls = 0
vi.spyOn(harness.runtime, 'isTerminalRunningAgent').mockImplementation(
() =>
new Promise<boolean>((resolve) => {
new Promise<boolean>((resolve, reject) => {
detectionCalls += 1
// Why reject instead of re-arming: a second call would overwrite resolveDetection and
// strand the first promise, hanging to a timeout instead of naming what changed.
if (detectionCalls > 1) {
reject(
new Error(
`isTerminalRunningAgent was called ${detectionCalls} times; this test drives exactly one detection.`
)
)
return
}
resolveDetection = resolve
signalDetectionStarted?.()
})