Files
reverse-engineering-anything/tests/fixtures/lifecycleAcknowledgement.ts
T
morluto b4a2a79c55 test(lifecycle): move local gate copies, tests/process-global and tests/boundary phase gates onto the shared harness (#11412)
* test(lifecycle): replace eight local gate helper copies with the shared harness

* test(lifecycle): count an arrival announced in the turn its operation settles

* test(lifecycle): move tests/process-global phase gates onto the shared harness (#11414)

* test(lifecycle): move tests/process-global phase gates onto the shared harness

* test(lifecycle): move tests/boundary filesystem and process phase gates onto the shared harness (#11418)

* test(lifecycle): move tests/boundary provider phase gates onto the shared harness

* test(lifecycle): move tests/boundary/mcp phase gates onto the shared harness (#11433)

* test(lifecycle): give each phaseGate hold its own promise so unhandled held rejections stay visible

* test(lifecycle): move tests/boundary browser, pcap and CLI worker phase gates onto the shared harness (#11437)

* test(lifecycle): move tests/boundary browser, pcap and CLI worker phase gates onto the shared harness

* test(lifecycle): move fixture-owned and arrival-only provider gates onto the shared harness (#11441)

* test(lifecycle): move src/server and provider phase gates onto the shared harness (#11447)

* test(lifecycle): move the remaining src server, Kuna copy, Frida and Ghidra phase gates onto the shared harness (#11471)
2026-11-16 04:49:19 +08:00

35 lines
1.2 KiB
TypeScript

import { testWaitDeadline } from "../support/testWait.js";
/**
* Fail if an operation settles, or the test's wait deadline passes, before it
* reaches its controlled lifecycle boundary.
*/
export const awaitAcknowledgement = async (
acknowledgement: Promise<unknown>,
operation: Promise<unknown>,
boundary: string,
timeoutMs = testWaitDeadline(),
): Promise<void> => {
let deadline: ReturnType<typeof setTimeout> | undefined;
try {
const observed = await Promise.race([
acknowledgement.then(() => ({ kind: "acknowledged" }) as const),
operation.then(
(value) => ({ kind: "settled", status: "fulfilled", value }) as const,
(cause: unknown) =>
({ kind: "settled", status: "rejected", cause }) as const,
),
new Promise<{ readonly kind: "deadline" }>((resolve) => {
deadline = setTimeout(() => resolve({ kind: "deadline" }), timeoutMs);
}),
]);
if (observed.kind !== "acknowledged")
throw new Error(
`${boundary} was not acknowledged before ${observed.kind === "deadline" ? "the gate deadline" : "the triggering operation settled"}`,
{ cause: observed },
);
} finally {
if (deadline !== undefined) clearTimeout(deadline);
}
};