44// Stops the worktree's dev server (only the group this script family started), seeds
55// settings.json, starts `vp run dev`, records the scripted steps, and logs the persisted
66// defaultModelSelection before and after. The server is left running for stills; stop it with stop.mjs.
7- import { execFileSync } from "node:child_process" ;
8- import { appendFileSync , mkdirSync , readFileSync , renameSync , writeFileSync } from "node:fs" ;
9- import { join } from "node:path" ;
10- import { setTimeout as sleep } from "node:timers/promises" ;
7+ import * as NodeChildProcess from "node:child_process" ;
8+ import * as NodeFS from "node:fs" ;
9+ import * as NodePath from "node:path" ;
10+ import * as NodeTimersPromises from "node:timers/promises" ;
1111import { caption , gotoSettingsGeneral , modelRow , openApp , webOriginFromLog } from "./lib.mjs" ;
1212import { startServer , stopServer } from "./server.mjs" ;
1313import { openNewThread } from "./new-thread.mjs" ;
@@ -30,42 +30,46 @@ if (!spec || !label || !worktree) {
3030 process . exit ( 2 ) ;
3131}
3232
33- mkdirSync ( outDir , { recursive : true } ) ;
34- const settingsFile = join ( worktree , ".t3/userdata/settings.json" ) ;
35- const pidFile = join ( outDir , `${ label } .pgid` ) ;
36- const logFile = join ( outDir , `${ label } -${ row } -dev.log` ) ;
37- const persistedLog = join ( outDir , "persisted.log" ) ;
33+ NodeFS . mkdirSync ( outDir , { recursive : true } ) ;
34+ const settingsFile = NodePath . join ( worktree , ".t3/userdata/settings.json" ) ;
35+ const pidFile = NodePath . join ( outDir , `${ label } .pgid` ) ;
36+ const logFile = NodePath . join ( outDir , `${ label } -${ row } -dev.log` ) ;
37+ const persistedLog = NodePath . join ( outDir , "persisted.log" ) ;
3838const base = `${ row } -${ label } ` ;
3939
4040function persisted ( ) {
4141 try {
42- return execFileSync ( "jq" , [ "-c" , ".defaultModelSelection" , settingsFile ] , {
42+ return NodeChildProcess . execFileSync ( "jq" , [ "-c" , ".defaultModelSelection" , settingsFile ] , {
4343 encoding : "utf8" ,
4444 } ) . trim ( ) ;
4545 } catch {
4646 return JSON . stringify (
47- JSON . parse ( readFileSync ( settingsFile , "utf8" ) ) . defaultModelSelection ?? null ,
47+ JSON . parse ( NodeFS . readFileSync ( settingsFile , "utf8" ) ) . defaultModelSelection ?? null ,
4848 ) ;
4949 }
5050}
5151function logPersisted ( phase ) {
5252 const line = `${ new Date ( ) . toISOString ( ) } ${ label } ${ row } ${ phase } ${ persisted ( ) } ` ;
53- appendFileSync ( persistedLog , `${ line } \n` ) ;
53+ NodeFS . appendFileSync ( persistedLog , `${ line } \n` ) ;
5454 console . log ( line ) ;
5555}
5656
5757await stopServer ( pidFile ) ;
58- execFileSync ( "node" , [ join ( import . meta. dirname , "seed.mjs" ) , worktree , spec . seed ] , {
59- stdio : "inherit" ,
60- } ) ;
58+ NodeChildProcess . execFileSync (
59+ "node" ,
60+ [ NodePath . join ( import . meta. dirname , "seed.mjs" ) , worktree , spec . seed ] ,
61+ {
62+ stdio : "inherit" ,
63+ } ,
64+ ) ;
6165logPersisted ( `seeded:${ spec . seed } ` ) ;
6266await startServer ( { worktree, pidFile, logFile } ) ;
6367logPersisted ( "server-started" ) ;
6468
65- const videoDir = join ( outDir , `video-${ base } ` ) ;
69+ const videoDir = NodePath . join ( outDir , `video-${ base } ` ) ;
6670const app = await openApp ( {
6771 worktree,
68- authFile : join ( outDir , `auth-${ label } .json` ) ,
72+ authFile : NodePath . join ( outDir , `auth-${ label } .json` ) ,
6973 webOrigin : webOriginFromLog ( logFile ) ,
7074 videoDir,
7175} ) ;
@@ -77,14 +81,14 @@ const say = async (text, hold = 1800) => {
7781 `${ String ( Math . floor ( s / 60 ) ) . padStart ( 2 , "0" ) } :${ String ( s % 60 ) . padStart ( 2 , "0" ) } ${ text } ` ,
7882 ) ;
7983 await caption ( app . page , `[${ label } ] ${ row } : ${ text } ` ) . catch ( ( ) => { } ) ;
80- await sleep ( hold ) ;
84+ await NodeTimersPromises . setTimeout ( hold ) ;
8185} ;
8286const ctx = {
8387 ...app ,
8488 say,
8589 persisted,
8690 logPersisted,
87- shot : ( n ) => app . page . screenshot ( { path : join ( outDir , `${ base } -${ n } .png` ) } ) ,
91+ shot : ( n ) => app . page . screenshot ( { path : NodePath . join ( outDir , `${ base } -${ n } .png` ) } ) ,
8892} ;
8993
9094try {
99103 await app . context . close ( ) ;
100104 await app . browser . close ( ) ;
101105 const webm = await video . path ( ) ;
102- execFileSync ( "ffmpeg" , [
106+ NodeChildProcess . execFileSync ( "ffmpeg" , [
103107 "-y" ,
104108 "-loglevel" ,
105109 "error" ,
@@ -111,14 +115,12 @@ try {
111115 "yuv420p" ,
112116 "-movflags" ,
113117 "+faststart" ,
114- join ( outDir , `${ base } .mp4` ) ,
118+ NodePath . join ( outDir , `${ base } .mp4` ) ,
115119 ] ) ;
116- writeFileSync ( join ( outDir , `${ base } .steps.txt` ) , `${ steps . join ( "\n" ) } \n` ) ;
120+ NodeFS . writeFileSync ( NodePath . join ( outDir , `${ base } .steps.txt` ) , `${ steps . join ( "\n" ) } \n` ) ;
117121 console . log ( steps . join ( "\n" ) ) ;
118122}
119123
120- // ---- scenarios ----
121-
122124function traitsTrigger ( page ) {
123125 // Every row button that is not the model picker, the source badge, or the reset button.
124126 return modelRow ( page ) . locator (
@@ -149,7 +151,7 @@ async function reloadAndShow({ page, say, persisted }) {
149151 { timeout : 30_000 } ,
150152 )
151153 . catch ( ( ) => { } ) ;
152- await sleep ( 2000 ) ;
154+ await NodeTimersPromises . setTimeout ( 2000 ) ;
153155 await say (
154156 `After reload. Row: "${ ( await modelRow ( page ) . innerText ( ) ) . split ( "\n" ) . filter ( Boolean ) . slice ( 2 ) . join ( " · " ) } "` ,
155157 2500 ,
@@ -171,11 +173,11 @@ function settingsEffort(target) {
171173 600 ,
172174 ) ;
173175 await trigger . first ( ) . click ( ) ;
174- await sleep ( 1200 ) ;
176+ await NodeTimersPromises . setTimeout ( 1200 ) ;
175177 await shot ( "menu" ) ;
176178 await say ( `Choose ${ target } ` , 600 ) ;
177179 await page . getByRole ( "menuitemradio" , { name : target , exact : true } ) . click ( ) ;
178- await sleep ( 1500 ) ;
180+ await NodeTimersPromises . setTimeout ( 1500 ) ;
179181 await say ( `Picked ${ target } . settings.json now ${ ctx . persisted ( ) } ` , 2500 ) ;
180182 }
181183 await reloadAndShow ( ctx ) ;
@@ -193,11 +195,11 @@ async function composerEffort(ctx) {
193195 600 ,
194196 ) ;
195197 await effort . click ( ) ;
196- await sleep ( 1200 ) ;
198+ await NodeTimersPromises . setTimeout ( 1200 ) ;
197199 await shot ( "composer-menu" ) ;
198200 await say ( "Choose Low" , 600 ) ;
199201 await page . getByRole ( "menuitemradio" , { name : "Low" , exact : true } ) . click ( ) ;
200- await sleep ( 1500 ) ;
202+ await NodeTimersPromises . setTimeout ( 1500 ) ;
201203 await say (
202204 `Composer effort now "${ ( await effort . innerText ( ) ) . trim ( ) } ". settings.json = ${ ctx . persisted ( ) } ` ,
203205 2500 ,
@@ -208,7 +210,7 @@ async function composerEffort(ctx) {
208210 . locator ( '[data-composer-shortcut="composer.effort"]' )
209211 . first ( )
210212 . waitFor ( { timeout : 90_000 } ) ;
211- await sleep ( 2500 ) ;
213+ await NodeTimersPromises . setTimeout ( 2500 ) ;
212214 await say (
213215 `After reload composer effort "${ ( await page . locator ( '[data-composer-shortcut="composer.effort"]' ) . first ( ) . innerText ( ) ) . trim ( ) } "` ,
214216 2000 ,
@@ -232,39 +234,39 @@ async function unsupportedEffort(ctx) {
232234 600 ,
233235 ) ;
234236 await trigger . click ( ) ;
235- await sleep ( 1200 ) ;
237+ await NodeTimersPromises . setTimeout ( 1200 ) ;
236238 await shot ( "menu" ) ;
237239 await say ( "Close it with Escape (no choice made)" , 600 ) ;
238240 await page . keyboard . press ( "Escape" ) ;
239- await sleep ( 1000 ) ;
241+ await NodeTimersPromises . setTimeout ( 1000 ) ;
240242 await say ( `settings.json = ${ ctx . persisted ( ) } ` , 2500 ) ;
241243 await reloadAndShow ( ctx ) ;
242244 await say ( "Now choose Max" , 600 ) ;
243245 await traitsTrigger ( page ) . first ( ) . click ( ) ;
244- await sleep ( 1000 ) ;
246+ await NodeTimersPromises . setTimeout ( 1000 ) ;
245247 await page . getByRole ( "menuitemradio" , { name : "Max" , exact : true } ) . click ( ) ;
246- await sleep ( 1500 ) ;
248+ await NodeTimersPromises . setTimeout ( 1500 ) ;
247249 await reloadAndShow ( ctx ) ;
248250 await shot ( "after-reload" ) ;
249251}
250252
251253async function pickModel ( page , say , query , optionName ) {
252254 await modelRow ( page ) . locator ( '[data-chat-provider-model-picker="true"]' ) . click ( ) ;
253- await sleep ( 1000 ) ;
255+ await NodeTimersPromises . setTimeout ( 1000 ) ;
254256 const claudeTab = page
255257 . locator ( "[data-model-picker-content]" )
256258 . getByRole ( "toolbar" )
257259 . getByRole ( "button" , { name : / c l a u d e / i } ) ;
258260 if ( await claudeTab . count ( ) ) await claudeTab . first ( ) . click ( ) ;
259261 await page . locator ( "[data-model-picker-content]" ) . getByRole ( "combobox" ) . fill ( query ) ;
260- await sleep ( 1000 ) ;
262+ await NodeTimersPromises . setTimeout ( 1000 ) ;
261263 await say ( `Model picker: search "${ query } "` , 1200 ) ;
262264 await page
263265 . locator ( "[data-model-picker-content]" )
264266 . getByRole ( "option" , { name : optionName } )
265267 . first ( )
266268 . click ( ) ;
267- await sleep ( 1500 ) ;
269+ await NodeTimersPromises . setTimeout ( 1500 ) ;
268270}
269271
270272async function noEffortModel ( ctx ) {
0 commit comments