@@ -128,50 +128,64 @@ it.effect("adds, renames, and removes projects through the V2 project CLI domain
128128 } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
129129) ;
130130
131- it . effect ( "waits for a busy live server to apply a project change" , ( ) =>
132- Effect . gen ( function * ( ) {
133- const baseDir = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-live-project-cli-" ) ) ;
134- const workspaceRoot = NodeFS . mkdtempSync (
135- NodePath . join ( NodeOS . tmpdir ( ) , "t3-live-project-workspace-" ) ,
136- ) ;
137- yield * persistServerRuntimeState ( {
138- path : NodePath . join ( baseDir , "userdata" , "server-runtime.json" ) ,
139- state : yield * makePersistedServerRuntimeState ( {
140- config : { host : "127.0.0.1" , devUrl : undefined } ,
141- port : 3_773 ,
142- } ) ,
143- } ) ;
144- const now = "2026-01-01T00:00:00.000Z" ;
145- const mutateReceived = Promise . withResolvers < void > ( ) ;
146- const mutateResponse = Promise . withResolvers < Response > ( ) ;
147- const fetch : typeof globalThis . fetch = async ( _input , init ) => {
148- if ( init ?. method !== "POST" ) return Response . json ( { projects : [ ] , updatedAt : now } ) ;
149- mutateReceived . resolve ( ) ;
150- return mutateResponse . promise ;
151- } ;
131+ it . effect . each ( [ "snapshot" , "mutation" ] as const ) (
132+ "waits for a busy live server's %s response" ,
133+ ( slowRequest ) =>
134+ Effect . gen ( function * ( ) {
135+ const fs = yield * FileSystem . FileSystem ;
136+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-live-project-cli-" } ) ;
137+ const baseDir = NodePath . join ( root , "state" ) ;
138+ const workspaceRoot = NodePath . join ( root , "workspace" ) ;
139+ yield * fs . makeDirectory ( workspaceRoot ) ;
140+ yield * persistServerRuntimeState ( {
141+ path : NodePath . join ( baseDir , "userdata" , "server-runtime.json" ) ,
142+ state : yield * makePersistedServerRuntimeState ( {
143+ config : { host : "127.0.0.1" , devUrl : undefined } ,
144+ port : 3_773 ,
145+ } ) ,
146+ } ) ;
147+ const now = "2026-01-01T00:00:00.000Z" ;
148+ const requestReceived = Promise . withResolvers < void > ( ) ;
149+ const releaseResponse = Promise . withResolvers < void > ( ) ;
150+ let snapshotRequests = 0 ;
151+ let mutations = 0 ;
152+ const fetch : typeof globalThis . fetch = async ( _input , init ) => {
153+ const isMutation = init ?. method === "POST" ;
154+ if ( isMutation ) mutations ++ ;
155+ else snapshotRequests ++ ;
156+ if ( slowRequest === "mutation" ? isMutation : ! isMutation && snapshotRequests === 2 ) {
157+ requestReceived . resolve ( ) ;
158+ await releaseResponse . promise ;
159+ }
160+ return Response . json (
161+ isMutation
162+ ? {
163+ id : "live-project" ,
164+ title : NodePath . basename ( workspaceRoot ) ,
165+ workspaceRoot,
166+ defaultModelSelection : null ,
167+ scripts : [ ] ,
168+ createdAt : now ,
169+ updatedAt : now ,
170+ deletedAt : null ,
171+ }
172+ : { projects : [ ] , updatedAt : now } ,
173+ ) ;
174+ } ;
152175
153- const add = yield * runCli ( [ "project" , "add" , workspaceRoot , "--base-dir" , baseDir ] ) . pipe (
154- Effect . provideService ( FetchHttpClient . Fetch , fetch ) ,
155- Effect . forkChild ,
156- ) ;
157- yield * Effect . promise ( ( ) => mutateReceived . promise ) ;
158- yield * TestClock . adjust ( "1 second" ) ;
159- mutateResponse . resolve (
160- Response . json ( {
161- id : "live-project" ,
162- title : NodePath . basename ( workspaceRoot ) ,
163- workspaceRoot,
164- defaultModelSelection : null ,
165- scripts : [ ] ,
166- createdAt : now ,
167- updatedAt : now ,
168- deletedAt : null ,
169- } ) ,
170- ) ;
171- yield * Fiber . join ( add ) ;
176+ const add = yield * runCli ( [ "project" , "add" , workspaceRoot , "--base-dir" , baseDir ] ) . pipe (
177+ Effect . provideService ( FetchHttpClient . Fetch , fetch ) ,
178+ Effect . forkChild ,
179+ ) ;
180+ yield * Effect . promise ( ( ) => requestReceived . promise ) ;
181+ yield * TestClock . adjust ( "2 seconds" ) ;
182+ releaseResponse . resolve ( ) ;
183+ yield * Fiber . join ( add ) ;
172184
173- assert . deepEqual ( ( yield * readProjects ( baseDir ) ) . projects , [ ] ) ;
174- } ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
185+ assert . equal ( snapshotRequests , 2 ) ;
186+ assert . equal ( mutations , 1 ) ;
187+ assert . deepEqual ( ( yield * readProjects ( baseDir ) ) . projects , [ ] ) ;
188+ } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
175189) ;
176190
177191const makeProjectLookupFixture = Effect . fn ( "ProjectCliTest.makeProjectLookupFixture" ) ( function * ( ) {
0 commit comments