@@ -47,7 +47,8 @@ type Stub = Partial<ExecResult> | Error;
4747 * The host tools one bundle open reads — `lsappinfo`, `ps`, `plutil`, and `open` itself — answered
4848 * per call through the one executor seam the probe runs end to end, with every call and the budget
4949 * it was given recorded in order. An `Error` answer throws, the way a missing tool throws at the
50- * real seam. The `ps` answer is the current process table.
50+ * real seam. `ps` answers with the current process table unless the responder overrides it, so a
51+ * test can make the scan throw, fail, or time out like any other read.
5152 */
5253function fakeMacHost ( respond : ( call : RecordedCall , index : number ) => Stub = ( ) => ( { } ) ) : {
5354 runCommand : AppleToolCommandExecutor ;
@@ -58,12 +59,10 @@ function fakeMacHost(respond: (call: RecordedCall, index: number) => Stub = () =
5859 const runCommand : AppleToolCommandExecutor = async ( cmd , args , options ) => {
5960 const call = { cmd, args, timeoutMs : options ?. timeoutMs } ;
6061 const index = calls . push ( call ) - 1 ;
61- if ( cmd === PROCESS_TABLE_TOOL ) {
62- return { stdout : processTable . stdout , stderr : '' , exitCode : 0 } ;
63- }
6462 const answer = respond ( call , index ) ;
6563 if ( answer instanceof Error ) throw answer ;
66- return { stdout : '' , stderr : '' , exitCode : 0 , ...answer } ;
64+ const fallback = cmd === PROCESS_TABLE_TOOL ? { stdout : processTable . stdout } : { } ;
65+ return { stdout : '' , stderr : '' , exitCode : 0 , ...fallback , ...answer } ;
6766 } ;
6867 return {
6968 runCommand,
@@ -348,6 +347,87 @@ test('openBundle treats a failing first registration read as an instance to atta
348347 expect ( mockSleep ) . not . toHaveBeenCalled ( ) ;
349348} ) ;
350349
350+ test ( 'openBundle opens unchanged when the process-table read cannot run' , async ( ) => {
351+ runningCopies ( ) ;
352+ const { runCommand, calls, transcript } = fakeMacHost ( ( call ) =>
353+ // The scan now runs through the provider's executor, so like every other probe read it can
354+ // fail outright. A ps that cannot spawn must end the probe, not be read as an empty table.
355+ call . cmd === PROCESS_TABLE_TOOL
356+ ? new AppError ( 'TOOL_MISSING' , 'Required macOS tool not found: ps' )
357+ : { } ,
358+ ) ;
359+
360+ await openBundle ( runCommand ) ;
361+
362+ expect ( transcript ( ) ) . toEqual ( [
363+ { cmd : LAUNCH_SERVICES_TOOL , args : [ 'find' , `bundleid=${ BUNDLE_ID } ` ] } ,
364+ { cmd : PROCESS_TABLE_TOOL , args : PROCESS_TABLE_ARGS } ,
365+ { cmd : 'open' , args : [ '-b' , BUNDLE_ID ] } ,
366+ ] ) ;
367+ expect ( calls . at ( - 1 ) ) . toEqual ( { cmd : 'open' , args : [ '-b' , BUNDLE_ID ] } ) ;
368+ expect ( mockEmitDiagnostic ) . toHaveBeenCalledWith (
369+ expect . objectContaining ( {
370+ level : 'warn' ,
371+ phase : 'macos_launch_services_registration_probe_failed' ,
372+ data : expect . objectContaining ( { bundleId : BUNDLE_ID , reason : 'TOOL_MISSING' } ) ,
373+ } ) ,
374+ ) ;
375+ expect ( mockSleep ) . not . toHaveBeenCalled ( ) ;
376+ } ) ;
377+
378+ test ( 'openBundle leaves the wait alone when the process-table read is killed at its budget' , async ( ) => {
379+ runningCopies ( ) ;
380+ const { runCommand, transcript } = fakeMacHost ( ( call ) =>
381+ // The exec seam rejects a command it killed at its own timeoutMs. The probe shares one budget
382+ // across reads, so a scan killed mid-probe says nothing about what runs: no candidates, no
383+ // wait, and the open proceeds exactly as it did before the probe existed.
384+ call . cmd === PROCESS_TABLE_TOOL
385+ ? new AppError ( 'COMMAND_FAILED' , 'ps timed out after 2000ms' , { timeoutMs : 2_000 } )
386+ : { } ,
387+ ) ;
388+
389+ await openBundle ( runCommand ) ;
390+
391+ expect ( transcript ( ) ) . toEqual ( [
392+ { cmd : LAUNCH_SERVICES_TOOL , args : [ 'find' , `bundleid=${ BUNDLE_ID } ` ] } ,
393+ { cmd : PROCESS_TABLE_TOOL , args : PROCESS_TABLE_ARGS } ,
394+ { cmd : 'open' , args : [ '-b' , BUNDLE_ID ] } ,
395+ ] ) ;
396+ expect ( mockEmitDiagnostic ) . toHaveBeenCalledWith (
397+ expect . objectContaining ( {
398+ level : 'warn' ,
399+ phase : 'macos_launch_services_registration_probe_failed' ,
400+ data : expect . objectContaining ( { bundleId : BUNDLE_ID , reason : 'COMMAND_FAILED' } ) ,
401+ } ) ,
402+ ) ;
403+ expect ( mockSleep ) . not . toHaveBeenCalled ( ) ;
404+ } ) ;
405+
406+ test ( 'openBundle treats a failed process-table exit as an unreadable table, not as no processes' , async ( ) => {
407+ runningCopies ( ) ;
408+ const { runCommand, transcript } = fakeMacHost ( ( call ) =>
409+ call . cmd === PROCESS_TABLE_TOOL ? { exitCode : 1 , stderr : 'ps: operation not permitted' } : { } ,
410+ ) ;
411+
412+ await openBundle ( runCommand ) ;
413+
414+ // `listHostProcesses` answers a non-zero exit with no rows, which the probe reads the same way as
415+ // an empty answer: the read failed, and inferring "nothing runs" from it would skip the wait.
416+ expect ( transcript ( ) ) . toEqual ( [
417+ { cmd : LAUNCH_SERVICES_TOOL , args : [ 'find' , `bundleid=${ BUNDLE_ID } ` ] } ,
418+ { cmd : PROCESS_TABLE_TOOL , args : PROCESS_TABLE_ARGS } ,
419+ { cmd : 'open' , args : [ '-b' , BUNDLE_ID ] } ,
420+ ] ) ;
421+ expect ( mockEmitDiagnostic ) . toHaveBeenCalledWith (
422+ expect . objectContaining ( {
423+ level : 'warn' ,
424+ phase : 'macos_launch_services_process_table_unreadable' ,
425+ data : { bundleId : BUNDLE_ID } ,
426+ } ) ,
427+ ) ;
428+ expect ( mockSleep ) . not . toHaveBeenCalled ( ) ;
429+ } ) ;
430+
351431test ( 'openBundle reports a process table that answers nothing rather than reading it as empty' , async ( ) => {
352432 processTable . stdout = '' ;
353433 const { runCommand, transcript } = fakeMacHost ( ( call ) =>
0 commit comments