test: dedupe gateway watch tmux mock reads

This commit is contained in:
Peter Steinberger
2026-05-13 02:48:11 +01:00
parent cc6da043bd
commit dfd63a2145

View File

@@ -26,13 +26,22 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
function spawnCall(mock: unknown, callIndex: number) {
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
const call = calls.at(callIndex);
const call = calls[callIndex];
if (!call) {
throw new Error(`Expected spawn call ${callIndex + 1}`);
}
return call;
}
function spawnShellCommand(mock: unknown, callIndex: number): string {
const call = spawnCall(mock, callIndex);
const args = call[1];
if (!Array.isArray(args) || typeof args[6] !== "string") {
throw new Error(`Expected spawn call ${callIndex + 1} shell command`);
}
return args[6];
}
function expectSpawn(mock: unknown, callIndex: number, command: string, args: Array<unknown>) {
const call = spawnCall(mock, callIndex);
expect(call[0]).toBe(command);
@@ -110,7 +119,7 @@ describe("gateway-watch tmux wrapper", () => {
});
expect(code).toBe(0);
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
const command = spawnShellCommand(spawnSync, 1);
expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'");
expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=0'");
expect(command).not.toContain("--benchmark");
@@ -142,7 +151,7 @@ describe("gateway-watch tmux wrapper", () => {
});
expect(code).toBe(0);
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
const command = spawnShellCommand(spawnSync, 1);
expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=1'");
expect(command).toContain(
"'OPENCLAW_RUN_NODE_OUTPUT_LOG=.artifacts/gateway-watch-profiles/gateway-watch-output.log'",
@@ -174,7 +183,7 @@ describe("gateway-watch tmux wrapper", () => {
});
expect(code).toBe(0);
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
const command = spawnShellCommand(spawnSync, 1);
expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'");
expect(command).not.toContain("--benchmark-no-force");
expect(command).toContain("'gateway'");