mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-10-21 13:54:39 +00:00
Ensure a wedged migration reports a failure instead of retaining a native fixture indefinitely. Apply a whole-run deadline and per-request cancellation through the generated client, bound startup/version probes, and reject repeated pagination cursors. Escalate termination only for the child spawned by the fixture, with bounded graceful/forced waits and explicit failure if termination cannot complete. Keep cleanup in finally blocks and add workflow timeout backstops. Gatekeeper re-review reports no remaining findings in acceptance/CI paths. Three failure-guard regressions pass; native historical migrations pass again on Windows and Linux with the guards enabled.
30 lines
1 KiB
JavaScript
30 lines
1 KiB
JavaScript
// Guards for isolated fixture-owned children and native acceptance pagination.
|
|
async function completesWithin(promise, timeoutMs) {
|
|
let timer
|
|
try {
|
|
return await Promise.race([promise.then(() => true), new Promise(resolve => {
|
|
timer = setTimeout(() => resolve(false), timeoutMs)
|
|
})])
|
|
} finally { clearTimeout(timer) }
|
|
}
|
|
|
|
export async function stopFixtureChild(child, stopped, graceMs = 1_000, forceMs = 2_000) {
|
|
child.kill()
|
|
if (await completesWithin(stopped, graceMs)) return
|
|
child.kill("SIGKILL")
|
|
if (await completesWithin(stopped, forceMs)) return
|
|
// A failed OS kill must report failure rather than retaining test handles.
|
|
child.stdout?.destroy()
|
|
child.stderr?.destroy()
|
|
child.stdin?.destroy()
|
|
child.unref()
|
|
throw new Error(`Fixture-owned child ${child.pid} did not exit after forced termination`)
|
|
}
|
|
|
|
export function fixturePaginationGuard() {
|
|
const seen = new Set()
|
|
return cursor => {
|
|
if (seen.has(cursor)) throw new Error("Native fixture pagination repeated a nonterminal cursor")
|
|
seen.add(cursor)
|
|
}
|
|
}
|