@@ -337,19 +337,23 @@ export async function launch(options: LaunchOptions = {}): Promise<HeadlessHost>
337337 : AbortSignal . any ( [ options . signal , deadlineSignal ] ) ;
338338 const socketPath = options . socketPath ?? defaultSocketPath ( options . environment ?? process . env ) ;
339339 validateSocketLocation ( socketPath ) ;
340- const presentation = options . presentation ?? "background" ;
341- if ( ! ( LAUNCH_PRESENTATIONS as readonly string [ ] ) . includes ( presentation ) ) {
340+ const presentation = options . presentation ;
341+ if ( presentation !== undefined
342+ && ! ( LAUNCH_PRESENTATIONS as readonly string [ ] ) . includes ( presentation ) ) {
342343 throw new ValidationError ( `presentation must be one of ${ LAUNCH_PRESENTATIONS . join ( ", " ) } ` ) ;
343344 }
344345 const presentationFlags = new Set ( LAUNCH_PRESENTATIONS . map ( ( value ) => `--${ value } ` ) ) ;
345346 const generatedPresentationFlags = LOCAL_LIFECYCLE . launch . argv
346347 . filter ( ( argument ) => presentationFlags . has ( argument ) ) ;
347- if ( generatedPresentationFlags . length !== 1 ) {
348+ if ( generatedPresentationFlags . length !== 0 ) {
348349 throw new ValidationError ( "generated launch argv has an invalid presentation flag" ) ;
349350 }
350- const argumentsList : string [ ] = LOCAL_LIFECYCLE . launch . argv . map ( ( argument ) => (
351- presentationFlags . has ( argument ) ? `--${ presentation } ` : argument
352- ) ) ;
351+ const argumentsList : string [ ] = [ ...LOCAL_LIFECYCLE . launch . argv ] ;
352+ const supervisedIndex = argumentsList . indexOf ( "--supervised" ) ;
353+ if ( supervisedIndex < 0 || argumentsList . lastIndexOf ( "--supervised" ) !== supervisedIndex ) {
354+ throw new ValidationError ( "generated launch argv has an invalid supervised flag" ) ;
355+ }
356+ if ( presentation !== undefined ) argumentsList . splice ( supervisedIndex , 0 , `--${ presentation } ` ) ;
353357 const allowDefinition = LOCAL_LIFECYCLE . launch . options . find ( ( option ) => option . name === "allow" ) ;
354358 const allow = options . allow ?? [ ] ;
355359 if ( ! allowDefinition || allow . length > allowDefinition . maximumItems ) {
0 commit comments