@@ -20,9 +20,42 @@ test.describe('AI Page Designer', () => {
2020 await auth . navigateToAdminPage ( page , 'admin.php?page=web#/ai-designer' ) ;
2121 await page . waitForSelector ( '#wppw-app-rendered' , { timeout : 15000 } ) ;
2222
23- if ( await mount . count ( ) ) {
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.
27+ try {
28+ await mount . waitFor ( { state : 'attached' , timeout : 15000 } ) ;
2429 break ;
30+ } catch ( e ) {
31+ // Genuinely absent after waiting -- fall through and record why.
2532 }
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 } ` ;
53+ }
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 } ` ) ;
2659 }
2760
2861 await expect ( mount ) . toBeVisible ( { timeout : 15000 } ) ;
0 commit comments