@@ -83,23 +83,6 @@ function stubAgentCache(instance: Stagehand): void {
8383 } ) ;
8484}
8585
86- function installHandleContext (
87- instance : Stagehand ,
88- targetId : string ,
89- page : Page ,
90- ) {
91- const resolvePageByTargetId = vi
92- . fn ( )
93- . mockImplementation ( ( requestedTargetId : string ) => {
94- if ( requestedTargetId === targetId ) {
95- return page ;
96- }
97- return undefined ;
98- } ) ;
99- Reflect . set ( instance , "ctx" , { resolvePageByTargetId } ) ;
100- return resolvePageByTargetId ;
101- }
102-
10386function createApiClient ( ) {
10487 return {
10588 act : vi . fn ( ) . mockResolvedValue ( defaultActResult ) ,
@@ -143,29 +126,6 @@ describe("Page boundary contracts", () => {
143126 resolvePage . call ( stagehand , { } as AnyPage ) ,
144127 ) . rejects . toBeInstanceOf ( StagehandInvalidArgumentError ) ;
145128 } ) ;
146-
147- it ( "maps PageHandle.targetId back to a V3 Page" , async ( ) => {
148- const stagehand = createStagehand ( ) ;
149- const fakePage = createInternalPage ( "frame-handle" ) ;
150- const resolvePageByTargetId = installHandleContext (
151- stagehand ,
152- "target-handle" ,
153- fakePage ,
154- ) ;
155-
156- const resolvePage = Reflect . get ( stagehand , "resolvePage" ) as (
157- page ?: AnyPage ,
158- ) => Promise < Page > ;
159-
160- const handle = {
161- pageId : "page-handle" ,
162- targetId : "target-handle" ,
163- } as AnyPage ;
164- const resolved = await resolvePage . call ( stagehand , handle ) ;
165-
166- expect ( resolvePageByTargetId ) . toHaveBeenCalledWith ( "target-handle" ) ;
167- expect ( resolved ) . toBe ( fakePage ) ;
168- } ) ;
169129 } ) ;
170130
171131 describe ( "normalizeToV3Page" , ( ) => {
@@ -263,16 +223,17 @@ describe("Page boundary contracts", () => {
263223 stubAgentCache ( stagehand ) ;
264224
265225 const frameId = "frame-act" ;
266- const targetId = "target-act" ;
267226 const fakePage = createInternalPage ( frameId ) ;
268- installHandleContext ( stagehand , targetId , fakePage ) ;
227+ Reflect . set (
228+ stagehand ,
229+ "resolvePage" ,
230+ vi . fn ( ) . mockResolvedValue ( fakePage ) ,
231+ ) ;
269232
270233 const apiClient = createApiClient ( ) ;
271234 Reflect . set ( stagehand , "apiClient" , apiClient ) ;
272235
273- const options = {
274- page : { pageId : "page-act" , targetId } as AnyPage ,
275- } ;
236+ const options = { } ;
276237
277238 await stagehand . act ( "Click button" , options ) ;
278239
@@ -289,17 +250,18 @@ describe("Page boundary contracts", () => {
289250 stubAgentCache ( stagehand ) ;
290251
291252 const frameId = "frame-extract" ;
292- const targetId = "target-extract" ;
293253 const fakePage = createInternalPage ( frameId ) ;
294- installHandleContext ( stagehand , targetId , fakePage ) ;
254+ Reflect . set (
255+ stagehand ,
256+ "resolvePage" ,
257+ vi . fn ( ) . mockResolvedValue ( fakePage ) ,
258+ ) ;
295259
296260 const apiClient = createApiClient ( ) ;
297261 Reflect . set ( stagehand , "apiClient" , apiClient ) ;
298262
299263 const schema = z . object ( { value : z . string ( ) } ) ;
300- const options = {
301- page : { pageId : "page-extract" , targetId } as AnyPage ,
302- } ;
264+ const options = { } ;
303265
304266 await stagehand . extract ( "Summarize" , schema , options ) ;
305267
@@ -317,16 +279,17 @@ describe("Page boundary contracts", () => {
317279 stubAgentCache ( stagehand ) ;
318280
319281 const frameId = "frame-observe" ;
320- const targetId = "target-observe" ;
321282 const fakePage = createInternalPage ( frameId ) ;
322- installHandleContext ( stagehand , targetId , fakePage ) ;
283+ Reflect . set (
284+ stagehand ,
285+ "resolvePage" ,
286+ vi . fn ( ) . mockResolvedValue ( fakePage ) ,
287+ ) ;
323288
324289 const apiClient = createApiClient ( ) ;
325290 Reflect . set ( stagehand , "apiClient" , apiClient ) ;
326291
327- const options = {
328- page : { pageId : "page-observe" , targetId } as AnyPage ,
329- } ;
292+ const options = { } ;
330293
331294 await stagehand . observe ( "Check" , options ) ;
332295
0 commit comments