@@ -123,6 +123,7 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
123123 const spec = JSON . parse (
124124 readFileSync ( path . join ( directory , "runtime/agent-runtime.json" ) , "utf8" ) ,
125125 ) ;
126+ assert . notEqual ( spec . gooseDevProfile , spec . goose . profile ) ;
126127 const run = ( ...args ) => {
127128 const result = spawnSync (
128129 process . execPath ,
@@ -138,58 +139,29 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
138139 . trim ( )
139140 . split ( "\n" )
140141 . map ( ( line ) => JSON . parse ( line ) ) ;
141- const recorded = ( dev = false ) =>
142+ const recorded = ( ) =>
142143 JSON . parse (
143144 readFileSync (
144- path . join (
145- directory ,
146- `src-tauri/resources/agent-runtime${ dev ? "-dev" : "" } /manifest.json` ,
147- ) ,
145+ path . join ( directory , "src-tauri/resources/agent-runtime/manifest.json" ) ,
148146 "utf8" ,
149147 ) ,
150148 ) . goose ;
151- const packagedFiles = { } ;
152149 const sources = path . join ( directory , "target/agent-runtime-src" ) ;
150+ // Packaging after desktop dev must replace the dev bundle, never accept it.
153151 for ( const [ args , profile ] of [
154152 [ [ ] , spec . goose . profile ] ,
155153 [ [ "--dev" ] , spec . gooseDevProfile ] ,
154+ [ [ ] , spec . goose . profile ] ,
156155 ] ) {
157156 assert . match ( run ( ...args ) , / V e r i f i e d i n p u t s s t a g e d / ) ;
158- if ( args . includes ( "--dev" ) )
159- assert . deepEqual (
160- recorded ( ) ,
161- spec . goose ,
162- "later packaged consumption must keep the selected lean profile" ,
163- ) ;
164- assert . deepEqual ( recorded ( args . includes ( "--dev" ) ) , {
165- ...spec . goose ,
166- profile,
167- } ) ;
157+ assert . deepEqual ( recorded ( ) , { ...spec . goose , profile } ) ;
168158 const gooseBuild = calls ( ) . at ( - 1 ) ;
169159 assert . equal (
170160 gooseBuild . args [ gooseBuild . args . indexOf ( "--profile" ) + 1 ] ,
171161 profile ,
172162 ) ;
173163 assert . match ( run ( ...args ) , / A g e n t r u n t i m e r e a d y / ) ;
174- if ( ! args . includes ( "--dev" ) ) {
175- const packaged = path . join (
176- directory ,
177- "src-tauri/resources/agent-runtime" ,
178- ) ;
179- for ( const name of readdirSync ( packaged ) )
180- packagedFiles [ name ] = readFileSync ( path . join ( packaged , name ) ) ;
181- }
182164 }
183- // A release build consumes resources after preparation has released its lock.
184- // Intervening dev preparation must preserve every selected packaged byte.
185- assert . deepEqual ( recorded ( ) , spec . goose ) ;
186- const packaged = path . join ( directory , "src-tauri/resources/agent-runtime" ) ;
187- for ( const name of readdirSync ( packaged ) )
188- assert . deepEqual (
189- readFileSync ( path . join ( packaged , name ) ) ,
190- packagedFiles [ name ] ,
191- ) ;
192- assert . notEqual ( spec . gooseDevProfile , spec . goose . profile ) ;
193165 // Rebuilds reuse stable source checkouts, so Cargo can skip unchanged crates.
194166 assert . deepEqual (
195167 [ ...new Set ( calls ( ) . map ( ( call ) => call . cwd ) ) ] ,
@@ -198,10 +170,6 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
198170 ) ,
199171 ) ;
200172 // A checkout an interrupted run left unusable is fetched again from scratch.
201- rmSync ( path . join ( directory , "src-tauri/resources/agent-runtime-dev" ) , {
202- recursive : true ,
203- force : true ,
204- } ) ;
205173 writeFileSync ( path . join ( sources , "goose/broken-checkout" ) , "" ) ;
206174 assert . match ( run ( "--dev" ) , / V e r i f i e d i n p u t s s t a g e d / ) ;
207175 assert . ok ( ! existsSync ( path . join ( sources , "goose/broken-checkout" ) ) ) ;
@@ -280,7 +248,7 @@ test("overlapping preparation cannot replace another build's source checkout", a
280248 const [ code ] = await completed ;
281249 assert . equal ( code , 0 , stderr ) ;
282250 }
283- // An abandoned lock is retained until the operator explicitly clears it .
251+ // A force-killed preparation's lock is retained until explicitly cleared .
284252 const lock = path . join ( directory , "target/agent-runtime-prepare.lock" ) ;
285253 mkdirSync ( lock ) ;
286254 const abandoned = spawnSync (
@@ -323,6 +291,50 @@ test("overlapping preparation cannot replace another build's source checkout", a
323291 ) ;
324292} ) ;
325293
294+ test ( "interrupting preparation releases its lock" , {
295+ skip : process . platform === "win32" && "POSIX process-group signal" ,
296+ } , async ( t ) => {
297+ const directory = mkdtempSync ( path . join ( tmpdir ( ) , "buzz-agent-runtime-" ) ) ;
298+ t . after ( ( ) => rmSync ( directory , { recursive : true , force : true } ) ) ;
299+ runtimeFixture ( directory ) ;
300+ const server = createServer ( ) ;
301+ const started = once ( server , "connection" ) ;
302+ server . listen ( 0 , "127.0.0.1" ) ;
303+ await once ( server , "listening" ) ;
304+ t . after ( ( ) => server . close ( ) ) ;
305+ writeFileSync (
306+ path . join ( directory , "hold-build" ) ,
307+ String ( server . address ( ) . port ) ,
308+ ) ;
309+ // Its own process group, like a terminal's foreground job.
310+ const child = spawn (
311+ process . execPath ,
312+ [ "scripts/build-agent-runtime.mjs" , "--dev" ] ,
313+ { cwd : directory , stdio : "ignore" , detached : true } ,
314+ ) ;
315+ const completed = once ( child , "close" ) ;
316+ const [ socket ] = await Promise . race ( [
317+ started ,
318+ completed . then ( ( [ code ] ) => {
319+ throw new Error ( `Preparation exited before the compiler (${ code } )` ) ;
320+ } ) ,
321+ ] ) ;
322+ const lock = path . join ( directory , "target/agent-runtime-prepare.lock" ) ;
323+ assert . ok ( existsSync ( lock ) ) ;
324+ const compilerStopped = once ( socket , "close" ) ;
325+ // Ctrl-C signals the whole foreground process group, compiler included.
326+ process . kill ( - child . pid , "SIGINT" ) ;
327+ const [ [ code ] ] = await Promise . all ( [ completed , compilerStopped ] ) ;
328+ assert . notEqual ( code , 0 ) ;
329+ assert . ok ( ! existsSync ( lock ) ) ;
330+ const next = spawnSync (
331+ process . execPath ,
332+ [ "scripts/build-agent-runtime.mjs" , "--dev" ] ,
333+ { cwd : directory , encoding : "utf8" , timeout : 10_000 } ,
334+ ) ;
335+ assert . equal ( next . status , 0 , next . stderr ) ;
336+ } ) ;
337+
326338test ( "runtime output ignores a user-level build target and survives an interrupted build" , ( t ) => {
327339 const directory = mkdtempSync ( path . join ( tmpdir ( ) , "buzz-agent-runtime-" ) ) ;
328340 t . after ( ( ) => rmSync ( directory , { recursive : true , force : true } ) ) ;
0 commit comments