@@ -17,45 +17,25 @@ test.describe('AI Page Designer', () => {
1717 // again rather than let whichever spec happens to run first absorb the failure.
1818 for ( let attempt = 0 ; attempt < 3 ; attempt ++ ) {
1919 await newfold . setCapability ( capabilities ) ;
20- await auth . navigateToAdminPage ( page , 'admin.php?page=web#/ai-designer' ) ;
20+
21+ if ( attempt === 0 ) {
22+ await auth . navigateToAdminPage ( page , 'admin.php?page=web#/ai-designer' ) ;
23+ } else {
24+ // Must be reload(), as it re-requests the document,
25+ // so a capability written since the initial load is actually picked up.
26+ await page . reload ( { waitUntil : 'domcontentloaded' } ) ;
27+ }
28+
2129 await page . waitForSelector ( '#wppw-app-rendered' , { timeout : 15000 } ) ;
2230
23- // Wait properly rather than checking instantaneously: the AI Designer
24- // page is a React.lazy() import, so the mount appears a beat after
25- // #wppw-app-rendered. A bare count() here retries on that race and
26- // makes the diagnostic below fire before the page had a fair chance.
31+ // Wait rather than checking instantaneously: the AI Designer page is
32+ // a React.lazy() import, so the mount appears a beat after
2733 try {
2834 await mount . waitFor ( { state : 'attached' , timeout : 15000 } ) ;
2935 break ;
3036 } catch ( e ) {
31- // Genuinely absent after waiting -- fall through and record why.
32- }
33-
34- // TEMPORARY DIAGNOSTIC -- remove once the first-run capability failure
35- // is understood. Three readings taken at the moment of failure:
36- // db - what the options table actually holds
37- // page - what this rendered document received
38- // refetch- a fresh server request on this same context/session,
39- // which distinguishes a stale browser cache from the server
40- // genuinely returning no capabilities for this session.
41- const dbCaps = await newfold . logCapabilities ( ) ;
42- const pageCaps = await page . evaluate (
43- ( ) => window . NewfoldRuntime && window . NewfoldRuntime . capabilities
44- ) ;
45- let refetchCaps = 'n/a' ;
46- try {
47- const res = await page . request . get ( page . url ( ) . split ( '#' ) [ 0 ] ) ;
48- const html = await res . text ( ) ;
49- const m = html . match ( / c a p a b i l i t i e s " : ( \[ \] | \{ [ ^ } ] * \} ) / ) ;
50- refetchCaps = m ? m [ 1 ] : 'not-found-in-html' ;
51- } catch ( e ) {
52- refetchCaps = `error: ${ e . message } ` ;
37+ // Genuinely absent after waiting -- fall through and retry.
5338 }
54-
55- console . log ( `[aipd-diag] attempt=${ attempt } url=${ page . url ( ) } ` ) ;
56- console . log ( `[aipd-diag] db = ${ JSON . stringify ( dbCaps ) } ` ) ;
57- console . log ( `[aipd-diag] page = ${ JSON . stringify ( pageCaps ) } ` ) ;
58- console . log ( `[aipd-diag] refetch = ${ refetchCaps } ` ) ;
5939 }
6040
6141 await expect ( mount ) . toBeVisible ( { timeout : 15000 } ) ;
0 commit comments