Skip to content

Commit f044da8

Browse files
committed
Fix plan expect handling on terminal navigation
1 parent 9c821b9 commit f044da8

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/agent/src/translator/browser-act.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export async function runBrowserAct(action: CuaActionBrowserAct, runtime: Browse
101101
}
102102

103103
let finalExpectation: BrowserActExpectationEvidence | undefined;
104-
const terminalNavigation = stopReason === "navigation" && stoppedAt === finalStepIndex && steps.at(-1)?.outcome === "worked";
104+
const terminalNavigation = stopReason === "navigation" && stoppedAt === finalStepIndex;
105105
if (action.expect && (!stopReason || terminalNavigation)) {
106106
try {
107107
const result = await runtime.wait(action.expect!, baseline, baseline.targetId, action.tab_id, action.timeout_ms, action.poll_ms);
@@ -163,7 +163,8 @@ export async function runBrowserAct(action: CuaActionBrowserAct, runtime: Browse
163163
const verified = action.expect
164164
? finalExpectation?.status === "newly_verified"
165165
: steps.length === action.steps.length && steps.every((step) => step.outcome === "worked");
166-
const verifiedNavigation = stopReason === "navigation" && steps.length === action.steps.length && steps.at(-1)?.outcome === "worked";
166+
const verifiedNavigation = stopReason === "navigation" && steps.length === action.steps.length
167+
&& (steps.at(-1)?.outcome === "worked" || finalExpectation?.status === "newly_verified");
167168
return {
168169
outcome: failed ? "didnt" : !timedOut && verified && (!stopReason || verifiedNavigation) ? "worked" : "unknown",
169170
steps,

packages/agent/test/translator-browser.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ describe("browser_act orchestration", () => {
185185
expect(result).toMatchObject({ outcome: "worked", stopped_at: 0, stop_reason: "navigation", final_expectation: { status: "newly_verified" } });
186186
});
187187

188+
it("evaluates plan expectations after terminal navigation without step expectations", async () => {
189+
const before = observation("before");
190+
const after = observation("after", 1);
191+
const result = await runBrowserAct({
192+
type: "browser_act",
193+
steps: [{ type: "click", ref: "e1" }],
194+
expect: { type: "url", contains: "after" },
195+
}, runtime([before, before, after, after], [waitResult("newly_verified")]));
196+
expect(result).toMatchObject({ outcome: "worked", stopped_at: 0, stop_reason: "navigation", final_expectation: { status: "newly_verified" } });
197+
});
198+
188199
it("recollects a successor after a raced target boundary", async () => {
189200
const result = await runBrowserAct({ type: "browser_act", steps: [{ type: "click", ref: "e1", expect: { type: "text", text: "Done" } }] }, runtime([
190201
observation("before"), observation("before"), observation("after"), observation("stale"), observation("stable"),

0 commit comments

Comments
 (0)