@@ -2,53 +2,12 @@ import { test, expect } from "@playwright/test";
22import fs from "fs/promises" ;
33import path from "path" ;
44import { V3 } from "../../lib/v3/v3.js" ;
5- import { getV3TestConfig } from "./v3.config.js" ;
5+ import { v3TestConfig } from "./v3.config.js" ;
66import type {
77 AgentReplayActStep ,
88 AgentReplayFillFormStep ,
99 CachedAgentEntry ,
1010} from "../../lib/v3/types/private/cache.js" ;
11- import {
12- createScriptedAisdkTestLlmClient ,
13- doneToolResponse ,
14- findElementRefForText ,
15- toolCallResponse ,
16- } from "./testUtils.js" ;
17-
18- function encodeHtml ( html : string ) : string {
19- return `data:text/html,${ encodeURIComponent ( html ) } ` ;
20- }
21-
22- function createSelfHealLlmClient ( ) {
23- return createScriptedAisdkTestLlmClient ( {
24- jsonResponses : {
25- act : [
26- ( options ) => ( {
27- action : {
28- target : findElementRefForText ( options , "Launch self-heal" ) ,
29- description : "launch self-heal button" ,
30- method : "click" ,
31- button : null ,
32- } ,
33- twoStep : false ,
34- } ) ,
35- ( options ) => ( {
36- action : {
37- target : findElementRefForText ( options , "Launch self-heal" ) ,
38- description : "launch self-heal button" ,
39- method : "click" ,
40- button : null ,
41- } ,
42- twoStep : false ,
43- } ) ,
44- ] ,
45- } ,
46- generateResponses : [
47- toolCallResponse ( "act" , { action : "click the button" } ) ,
48- doneToolResponse ( "Clicked the button successfully." , true ) ,
49- ] ,
50- } ) ;
51- }
5211
5312test . describe ( "Agent cache self-heal (e2e)" , ( ) => {
5413 let v3 : V3 ;
@@ -59,10 +18,7 @@ test.describe("Agent cache self-heal (e2e)", () => {
5918 await fs . mkdir ( testInfo . outputDir , { recursive : true } ) ;
6019 cacheDir = await fs . mkdtemp ( path . join ( testInfo . outputDir , "agent-cache-" ) ) ;
6120 v3 = new V3 ( {
62- ...getV3TestConfig ( {
63- experimental : true ,
64- llmClient : createSelfHealLlmClient ( ) ,
65- } ) ,
21+ ...v3TestConfig ,
6622 cacheDir,
6723 selfHeal : true ,
6824 } ) ;
@@ -74,32 +30,19 @@ test.describe("Agent cache self-heal (e2e)", () => {
7430 } ) ;
7531
7632 test ( "replays heal corrupted selectors" , async ( ) => {
77- test . setTimeout ( 60_000 ) ;
33+ test . setTimeout ( 120_000 ) ;
7834
79- const agent = v3 . agent ( ) ;
35+ const agent = v3 . agent ( {
36+ model : "anthropic/claude-haiku-4-5-20251001" ,
37+ } ) ;
8038 const page = v3 . context . pages ( ) [ 0 ] ;
81- const url = encodeHtml ( `
82- <!doctype html>
83- <html>
84- <body>
85- <button
86- id="launch"
87- onclick="document.getElementById('status').textContent = 'clicked';"
88- >
89- Launch self-heal
90- </button>
91- <div id="status">idle</div>
92- </body>
93- </html>
94- ` ) ;
39+ const url =
40+ "https://browserbase.github.io/stagehand-eval-sites/sites/shadow-dom/" ;
9541 const instruction = "click the button" ;
9642
97- await page . goto ( url , { waitUntil : "load " } ) ;
43+ await page . goto ( url , { waitUntil : "networkidle " } ) ;
9844 const firstResult = await agent . execute ( { instruction, maxSteps : 20 } ) ;
9945 expect ( firstResult . success ) . toBe ( true ) ;
100- await expect
101- . poll ( async ( ) => page . evaluate ( ( ) => document . body . textContent ?? "" ) )
102- . toContain ( "clicked" ) ;
10346
10447 const cachePath = await locateAgentCacheFile ( cacheDir ) ;
10548 const originalEntry = await readCacheEntry ( cachePath ) ;
@@ -119,13 +62,9 @@ test.describe("Agent cache self-heal (e2e)", () => {
11962 ) ;
12063
12164 // Second run should replay from cache, self-heal, and update the file.
122- await page . goto ( url , { waitUntil : "load " } ) ;
65+ await page . goto ( url , { waitUntil : "networkidle " } ) ;
12366 const replayResult = await agent . execute ( { instruction, maxSteps : 20 } ) ;
12467 expect ( replayResult . success ) . toBe ( true ) ;
125- expect ( replayResult . metadata ?. cacheHit ) . toBe ( true ) ;
126- await expect
127- . poll ( async ( ) => page . evaluate ( ( ) => document . body . textContent ?? "" ) )
128- . toContain ( "clicked" ) ;
12968
13069 const healedEntry = await readCacheEntry ( cachePath ) ;
13170 const healedActionStep = findFirstActionStep ( healedEntry ) ;
0 commit comments