@@ -82,18 +82,20 @@ export function createFixture(options = {}) {
8282 try {
8383 const bin = NodePath . join ( dir , "fake-bin" ) ;
8484 NodeFS . mkdirSync ( bin ) ;
85- const app = NodePath . join ( dir , "Fixture App.app" ) ;
85+ const app = NodePath . join ( dir , options . installedName ?? "Fixture App.app" ) ;
8686 createBundle ( app , "1.0.0" ) ;
87- const source = NodePath . join ( dir , "release/ Fixture App.app" ) ;
87+ const source = NodePath . join ( dir , "release" , options . archiveName ?? " Fixture App.app") ;
8888 createBundle ( source , options . version ?? "2.0.0" , options ) ;
89+ for ( const [ index , bundle ] of ( options . extraBundles ?? [ ] ) . entries ( ) ) {
90+ createBundle ( NodePath . join ( dir , "release" , `Extra ${ index } .app` ) , "2.0.0" , bundle ) ;
91+ }
8992 const expected = snapshot ( source ) ;
9093 const archive = NodePath . join ( dir , "selected.zip" ) ;
9194 const archived = run ( "/usr/bin/ditto" , [
9295 "-c" ,
9396 "-k" ,
9497 "--sequesterRsrc" ,
95- "--keepParent" ,
96- source ,
98+ NodePath . dirname ( source ) ,
9799 archive ,
98100 ] ) ;
99101 NodeAssert . equal ( archived . status , 0 , archived . stderr ) ;
@@ -102,6 +104,10 @@ export function createFixture(options = {}) {
102104
103105 // Only signature, Gatekeeper and launch boundaries are simulated; these are not signed-app fixtures.
104106 const stubs = {
107+ sleep : `#!/bin/sh
108+ printf 'waiting\\n' >&5
109+ exec /bin/sleep "$@"
110+ ` ,
105111 codesign : `#!/bin/sh
106112for arg do bundle=$arg; done
107113if [ "$1" = -dv ]; then printf 'TeamIdentifier=%s\\n' "$(cat "$bundle/.team")" >&2; exit 0; fi
@@ -143,15 +149,16 @@ printf 'open:%s\\n' "$*" >> "$FIXTURE_EVENTS"
143149 FIXTURE_EVENTS : events ,
144150 FIXTURE_PARENT : "99999999" ,
145151 } ;
146- const prepare = ( ) => run ( "/bin/sh" , [ helper , "prepare" , archive , app , "2.0.0" ] , { env } ) ;
147- return { dir, app, archive, expected, helper, env, events, prepare, clean } ;
152+ const attempt = ( ) =>
153+ run ( "/bin/sh" , [ helper , archive , app , "2.0.0" , "99999999" , "false" ] , { env } ) ;
154+ return { dir, app, archive, expected, helper, env, events, attempt, clean } ;
148155 } catch ( error ) {
149156 clean ( ) ;
150157 throw error ;
151158 }
152159}
153160
154- export async function startParent ( ) {
161+ async function startParent ( ) {
155162 const child = NodeChildProcess . spawn (
156163 process . execPath ,
157164 [ "-e" , "process.stdin.resume();process.stdin.on('end',()=>process.exit(0));" ] ,
@@ -161,35 +168,43 @@ export async function startParent() {
161168 return child ;
162169}
163170
164- export async function stopParent ( child ) {
171+ async function stopParent ( child ) {
165172 if ( child . exitCode === null && child . signalCode === null ) {
166173 const exited = NodeEvents . once ( child , "exit" ) ;
167174 child . stdin . end ( ) ;
168175 await exited ;
169176 }
170177}
171178
172- export async function install ( fixture , { relaunch = true , failInstalled = false } = { } ) {
179+ export async function install (
180+ fixture ,
181+ { relaunch = true , failInstalled = false , cancel = false , timeout = false } = { } ,
182+ ) {
173183 const parent = await startParent ( ) ;
174184 let child ;
175185 let watchdog ;
176186 let stdout = "" ;
177187 let stderr = "" ;
178188 try {
179- const prepared = fixture . prepare ( ) ;
180- NodeAssert . equal ( prepared . status , 0 , prepared . stderr ) ;
181- const candidate = prepared . stdout . trim ( ) ;
182- const stage = NodePath . dirname ( candidate ) ;
189+ if ( timeout ) {
190+ // Exercise the production timeout branch without waiting two minutes.
191+ const source = NodeFS . readFileSync ( fixture . helper , "utf8" ) ;
192+ NodeAssert . equal ( source . split ( '"$attempts" -lt 120' ) . length , 2 ) ;
193+ NodeFS . writeFileSync (
194+ fixture . helper ,
195+ source . replace ( '"$attempts" -lt 120' , '"$attempts" -lt 0' ) ,
196+ ) ;
197+ }
183198 child = NodeChildProcess . spawn (
184199 "/bin/sh" ,
185- [ fixture . helper , "install" , candidate , fixture . app , String ( parent . pid ) , String ( relaunch ) ] ,
200+ [ fixture . helper , fixture . archive , fixture . app , "2.0.0" , String ( parent . pid ) , String ( relaunch ) ] ,
186201 {
187202 env : {
188203 ...fixture . env ,
189204 FIXTURE_PARENT : String ( parent . pid ) ,
190205 FIXTURE_FAIL_INSTALLED : failInstalled ? "1" : "0" ,
191206 } ,
192- stdio : [ "ignore" , "pipe" , "pipe" ] ,
207+ stdio : [ "ignore" , "pipe" , "pipe" , "ignore" , "ignore" , "pipe" ] ,
193208 } ,
194209 ) ;
195210 const closed = NodeEvents . once ( child , "close" ) ;
@@ -221,15 +236,37 @@ export async function install(fixture, { relaunch = true, failInstalled = false
221236 } ) ;
222237 NodeAssert . equal ( isAlive ( parent . pid ) , true , "ready precedes fixture parent exit" ) ;
223238 NodeAssert . equal ( NodeFS . readFileSync ( NodePath . join ( fixture . app , ".version" ) , "utf8" ) , "1.0.0" ) ;
224- NodeAssert . equal ( NodeFS . existsSync ( candidate ) , true , "candidate remains staged at readiness" ) ;
225- NodeAssert . equal (
226- NodeFS . existsSync ( `${ fixture . app } .update-lock` ) ,
227- true ,
228- "ready follows lock acquisition" ,
239+ const stages = NodeFS . readdirSync ( fixture . dir ) . filter (
240+ ( name ) =>
241+ name . startsWith ( ".t3-update." ) &&
242+ NodeFS . existsSync ( NodePath . join ( fixture . dir , name , "install.log" ) ) ,
229243 ) ;
244+ NodeAssert . equal ( stages . length , 1 , "one stage belongs to this invocation" ) ;
245+ const stage = NodePath . join ( fixture . dir , stages [ 0 ] ) ;
246+ const candidate = NodePath . join ( stage , "candidate.app" ) ;
247+ if ( ! timeout ) {
248+ NodeAssert . equal ( NodeFS . existsSync ( candidate ) , true , "candidate remains staged at readiness" ) ;
249+ NodeAssert . equal (
250+ NodeFS . existsSync ( `${ fixture . app } .update-lock` ) ,
251+ true ,
252+ "ready follows lock acquisition" ,
253+ ) ;
254+ }
230255 NodeAssert . equal ( NodeFS . readFileSync ( fixture . events , "utf8" ) . includes ( "open:" ) , false ) ;
231- await stopParent ( parent ) ;
256+ if ( cancel ) child . kill ( "SIGTERM" ) ;
257+ else if ( ! timeout ) {
258+ await new Promise ( ( resolve , reject ) => {
259+ child . stdio [ 5 ] . once ( "data" , resolve ) ;
260+ child . once ( "close" , ( ) =>
261+ reject ( new Error ( "installer exited without waiting for its live parent" ) ) ,
262+ ) ;
263+ if ( child . exitCode !== null ) reject ( new Error ( "installer already exited without waiting" ) ) ;
264+ } ) ;
265+ await stopParent ( parent ) ;
266+ }
232267 const [ status ] = await closed ;
268+ if ( cancel || timeout )
269+ NodeAssert . equal ( isAlive ( parent . pid ) , true , "failed handoff leaves parent running" ) ;
233270 return {
234271 status,
235272 stdout,
0 commit comments