Skip to content

Commit ab12612

Browse files
Add trap-fallback regressions for cdp override reads
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 23310e2 commit ab12612

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎src/agent/__tests__/hyperagent-constructor.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,46 @@ describe("HyperAgent constructor and task controls", () => {
313313
expect(runtimeCtx?.filterAdTrackingFrames).toBe(false);
314314
});
315315

316+
it("falls back to agent cdpActions setting when task params cdp getter traps", async () => {
317+
const mockedRunAgentTask = jest.mocked(runAgentTask);
318+
mockedRunAgentTask.mockResolvedValue({
319+
taskId: "task-id-cdp-trap",
320+
status: TaskStatus.COMPLETED,
321+
steps: [],
322+
output: "done",
323+
actionCache: {
324+
taskId: "task-id-cdp-trap",
325+
createdAt: new Date().toISOString(),
326+
status: TaskStatus.COMPLETED,
327+
steps: [],
328+
},
329+
});
330+
331+
const agent = new HyperAgent({
332+
llm: createMockLLM(),
333+
cdpActions: false,
334+
});
335+
const trappedParams = new Proxy(
336+
{},
337+
{
338+
get: (_target, prop: string | symbol) => {
339+
if (prop === "cdpActions") {
340+
throw new Error("cdp option trap");
341+
}
342+
return undefined;
343+
},
344+
}
345+
) as TaskParams;
346+
const fakePage = {} as unknown as Page;
347+
const task = await agent.executeTaskAsync("test task", trappedParams, fakePage);
348+
await task.result;
349+
350+
const runtimeCtx = mockedRunAgentTask.mock.calls[0]?.[0] as {
351+
cdpActions?: boolean;
352+
};
353+
expect(runtimeCtx?.cdpActions).toBe(false);
354+
});
355+
316356
it("executeTaskAsync cleans up state when setup throws before run starts", async () => {
317357
const agent = new HyperAgent({
318358
llm: createMockLLM(),

‎src/agent/__tests__/run-from-action-cache.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,66 @@ describe("runFromActionCache hardening", () => {
14241424
);
14251425
});
14261426

1427+
it("falls back to agent cdpActions for replay when params getter traps", async () => {
1428+
const agent = new HyperAgent({
1429+
llm: createMockLLM(),
1430+
cdpActions: false,
1431+
});
1432+
const perform = jest.fn().mockResolvedValue({
1433+
taskId: "perform-task",
1434+
status: TaskStatus.COMPLETED,
1435+
steps: [],
1436+
output: "performed via instruction",
1437+
replayStepMeta: {
1438+
usedCachedAction: false,
1439+
fallbackUsed: true,
1440+
retries: 1,
1441+
},
1442+
});
1443+
const page = {
1444+
perform,
1445+
} as unknown as import("@/types/agent/types").HyperPage;
1446+
const cache: ActionCacheOutput = {
1447+
taskId: "cache-task",
1448+
createdAt: new Date().toISOString(),
1449+
status: TaskStatus.COMPLETED,
1450+
steps: [
1451+
{
1452+
stepIndex: 0,
1453+
instruction: "click fallback target",
1454+
elementId: "0-1",
1455+
method: "click",
1456+
arguments: [],
1457+
frameIndex: 0,
1458+
xpath: null,
1459+
actionType: "actElement",
1460+
success: true,
1461+
message: "cached",
1462+
},
1463+
],
1464+
};
1465+
const trappedParams = new Proxy(
1466+
{},
1467+
{
1468+
get: (_target, prop: string | symbol) => {
1469+
if (prop === "cdpActions") {
1470+
throw new Error("replay cdp trap");
1471+
}
1472+
return undefined;
1473+
},
1474+
}
1475+
) as import("@/types/agent/types").RunFromActionCacheParams;
1476+
1477+
await agent.runFromActionCache(cache, page, trappedParams);
1478+
1479+
expect(perform).toHaveBeenCalledWith(
1480+
"click fallback target",
1481+
expect.objectContaining({
1482+
cdpActions: false,
1483+
})
1484+
);
1485+
});
1486+
14271487
it("truncates oversized cached-step read diagnostics", async () => {
14281488
const agent = new HyperAgent({
14291489
llm: createMockLLM(),

0 commit comments

Comments
 (0)