Skip to content

Commit 8cdd96f

Browse files
committed
perf(test): bypass computer settle waits
1 parent 0990bcc commit 8cdd96f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/agents/tools/computer-tool.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Cover the computer.act wire mapping and node resolution / arming behavior.
55
*/
66
import { createHash } from "node:crypto";
7-
import { beforeEach, describe, expect, it, vi } from "vitest";
7+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
88
import type { AgentMessage } from "../runtime/index.js";
99

1010
const listNodesMock = vi.fn();
@@ -34,6 +34,7 @@ const {
3434
invalidateComputerFrameIfMissing,
3535
COMPUTER_ACT_COMMAND,
3636
COMPUTER_REF_WIDTH,
37+
testing,
3738
} = await import("./computer-tool.js");
3839
const { DEFAULT_IMAGE_MAX_DIMENSION_PX } = await import("../image-sanitization.js");
3940
// With no config the reference width is capped at the default sanitization limit.
@@ -351,6 +352,12 @@ describe("createComputerTool node resolution", () => {
351352
beforeEach(() => {
352353
listNodesMock.mockReset();
353354
callGatewayToolMock.mockReset();
355+
// Mapping and state tests do not need the real desktop's 500ms settle.
356+
testing.setWaitForPostActionSettleForTest(async (signal) => signal?.throwIfAborted());
357+
});
358+
359+
afterEach(() => {
360+
testing.setWaitForPostActionSettleForTest();
354361
});
355362

356363
it("errors when no computer-capable node is connected", async () => {

‎src/agents/tools/computer-tool.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const AFTER_ACTION_SCREENSHOT_DELAY_MS = 500;
4747
const MAX_WAIT_SECONDS = 100;
4848
const MAX_HOLD_SECONDS = 10;
4949

50+
const defaultWaitForPostActionSettle = (signal?: AbortSignal) =>
51+
sleep(AFTER_ACTION_SCREENSHOT_DELAY_MS, signal);
52+
let waitForPostActionSettle = defaultWaitForPostActionSettle;
53+
5054
export const COMPUTER_TOOL_ACTIONS = [
5155
"screenshot",
5256
"left_click",
@@ -916,7 +920,7 @@ export function createComputerTool(options?: {
916920
if (action === "left_mouse_up") {
917921
heldButtonTarget = undefined;
918922
}
919-
await sleep(AFTER_ACTION_SCREENSHOT_DELAY_MS, signal);
923+
await waitForPostActionSettle(signal);
920924
try {
921925
const capture = await captureScreenshot({
922926
gatewayOpts,
@@ -942,3 +946,11 @@ export function createComputerTool(options?: {
942946
}),
943947
};
944948
}
949+
950+
/** Test-only dependency override for the post-action UI settle delay. */
951+
export const testing = {
952+
setWaitForPostActionSettleForTest(override?: typeof waitForPostActionSettle) {
953+
waitForPostActionSettle = override ?? defaultWaitForPostActionSettle;
954+
},
955+
};
956+
export { testing as __testing };

0 commit comments

Comments
 (0)