From ec2944dc821bc3e2918bf002eec9cf15d493878a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 22:52:33 +0100 Subject: [PATCH] test: dedupe qa lab agent process mock reads --- .../src/suite-runtime-agent-process.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/extensions/qa-lab/src/suite-runtime-agent-process.test.ts b/extensions/qa-lab/src/suite-runtime-agent-process.test.ts index c322029190b..fa3c30fa6b3 100644 --- a/extensions/qa-lab/src/suite-runtime-agent-process.test.ts +++ b/extensions/qa-lab/src/suite-runtime-agent-process.test.ts @@ -63,6 +63,16 @@ async function waitForSpawnCount(count: number) { await Promise.resolve(); } +function firstSpawnCall(): unknown[] | undefined { + return spawnMock.mock.calls[0]; +} + +function firstGatewayCall( + gatewayCall: ReturnType, +): [string, unknown, unknown] | undefined { + return gatewayCall.mock.calls[0] as [string, unknown, unknown] | undefined; +} + describe("qa suite runtime agent process helpers", () => { beforeEach(() => { spawnMock.mockReset(); @@ -94,7 +104,7 @@ describe("qa suite runtime agent process helpers", () => { child.emit("exit", 0); await expect(pending).resolves.toBe("ok"); - const spawnCall = spawnMock.mock.calls.at(0); + const spawnCall = firstSpawnCall(); expect(spawnCall?.[0]).toBe("/usr/bin/node"); expect(spawnCall?.[1]).toEqual([path.join("/repo", "dist", "index.js"), "qa", "suite"]); expect((spawnCall?.[2] as { cwd?: string; env?: unknown } | undefined)?.cwd).toBe( @@ -132,7 +142,7 @@ describe("qa suite runtime agent process helpers", () => { child.emit("exit", 0); await expect(pending).resolves.toBe("ok"); - const spawnCall = spawnMock.mock.calls.at(0); + const spawnCall = firstSpawnCall(); expect(spawnCall?.[0]).toBe("/usr/bin/node"); expect(spawnCall?.[1]).toEqual([ path.join("/repo", "dist", "index.js"), @@ -253,9 +263,7 @@ describe("qa suite runtime agent process helpers", () => { message: "hello", }), ).resolves.toEqual({ runId: "run-1" }); - const gatewayArgs = gatewayCall.mock.calls.at(0) as unknown as - | [string, unknown, unknown] - | undefined; + const gatewayArgs = firstGatewayCall(gatewayCall); expect(gatewayArgs?.[0]).toBe("agent"); const agentPayload = gatewayArgs?.[1] as | {