Skip to content

Commit dfd63a2

Browse files
committed
test: dedupe gateway watch tmux mock reads
1 parent cc6da04 commit dfd63a2

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/infra/gateway-watch-tmux.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
2626

2727
function spawnCall(mock: unknown, callIndex: number) {
2828
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
29-
const call = calls.at(callIndex);
29+
const call = calls[callIndex];
3030
if (!call) {
3131
throw new Error(`Expected spawn call ${callIndex + 1}`);
3232
}
3333
return call;
3434
}
3535

36+
function spawnShellCommand(mock: unknown, callIndex: number): string {
37+
const call = spawnCall(mock, callIndex);
38+
const args = call[1];
39+
if (!Array.isArray(args) || typeof args[6] !== "string") {
40+
throw new Error(`Expected spawn call ${callIndex + 1} shell command`);
41+
}
42+
return args[6];
43+
}
44+
3645
function expectSpawn(mock: unknown, callIndex: number, command: string, args: Array<unknown>) {
3746
const call = spawnCall(mock, callIndex);
3847
expect(call[0]).toBe(command);
@@ -110,7 +119,7 @@ describe("gateway-watch tmux wrapper", () => {
110119
});
111120

112121
expect(code).toBe(0);
113-
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
122+
const command = spawnShellCommand(spawnSync, 1);
114123
expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'");
115124
expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=0'");
116125
expect(command).not.toContain("--benchmark");
@@ -142,7 +151,7 @@ describe("gateway-watch tmux wrapper", () => {
142151
});
143152

144153
expect(code).toBe(0);
145-
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
154+
const command = spawnShellCommand(spawnSync, 1);
146155
expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=1'");
147156
expect(command).toContain(
148157
"'OPENCLAW_RUN_NODE_OUTPUT_LOG=.artifacts/gateway-watch-profiles/gateway-watch-output.log'",
@@ -174,7 +183,7 @@ describe("gateway-watch tmux wrapper", () => {
174183
});
175184

176185
expect(code).toBe(0);
177-
const command = spawnSync.mock.calls.at(1)?.[1]?.[6] as string;
186+
const command = spawnShellCommand(spawnSync, 1);
178187
expect(command).toContain("'OPENCLAW_RUN_NODE_CPU_PROF_DIR=.artifacts/gateway-watch-profiles'");
179188
expect(command).not.toContain("--benchmark-no-force");
180189
expect(command).toContain("'gateway'");

0 commit comments

Comments
 (0)