@@ -8,6 +8,25 @@ import os from 'os';
88import { collapseDuplicateShapeCRoutes , getNodesData , getEdgesData } from '../../../../../../ai/daemons/bridge/queries.mjs' ;
99import { SQLITE_IN_CLAUSE_BATCH_SIZE } from '../../../../../../ai/graph/storage/constants.mjs' ;
1010
11+ /**
12+ * @summary Stubs `ps` for subprocess daemon tests so instance-resolution branches do not depend
13+ * on the host machine's live GUI process list.
14+ *
15+ * The bridge daemon resolves same-bundle harness instances by shelling out to `ps`. Unit tests that
16+ * assert the default app-activate AppleScript path must force the resolver to return `null`,
17+ * otherwise a developer machine with Claude.app already running can take the PID-targeted branch
18+ * while CI takes the activate branch.
19+ *
20+ * @param {String } binDir
21+ * @param {String } [psOutput='']
22+ */
23+ function writeMockPs ( binDir , psOutput = '' ) {
24+ const mockPsPath = path . join ( binDir , 'ps' ) ;
25+
26+ fs . writeFileSync ( mockPsPath , `#!/usr/bin/env node\nprocess.stdout.write(${ JSON . stringify ( psOutput ) } );\n` ) ;
27+ fs . chmodSync ( mockPsPath , 0o755 ) ;
28+ }
29+
1130test . describe ( 'Bridge Daemon' , ( ) => {
1231 let db ;
1332 let daemonProcess ;
@@ -643,6 +662,7 @@ test.describe('Bridge Daemon', () => {
643662 // Create mock osascript to capture args without actually running AppleScript
644663 const binDir = path . join ( DAEMON_DIR , 'bin' ) ;
645664 fs . ensureDirSync ( binDir ) ;
665+ writeMockPs ( binDir ) ;
646666 const mockOsascriptPath = path . join ( binDir , 'osascript' ) ;
647667 const mockOutPath = path . join ( DAEMON_DIR , 'mock_out.json' ) ;
648668 fs . writeFileSync ( mockOsascriptPath , `#!/usr/bin/env node\nimport fs from 'fs';\nfs.writeFileSync('${ mockOutPath } ', JSON.stringify(process.argv.slice(2)));\n` ) ;
@@ -731,6 +751,7 @@ test.describe('Bridge Daemon', () => {
731751
732752 const binDir = path . join ( DAEMON_DIR , 'bin' ) ;
733753 fs . ensureDirSync ( binDir ) ;
754+ writeMockPs ( binDir ) ;
734755 const mockOsascriptPath = path . join ( binDir , 'osascript' ) ;
735756 const mockOutPath = path . join ( DAEMON_DIR , 'mock_claude_out.json' ) ;
736757 fs . writeFileSync ( mockOsascriptPath , `#!/usr/bin/env node\nimport fs from 'fs';\nfs.writeFileSync('${ mockOutPath } ', JSON.stringify(process.argv.slice(2)));\n` ) ;
@@ -865,6 +886,7 @@ test.describe('Bridge Daemon', () => {
865886
866887 const binDir = path . join ( DAEMON_DIR , 'bin' ) ;
867888 fs . ensureDirSync ( binDir ) ;
889+ writeMockPs ( binDir ) ;
868890 const mockOsascriptPath = path . join ( binDir , 'osascript' ) ;
869891 const mockOutPath = path . join ( DAEMON_DIR , 'mock_codex_failclosed_out.json' ) ;
870892 fs . writeFileSync ( mockOsascriptPath , `#!/usr/bin/env node\nimport fs from 'fs';\nfs.writeFileSync('${ mockOutPath } ', JSON.stringify(process.argv.slice(2)));\n` ) ;
@@ -957,6 +979,7 @@ test.describe('Bridge Daemon', () => {
957979
958980 const binDir = path . join ( DAEMON_DIR , 'bin' ) ;
959981 fs . ensureDirSync ( binDir ) ;
982+ writeMockPs ( binDir ) ;
960983 const mockOsascriptPath = path . join ( binDir , 'osascript' ) ;
961984 const mockOutPath = path . join ( DAEMON_DIR , 'mock_codex_cleanup_out.json' ) ;
962985 fs . writeFileSync ( mockOsascriptPath , `#!/usr/bin/env node\nimport fs from 'fs';\nfs.writeFileSync('${ mockOutPath } ', JSON.stringify(process.argv.slice(2)));\n` ) ;
0 commit comments