Skip to content

Commit ae29929

Browse files
committed
test(cua-computer): drive the real in-flight generation-rotation path
1 parent 27f3207 commit ae29929

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

‎extensions/cua-computer/src/ref-lifecycle.contract.test.ts‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { readFileSync } from "node:fs";
22
import { describe, expect, it } from "vitest";
3+
import { driver, result } from "./commands.test-helpers.js";
4+
import { callWindowTool } from "./driver-result.js";
35
import {
46
adoptGeneration,
57
issueElementRef,
@@ -8,7 +10,6 @@ import {
810
resolveElementRef,
911
resolveObservation,
1012
resolveWindowRef,
11-
verifyGeneration,
1213
type CuaFrameState,
1314
} from "./frame.js";
1415

@@ -38,7 +39,7 @@ const contract = JSON.parse(
3839
),
3940
) as RefLifecycleContract;
4041

41-
function runCase(testCase: RefLifecycleCase): void {
42+
async function runCase(testCase: RefLifecycleCase): Promise<void> {
4243
const state: CuaFrameState = { generation: "generation-1" };
4344
const windowRef = issueWindowRef(state, { pid: 100, windowId: 10 });
4445
const observation = issueObservation(state, windowRef);
@@ -64,9 +65,23 @@ function runCase(testCase: RefLifecycleCase): void {
6465
adoptGeneration(state, "generation-2");
6566
resolveWindowRef(state, windowRef);
6667
return;
67-
case "in_flight_generation_change":
68-
verifyGeneration(state, "generation-2");
68+
case "in_flight_generation_change": {
69+
// The production path is callWindowTool: it snapshots the driver
70+
// generation, awaits the driver call, then detects rotation. Asserting a
71+
// pre-call guard instead would leave that post-await check unprotected.
72+
const session = driver();
73+
session.callTool.mockImplementationOnce(async () => {
74+
session.setGeneration("execution-2");
75+
return result({});
76+
});
77+
await callWindowTool(
78+
session.session,
79+
{ generation: session.session.generation },
80+
"get_window_state",
81+
{},
82+
);
6983
return;
84+
}
7085
case "superseded_observation":
7186
issueObservation(state, windowRef);
7287
resolveObservation(state, observation.id, windowRef);
@@ -82,11 +97,13 @@ function runCase(testCase: RefLifecycleCase): void {
8297

8398
describe("Computer Use ref lifecycle contract", () => {
8499
for (const testCase of contract.cases) {
85-
it(testCase.id, () => {
100+
it(testCase.id, async () => {
86101
if (testCase.expected === "valid") {
87-
expect(() => runCase(testCase)).not.toThrow();
102+
await expect(runCase(testCase)).resolves.toBeUndefined();
88103
} else {
89-
expect(() => runCase(testCase)).toThrow(new RegExp(`^${contract.staleErrorCode}:`, "u"));
104+
await expect(runCase(testCase)).rejects.toThrow(
105+
new RegExp(`^${contract.staleErrorCode}:`, "u"),
106+
);
90107
}
91108
});
92109
}

0 commit comments

Comments
 (0)