test: dedupe acp startup test harness

This commit is contained in:
Peter Steinberger 2026-03-13 20:54:28 +00:00
parent 1301462a1b
commit d9fb1e0e45
1 changed files with 22 additions and 22 deletions

View File

@ -129,6 +129,22 @@ describe("serveAcpGateway startup", () => {
return { signalHandlers, onceSpy }; return { signalHandlers, onceSpy };
} }
async function emitHelloAndWaitForAgentSideConnection() {
const gateway = getMockGateway();
gateway.emitHello();
await vi.waitFor(() => {
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
});
}
async function stopServeWithSigint(
signalHandlers: Map<NodeJS.Signals, () => void>,
servePromise: Promise<void>,
) {
signalHandlers.get("SIGINT")?.();
await servePromise;
}
beforeAll(async () => { beforeAll(async () => {
({ serveAcpGateway } = await import("./server.js")); ({ serveAcpGateway } = await import("./server.js"));
}); });
@ -153,14 +169,8 @@ describe("serveAcpGateway startup", () => {
await Promise.resolve(); await Promise.resolve();
expect(mockState.agentSideConnectionCtor).not.toHaveBeenCalled(); expect(mockState.agentSideConnectionCtor).not.toHaveBeenCalled();
const gateway = getMockGateway(); await emitHelloAndWaitForAgentSideConnection();
gateway.emitHello(); await stopServeWithSigint(signalHandlers, servePromise);
await vi.waitFor(() => {
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
});
signalHandlers.get("SIGINT")?.();
await servePromise;
} finally { } finally {
onceSpy.mockRestore(); onceSpy.mockRestore();
} }
@ -207,13 +217,8 @@ describe("serveAcpGateway startup", () => {
password: "resolved-secret-password", // pragma: allowlist secret password: "resolved-secret-password", // pragma: allowlist secret
}); });
const gateway = getMockGateway(); await emitHelloAndWaitForAgentSideConnection();
gateway.emitHello(); await stopServeWithSigint(signalHandlers, servePromise);
await vi.waitFor(() => {
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
});
signalHandlers.get("SIGINT")?.();
await servePromise;
} finally { } finally {
onceSpy.mockRestore(); onceSpy.mockRestore();
} }
@ -236,13 +241,8 @@ describe("serveAcpGateway startup", () => {
}), }),
); );
const gateway = getMockGateway(); await emitHelloAndWaitForAgentSideConnection();
gateway.emitHello(); await stopServeWithSigint(signalHandlers, servePromise);
await vi.waitFor(() => {
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
});
signalHandlers.get("SIGINT")?.();
await servePromise;
} finally { } finally {
onceSpy.mockRestore(); onceSpy.mockRestore();
} }