CodeNomad/scripts/native-fixture-guards.test.mjs
Pascal André 8e32d4626b
test(opencode): bound native migration acceptance and cleanup
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.
2026-09-20 16:50:04 +02:00

27 lines
1.2 KiB
JavaScript

import assert from "node:assert/strict"
import test from "node:test"
import { fixturePaginationGuard, stopFixtureChild } from "./native-fixture-guards.mjs"
test("fixture cleanup escalates a stuck owned child and returns a bounded failure", async () => {
const signals = []
let released = false
const child = { pid: 123, kill: signal => signals.push(signal ?? "SIGTERM"), unref: () => { released = true } }
await assert.rejects(stopFixtureChild(child, new Promise(() => {}), 5, 5), /forced termination/)
assert.deepEqual(signals, ["SIGTERM", "SIGKILL"])
assert.equal(released, true)
})
test("fixture cleanup accepts an owned child closing after forced termination", async () => {
let closed
const stopped = new Promise(resolve => { closed = resolve })
const signals = []
const child = { kill: signal => { signals.push(signal ?? "SIGTERM"); if (signal === "SIGKILL") closed() } }
await stopFixtureChild(child, stopped, 5, 5)
assert.deepEqual(signals, ["SIGTERM", "SIGKILL"])
})
test("native pagination rejects cycles instead of looping indefinitely", () => {
const accept = fixturePaginationGuard()
accept("one"); accept("two")
assert.throws(() => accept("one"), /repeated a nonterminal cursor/)
})