@@ -3,26 +3,87 @@ const path = require("path");
33const fs = require ( "fs" ) ;
44const ROOT = process . cwd ( ) ;
55const { chromium } = require ( path . join ( ROOT , "apps/desktop/node_modules/playwright-core" ) ) ;
6- const CHROME = "/Users/nathanaelaninweze/Library/Caches/ms-playwright/chromium-1228/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing" ;
6+ // Resolve the browser through playwright-core's own registry. A hardcoded
7+ // absolute path pins the rig to one user's home and one chromium build, which is
8+ // why it cannot run on the build box.
9+ function resolveChrome ( ) {
10+ if ( process . env . T3_E2E_CHROME ) return process . env . T3_E2E_CHROME ;
11+ const registry = ( ( ) => {
12+ try {
13+ return chromium . executablePath ( ) ;
14+ } catch {
15+ return null ;
16+ }
17+ } ) ( ) ;
18+ if ( registry && fs . existsSync ( registry ) ) return registry ;
19+ // playwright-core's pinned revision is not always the one actually downloaded.
20+ // Fall back to any installed chromium build in the local cache.
21+ const cache =
22+ process . env . PLAYWRIGHT_BROWSERS_PATH ||
23+ path . join (
24+ require ( "os" ) . homedir ( ) ,
25+ process . platform === "darwin" ? "Library/Caches/ms-playwright" : ".cache/ms-playwright" ,
26+ ) ;
27+ if ( ! fs . existsSync ( cache ) ) throw new Error ( "no playwright browser cache at " + cache ) ;
28+ const tails = [
29+ "chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing" ,
30+ "chrome-mac/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing" ,
31+ "chrome-linux/chrome" ,
32+ ] ;
33+ for ( const dir of fs
34+ . readdirSync ( cache )
35+ . filter ( ( d ) => d . startsWith ( "chromium-" ) )
36+ . sort ( )
37+ . reverse ( ) ) {
38+ for ( const tail of tails ) {
39+ const p = path . join ( cache , dir , tail ) ;
40+ if ( fs . existsSync ( p ) ) return p ;
41+ }
42+ }
43+ throw new Error ( "no chromium build found under " + cache ) ;
44+ }
45+ const CHROME = resolveChrome ( ) ;
746
847const log = [ ] ;
9- const say = ( s ) => { log . push ( String ( s ) ) ; console . log ( String ( s ) ) ; } ;
48+ const say = ( s ) => {
49+ log . push ( String ( s ) ) ;
50+ console . log ( String ( s ) ) ;
51+ } ;
1052
1153function startServer ( ) {
1254 return new Promise ( ( resolve , reject ) => {
13- const p = spawn ( "node" , [ "scripts/dev-runner.ts" , "dev" ] , { cwd : ROOT , env : process . env } ) ;
55+ // The workspace bin dir must be on PATH or dev-runner dies with `spawn vp ENOENT`.
56+ const binDir = path . join ( ROOT , "node_modules" , ".bin" ) ;
57+ const env = { ...process . env , PATH : binDir + path . delimiter + process . env . PATH } ;
58+ if ( ! env . T3CODE_BACKEND ) env . T3CODE_BACKEND = "rust" ;
59+ const p = spawn ( "node" , [ "scripts/dev-runner.ts" , "dev" ] , { cwd : ROOT , env } ) ;
1460 let out = "" ;
15- let url = null , pair = null ;
16- const maybe = ( ) => { if ( url && pair ) { clearTimeout ( t ) ; resolve ( { proc : p , url, pair, out } ) ; } } ;
17- const t = setTimeout ( ( ) => reject ( new Error ( "no url/pair in 240s:\n" + out . slice ( - 1500 ) ) ) , 240000 ) ;
61+ let url = null ,
62+ pair = null ;
63+ const maybe = ( ) => {
64+ if ( url && pair ) {
65+ clearTimeout ( t ) ;
66+ resolve ( { proc : p , url, pair, out } ) ;
67+ }
68+ } ;
69+ const t = setTimeout (
70+ ( ) => reject ( new Error ( "no url/pair in 240s:\n" + out . slice ( - 1500 ) ) ) ,
71+ 240000 ,
72+ ) ;
1873 const scan = ( d ) => {
1974 out += d ;
20- const u = out . match ( / L o c a l : \s + ( h t t p : \/ \/ l o c a l h o s t : \d + ) / ) ; if ( u ) url = u [ 1 ] ;
21- const pr = out . match ( / p a i r i n g U r l : \s * ( h t t p : \/ \/ l o c a l h o s t : \d + \/ p a i r # t o k e n = \S + ) / ) ; if ( pr ) pair = pr [ 1 ] ;
75+ const u = out . match ( / L o c a l : \s + ( h t t p : \/ \/ l o c a l h o s t : \d + ) / ) ;
76+ if ( u ) url = u [ 1 ] ;
77+ const pr = out . match ( / p a i r i n g U r l : \s * ( h t t p : \/ \/ l o c a l h o s t : \d + \/ p a i r # t o k e n = \S + ) / ) ;
78+ if ( pr ) pair = pr [ 1 ] ;
2279 maybe ( ) ;
2380 } ;
24- p . stdout . on ( "data" , scan ) ; p . stderr . on ( "data" , scan ) ;
25- p . on ( "exit" , c => { clearTimeout ( t ) ; reject ( new Error ( "server exited " + c + "\n" + out . slice ( - 1500 ) ) ) ; } ) ;
81+ p . stdout . on ( "data" , scan ) ;
82+ p . stderr . on ( "data" , scan ) ;
83+ p . on ( "exit" , ( c ) => {
84+ clearTimeout ( t ) ;
85+ reject ( new Error ( "server exited " + c + "\n" + out . slice ( - 1500 ) ) ) ;
86+ } ) ;
2687 } ) ;
2788}
2889
@@ -36,29 +97,43 @@ function startServer() {
3697 browser = await chromium . launch ( { executablePath : CHROME , args : [ "--no-sandbox" ] } ) ;
3798 const ctx = await browser . newContext ( { viewport : { width : 1440 , height : 900 } } ) ;
3899 const page = await ctx . newPage ( ) ;
39- const errs = [ ] , ws = [ ] ;
40- page . on ( "console" , m => { if ( m . type ( ) === "error" ) errs . push ( m . text ( ) . slice ( 0 , 160 ) ) ; } ) ;
41- page . on ( "websocket" , s => s . on ( "framereceived" , f => { if ( ws . length < 60 ) ws . push ( String ( f . payload ) . slice ( 0 , 200 ) ) ; } ) ) ;
100+ const errs = [ ] ,
101+ ws = [ ] ;
102+ page . on ( "console" , ( m ) => {
103+ if ( m . type ( ) === "error" ) errs . push ( m . text ( ) . slice ( 0 , 160 ) ) ;
104+ } ) ;
105+ page . on ( "websocket" , ( s ) =>
106+ s . on ( "framereceived" , ( f ) => {
107+ if ( ws . length < 60 ) ws . push ( String ( f . payload ) . slice ( 0 , 200 ) ) ;
108+ } ) ,
109+ ) ;
42110
43111 // PAIR, then land in the app.
44112 await page . goto ( server . pair , { waitUntil : "domcontentloaded" , timeout : 60000 } ) ;
45113 await page . waitForTimeout ( 12000 ) ;
46114 say ( "AFTER PAIR url: " + page . url ( ) ) ;
47115 say ( "AFTER PAIR title: " + ( await page . title ( ) ) ) ;
48116 await page . screenshot ( { path : "/tmp/t3e2e/01-after-pair.png" } ) ;
49- const txt = ( await page . evaluate ( ( ) => document . body . innerText || "" ) ) . replace ( / \n { 2 , } / g, "\n" ) . slice ( 0 , 900 ) ;
117+ const txt = ( await page . evaluate ( ( ) => document . body . innerText || "" ) )
118+ . replace ( / \n { 2 , } / g, "\n" )
119+ . slice ( 0 , 900 ) ;
50120 say ( "BODY:\n" + txt ) ;
51121
52122 // THE COMPOSER — the thing reins could not drive.
53- const cands = [ '[contenteditable="true"]' , ' textarea' , '[role="textbox"]' ] ;
123+ const cands = [ '[contenteditable="true"]' , " textarea" , '[role="textbox"]' ] ;
54124 let found = null ;
55- for ( const c of cands ) { const n = await page . locator ( c ) . count ( ) ; say ( "locator " + c + " -> " + n ) ; if ( n && ! found ) found = c ; }
125+ for ( const c of cands ) {
126+ const n = await page . locator ( c ) . count ( ) ;
127+ say ( "locator " + c + " -> " + n ) ;
128+ if ( n && ! found ) found = c ;
129+ }
56130 if ( found ) {
57131 const box = page . locator ( found ) . first ( ) ;
58132 await box . click ( ) ;
59133 await page . keyboard . type ( "say the word BANANA and nothing else" , { delay : 20 } ) ;
60134 await page . waitForTimeout ( 1200 ) ;
61- const got = ( await box . innerText ( ) . catch ( ( ) => "" ) ) || ( await box . inputValue ( ) . catch ( ( ) => "" ) ) ;
135+ const got =
136+ ( await box . innerText ( ) . catch ( ( ) => "" ) ) || ( await box . inputValue ( ) . catch ( ( ) => "" ) ) ;
62137 say ( "COMPOSER AFTER keyboard.type: " + JSON . stringify ( String ( got ) . slice ( 0 , 120 ) ) ) ;
63138 await page . screenshot ( { path : "/tmp/t3e2e/02-typed.png" } ) ;
64139
@@ -67,25 +142,44 @@ function startServer() {
67142 say ( "PRESSED ENTER at " + new Date ( ) . toISOString ( ) ) ;
68143 for ( let i = 0 ; i < 12 ; i ++ ) {
69144 await page . waitForTimeout ( 5000 ) ;
70- const t = ( await page . evaluate ( ( ) => document . body . innerText || "" ) ) . replace ( / \n { 2 , } / g, "\n" ) ;
71- if ( / B A N A N A / i. test ( t ) && ! / s a y t h e w o r d B A N A N A / i. test ( t . replace ( / s a y t h e w o r d B A N A N A a n d n o t h i n g e l s e / i, "" ) ) ) { say ( "REPLY SEEN at tick " + i ) ; break ; }
72- if ( i % 3 === 0 ) say ( "tick " + i + " url=" + page . url ( ) + " tail=" + t . slice ( - 160 ) . replace ( / \n / g, " " ) ) ;
145+ const t = ( await page . evaluate ( ( ) => document . body . innerText || "" ) ) . replace (
146+ / \n { 2 , } / g,
147+ "\n" ,
148+ ) ;
149+ if (
150+ / B A N A N A / i. test ( t ) &&
151+ ! / s a y t h e w o r d B A N A N A / i. test ( t . replace ( / s a y t h e w o r d B A N A N A a n d n o t h i n g e l s e / i, "" ) )
152+ ) {
153+ say ( "REPLY SEEN at tick " + i ) ;
154+ break ;
155+ }
156+ if ( i % 3 === 0 )
157+ say ( "tick " + i + " url=" + page . url ( ) + " tail=" + t . slice ( - 160 ) . replace ( / \n / g, " " ) ) ;
73158 }
74159 await page . screenshot ( { path : "/tmp/t3e2e/03-after-send.png" , fullPage : true } ) ;
75- const after = ( await page . evaluate ( ( ) => document . body . innerText || "" ) ) . replace ( / \n { 2 , } / g, "\n" ) ;
160+ const after = ( await page . evaluate ( ( ) => document . body . innerText || "" ) ) . replace (
161+ / \n { 2 , } / g,
162+ "\n" ,
163+ ) ;
76164 say ( "URL AFTER SEND: " + page . url ( ) ) ;
77165 say ( "BODY AFTER SEND (1200):\n" + after . slice ( 0 , 1200 ) ) ;
78166 } else {
79167 say ( "NO COMPOSER FOUND" ) ;
80168 }
81169 say ( "CONSOLE ERRORS (" + errs . length + "): " + errs . slice ( 0 , 4 ) . join ( " | " ) ) ;
82170 say ( "WS FRAMES RECEIVED (" + ws . length + "):" ) ;
83- ws . slice ( 0 , 10 ) . forEach ( f => say ( " " + f ) ) ;
171+ ws . slice ( 0 , 10 ) . forEach ( ( f ) => say ( " " + f ) ) ;
84172 } catch ( e ) {
85173 say ( "FAILED: " + ( e && e . message ? e . message : String ( e ) ) ) ;
86174 } finally {
87- try { if ( browser ) await browser . close ( ) ; } catch ( e ) { }
88- if ( server && server . proc ) { try { server . proc . kill ( "SIGKILL" ) ; } catch ( e ) { } }
175+ try {
176+ if ( browser ) await browser . close ( ) ;
177+ } catch ( e ) { }
178+ if ( server && server . proc ) {
179+ try {
180+ server . proc . kill ( "SIGKILL" ) ;
181+ } catch ( e ) { }
182+ }
89183 fs . writeFileSync ( "/tmp/t3e2e/run.log" , log . join ( "\n" ) ) ;
90184 process . exit ( 0 ) ;
91185 }
0 commit comments