diff --git a/apps/ios/ModexCompanion/Scripts/observe-trust-stalls.mjs b/apps/ios/ModexCompanion/Scripts/observe-trust-stalls.mjs index f5af4d18..09064b64 100644 --- a/apps/ios/ModexCompanion/Scripts/observe-trust-stalls.mjs +++ b/apps/ios/ModexCompanion/Scripts/observe-trust-stalls.mjs @@ -190,6 +190,42 @@ export async function resolveAppImage({ deviceId, signal, command = runBounded } catch (error) { throw Object.assign(Error('App image realpath unavailable'), { imageStage: 'image-realpath', code: error?.code }); } } +// Only a confirmed-closed metadata timeout permits another read; no pairing or sampling is retried here. +export async function confirmBootedSimulator({ deviceId, signal, command = runBounded, onAttempt = () => {} }) { + const failure = (code, closed, pid) => Object.assign(Error('Explicit simulator metadata unavailable'), { + code, ...(typeof closed === 'boolean' ? { closed } : {}), ...(pidOK(pid) ? { pid } : {}), + }); + if (!UUID.test(deviceId)) throw failure('INVALID_DEVICE'); + const codes = new Set(['COMMAND_TIMEOUT', 'ABORT_ERR', 'COMMAND_FAILED', 'OUTPUT_LIMIT', 'DIAGNOSTIC_STOPPED', 'INVALID_BOUNDS', 'COMMAND_CLEANUP_UNVERIFIED']); + for (let attempt = 1; attempt <= 3; attempt++) { + if (signal?.aborted) throw failure('ABORT_ERR', true); + let result; + try { + result = await command('/usr/bin/xcrun', ['simctl', 'list', 'devices', 'booted', '-j'], { signal, maxBytes: 1024 * 1024, timeoutMs: 5000 }); + if (result.closed !== true) throw failure('COMMAND_CLEANUP_UNVERIFIED', result.closed, result.pid); + if (signal?.aborted) throw failure('ABORT_ERR', true, result.pid); + } catch (error) { + const code = codes.has(error?.code) ? error.code : 'SIMULATOR_QUERY_UNAVAILABLE'; + onAttempt({ attempt, outcome: 'unavailable', code, ...(typeof error?.closed === 'boolean' ? { commandClosed: error.closed } : {}) }); + if (signal?.aborted) throw failure('ABORT_ERR', error?.closed, error?.pid); + if (code !== 'COMMAND_TIMEOUT' || error?.closed !== true || attempt === 3) throw failure(code, error?.closed, error?.pid); + continue; + } + let devices; + try { devices = JSON.parse(result.stdout.toString()); } + catch { + onAttempt({ attempt, outcome: 'unavailable', code: 'INVALID_DEVICE_LIST', commandClosed: true }); + throw failure('INVALID_DEVICE_LIST', true); + } + if (!Object.values(devices?.devices ?? {}).flat().some(device => device?.udid === deviceId && device.state === 'Booted')) { + onAttempt({ attempt, outcome: 'refused', code: 'DEVICE_NOT_BOOTED', commandClosed: true }); + throw failure('DEVICE_NOT_BOOTED', true); + } + onAttempt({ attempt, outcome: 'booted' }); + return; + } +} + export async function runObserver({ deviceId, output, signal }) { if (process.platform !== 'darwin' || process.env.GITHUB_ACTIONS !== 'true' || process.env.RUNNER_OS !== 'macOS' || !UUID.test(deviceId) || !path.isAbsolute(output) || path.resolve(output) === '/') throw Error('Trust stack diagnostics require an explicit macOS CI simulator and output path'); @@ -203,8 +239,9 @@ export async function runObserver({ deviceId, output, signal }) { const command = gateCommands(runBounded, info => { receipt.unconfirmedCommand = info; receipt.unavailable = 'COMMAND_CLEANUP_UNVERIFIED'; deadline.abort(); observer?.close(); }); const save = () => fs.writeFileSync(path.join(directory, 'manifest.json'), JSON.stringify({ ...receipt, observation: observer?.report }, null, 2) + '\n', { mode: 0o600 }); try { - const devices = JSON.parse((await command('/usr/bin/xcrun', ['simctl', 'list', 'devices', 'booted', '-j'], { signal: combined })).stdout.toString()); - if (!Object.values(devices.devices ?? {}).flat().some(x => x.udid === deviceId && x.state === 'Booted')) throw Error('Explicit simulator is not booted'); + receipt.startup = { stage: 'device-metadata', attempts: [] }; save(); + await confirmBootedSimulator({ deviceId, signal: combined, command, onAttempt: row => { receipt.startup.attempts.push(row); save(); } }); + receipt.startup.stage = 'device-confirmed'; save(); const appImage = () => resolveAppImage({ deviceId, signal: combined, command }); observer = new TrustStallObserver({ deviceId, appImage, identity: (pid, image) => currentIdentity(pid, image, combined, command), sample: async (pid, opts) => { diff --git a/docs/reviews/2026-11-13-ios-trust-bootstrap.md b/docs/reviews/2026-11-13-ios-trust-bootstrap.md new file mode 100644 index 00000000..faddcf80 --- /dev/null +++ b/docs/reviews/2026-11-13-ios-trust-bootstrap.md @@ -0,0 +1,13 @@ +# iPhone trust observer startup recovery + +The paired iPhone job for PR #524 at signed `ff353c0c0900ee4090985f897ba4e44e65c55d7f` failed before its Mac thread appeared. Its immutable artifact passed API size/digest and ZIP checks. Native xcresults retain 65 passes; paired xcresults retain 42 passes, one expected-failure control and one actual failure. The recording shows “Connection issue — The request timed out.” App diagnostics record callback-enter and chain-start without chain-return, and the system archive records the same app entering Security trust evaluation with a matching trustd peer. These observations localize the blocked certificate-chain read, but do not establish its underlying cause or a product TLS repair. + +The observer itself stopped after its first five-second booted-device metadata query. Its manifest records COMMAND_TIMEOUT without the common unconfirmed-cleanup marker. The existing bounded-command implementation distinguishes a closed timeout from unverified closure; the new recovery relies on the actual `closed === true` result for every retry rather than assuming closure from an error name. It makes at most three sequential reads of the same booted-device metadata, retaining the same five-second and one-MiB command limits and the existing fifteen-minute observer deadline. Non-timeout errors, cancellation, malformed metadata, the wrong/not-booted device and unconfirmed closure remain terminal. A success racing cancellation cannot confirm startup. Receipts retain fixed outcome/error classes per attempt and no raw command output or error text. + +The explicit CI/Debug device guard, app image/process birth checks, callback/thread/activity and trustd-peer binding, sample bounds and common cleanup stop gate remain unchanged. Direct command closure still does not prove simulator-side descendant cleanup or atomic native identity. This change retries only diagnostic startup reads; it does not retry pairing, change test outcomes, alter trust APIs/pins/request deadlines, modify OS preferences or admit a runtime. + +The existing focused baseline passed 25 cases. Seventeen new bootstrap controls cover successful metadata, one/two closed timeouts, budget exhaustion, unclosed/unknown closure, non-timeout errors, pre/post-command cancellation, wrong device, malformed data, successful-but-unconfirmed closure, invalid identifiers and private error strings. The cancellation-success race first failed with a missing rejection and then passed after the post-command abort check. The final combined run passed all 42 cases with no skips or failures. The initial missing-helper RED and one test-fixture correction are retained separately; the original four-file scoped review found no Critical or Important issues. Full root validation and hosted diagnostic collection retain their own receipts. + +Evidence is retained outside the worktree in the session’s `modex-closeout` directory: `pr524-ff353c0-iphone-first-failure-proof.json`, the verified archive and extracted xcresults/recording/diagnostics, `ios-trust-bootstrap-baseline.log`, `ios-trust-bootstrap-red.log`, `ios-trust-bootstrap-abort-race-red.log` and `ios-trust-bootstrap-final-focused.log`. No acceptance checkbox, physical-phone/older-Companion/two-LAN gate, release or activation decision changes on these observations. A future successful pairing alone must not be described as a repair of the original trust stall. + +The first frozen full-root run at signed `8ac7c8014b7a30d7900986234f0f65f0df5ac842` passed build and typechecks but failed the shell-harness unit case: its mock returned the expected Xcode failure while the trace lacked observer startup. That mock used the same exit code for ready acknowledgement and a 1.5-second wait expiry. A controlled two-second acknowledgement delay reproduced the missing startup trace, and a suppressed acknowledgement reproduced the falsely expected exit code; neither proves the exact cause of the original occurrence. The fixture now reports Xcode failure only after acknowledgement and a distinct fixture failure on its shared monotonic deadline. Its seven-second total fixture budget stays below the unchanged eight-second parent and ten-second test limits; the missing-acknowledgement control uses the same seven-second budget so setup under load does not consume a separate short startup allowance. The independent follow-up review caught and removed an initial 500-millisecond negative-case allowance. Both controls still require owned helper start/stop records. Production shell behavior, pairing outcomes and request deadlines remain unchanged. All 44 combined focused cases pass without failures or skips; fresh full-root validation remains required. The first full-root failure and both controlled RED failures are retained in `ios-trust-bootstrap-full-test.log` and `ios-trust-bootstrap-harness-ack-red.log`; the complete focused result is `ios-trust-bootstrap-all44-focused.log`. diff --git a/docs/status.md b/docs/status.md index 76593cbe..4422ee30 100644 --- a/docs/status.md +++ b/docs/status.md @@ -162,6 +162,8 @@ before relying on a tick. - **Paired trust stack diagnostics** (#498). Parent `fc593e0` passed all 44 paired/demo executions, while the earlier `da13074` initial-pair failure retains Security/trustd activity before a request timeout and no proven cause. The new CI-only Debug observer binds an explicit simulator, app/process metadata, callback thread/activity and trustd peer before bounded stack collection. Completed callbacks suppress collection; unavailable or unconfirmed cleanup stays explicit, and Xcode's original exit code is preserved. Nineteen focused controls and frozen build/typecheck/full units passed (2,454 passes, 36 explicit skips, zero failures). Actual owned-process sample/identity controls and retained-log schema replay passed within their limited scopes. Fresh hosted simulator collection, descendant cleanup, TLS repair and human/device acceptance remain unqualified. Client trust APIs, pins and deadlines are unchanged. [Evidence and limits](reviews/2026-11-11-ios-trust-stack-observer.md). +- **iPhone diagnostic startup recovery** (#109, #281). PR #524’s first paired run retains a connection timeout, 65 native passes and 42 paired passes with one expected-failure control and one actual failure. App/system diagnostics reach certificate-chain trust evaluation without a return; the underlying cause remains unproven. Its observer exited on a five-second startup metadata timeout before collecting stacks. A separate diagnostic-only repair permits at most three reads after confirmed-closed startup timeouts while preserving command bounds, device/process identity, cleanup refusal and test outcomes. All 44 focused observer/harness controls pass. The first full-root build/typecheck passed but its harness unit failed; controlled RED cases established a fixture acknowledgement defect, now corrected within the existing parent/test limits without establishing the original timing cause. Fresh full/hosted qualification and actual causal stack collection remain pending. Pins, trust APIs, request deadlines and human/device gates are unchanged. [Failure, recovery and limits](reviews/2026-11-13-ios-trust-bootstrap.md). + - **Actionable local context failures** (#380, #498). The captured real native dense-input run failed after compaction at 73,800 tokens against a 65,536-token slot; the outbound request retained all three prior dense inputs and the fourth new input. The repair explains recognized context-limit failures while preserving failed status, native diagnostics and no automatic retry/model switch. Build/typechecks passed; final full units passed with 2,435 passes, 36 explicit skips and zero failures. Four installed-Codex/scripted-server failure cases passed, each with one synthetic command effect and no repeated request or model change. The first final unit run's Vite port failure remains retained despite a green explicit revalidation. Parent `da13074` passed Windows, but Linux package-host DNS and initial paired-iPhone qualification failed; archived TLS activity reaches Security/trustd before the request timeout, with no cause or trust repair established. Fresh exact-head hosted checks and all admission/native/human gates remain open. [Evidence and limits](reviews/2026-11-11-local-context-overflow.md). - **Local draft destination fence** (#380, #381, #498). Final review found that an asynchronous local selection could accept input/send through its old non-local configuration before the target was pinned. Two controlled regressions failed; the repair reserves and fences only the source/new target, preserves the exact raw draft, and leaves unrelated Stop and editing available. All three focused Electron cases and full frozen build/typechecks/units pass (2,465 unit passes, 36 skips), followed by 511 desktop E2E passes with 11 skips and seven site passes. Protected [#498](https://github.com/TypeSafeAI/modex/pull/498) has since delivered this repair; its exact merge-group macOS check passed. The counts above retain their original candidate scope, and product local execution remains unadmitted. [Failure, repair and limits](reviews/2026-11-11-local-selection-fence.md). diff --git a/scripts/test/ios-trust-bootstrap.test.mjs b/scripts/test/ios-trust-bootstrap.test.mjs new file mode 100644 index 00000000..e652051e --- /dev/null +++ b/scripts/test/ios-trust-bootstrap.test.mjs @@ -0,0 +1,100 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import * as diagnostics from '../../apps/ios/ModexCompanion/Scripts/observe-trust-stalls.mjs'; + +const deviceId = '2CC7A2C1-E1A7-4633-911A-DB60BDEB97F0'; +const otherId = 'CE535A64-185F-4FD3-8C18-86EE73EB4C42'; +const booted = () => ({ stdout: Buffer.from(JSON.stringify({ devices: { runtime: [{ udid: deviceId, state: 'Booted' }] } })), closed: true }); +const unavailable = (code = 'COMMAND_TIMEOUT', closed = true) => Object.assign(Error('private command text'), { code, closed, pid: 12345 }); + +// These tests never invoke simctl or inspect a person's simulator: only the fixed command contract is exercised. +test('startup observes the explicitly selected booted device with unchanged command bounds', async () => { + const signal = new AbortController().signal, rows = []; let calls = 0; + await diagnostics.confirmBootedSimulator({ deviceId, signal, onAttempt: row => rows.push(row), command: async (binary, args, options) => { + calls++; assert.equal(binary, '/usr/bin/xcrun'); assert.deepEqual(args, ['simctl', 'list', 'devices', 'booted', '-j']); + assert.equal(options.signal, signal); assert.equal(options.timeoutMs, 5000); assert.equal(options.maxBytes, 1024 * 1024); return booted(); + } }); + assert.equal(calls, 1); assert.deepEqual(rows, [{ attempt: 1, outcome: 'booted' }]); +}); + +for (const failures of [1, 2]) test(`startup recovers after ${failures} confirmed-closed metadata timeout(s)`, async () => { + let calls = 0; const rows = []; + await diagnostics.confirmBootedSimulator({ deviceId, onAttempt: row => rows.push(row), command: async () => { if (++calls <= failures) throw unavailable(); return booted(); } }); + assert.equal(calls, failures + 1); + assert.deepEqual(rows.slice(0, failures), Array.from({ length: failures }, (_, i) => ({ attempt: i + 1, outcome: 'unavailable', code: 'COMMAND_TIMEOUT', commandClosed: true }))); + assert.deepEqual(rows.at(-1), { attempt: failures + 1, outcome: 'booted' }); +}); + +test('three closed startup timeouts exhaust the budget without accepting a device', async () => { + let calls = 0; const rows = []; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, onAttempt: row => rows.push(row), command: async () => { calls++; throw unavailable(); } }), e => e.code === 'COMMAND_TIMEOUT' && e.closed === true); + assert.equal(calls, 3); assert.equal(rows.length, 3); assert.equal(rows.some(row => row.outcome === 'booted'), false); +}); + +test('an unclosed startup child keeps the common stop gate and never permits another command', async () => { + let calls = 0; const notices = []; + const command = diagnostics.gateCommands(async () => { calls++; throw unavailable('COMMAND_TIMEOUT', false); }, info => notices.push(info)); + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, command }), e => e.code === 'COMMAND_TIMEOUT' && e.closed === false); + await assert.rejects(command(), e => e.code === 'DIAGNOSTIC_STOPPED'); + assert.equal(calls, 1); assert.deepEqual(notices, [{ pid: 12345, code: 'COMMAND_TIMEOUT' }]); +}); + +test('unknown child closure never qualifies for a retry', async () => { + let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, command: async () => { calls++; const error = unavailable(); delete error.closed; throw error; } }), e => e.code === 'COMMAND_TIMEOUT'); + assert.equal(calls, 1); +}); + +for (const code of ['COMMAND_FAILED', 'OUTPUT_LIMIT', 'ABORT_ERR']) test(`closed ${code} is not a retryable startup timeout`, async () => { + let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, command: async () => { calls++; throw unavailable(code); } }), e => e.code === code); + assert.equal(calls, 1); +}); + +test('an already-aborted observer launches no startup command', async () => { + const abort = new AbortController(); abort.abort(); let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, signal: abort.signal, command: async () => { calls++; return booted(); } }), e => e.code === 'ABORT_ERR'); + assert.equal(calls, 0); +}); + +test('abort after a closed timeout prevents the next attempt', async () => { + const abort = new AbortController(); let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, signal: abort.signal, command: async () => { calls++; abort.abort(); throw unavailable(); } }), e => e.code === 'ABORT_ERR'); + assert.equal(calls, 1); +}); + +test('another booted device does not satisfy explicit simulator identity', async () => { + let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, command: async () => { calls++; return { stdout: Buffer.from(JSON.stringify({ devices: { runtime: [{ udid: otherId, state: 'Booted' }] } })), closed: true }; } }), e => e.code === 'DEVICE_NOT_BOOTED'); + assert.equal(calls, 1); +}); + +test('malformed device metadata is refused without retry or retained output', async () => { + let calls = 0; const rows = []; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, onAttempt: row => rows.push(row), command: async () => { calls++; return { stdout: Buffer.from('private malformed JSON'), closed: true }; } }), e => e.code === 'INVALID_DEVICE_LIST'); + assert.equal(calls, 1); assert.equal(JSON.stringify(rows).includes('private'), false); +}); + +test('even a successful result needs confirmed command closure', async () => { + let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, command: async () => { calls++; return { ...booted(), closed: false }; } }), e => e.code === 'COMMAND_CLEANUP_UNVERIFIED' && e.closed === false); + assert.equal(calls, 1); +}); + +test('invalid explicit device identifiers launch nothing', async () => { + let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId: '../other-device', command: async () => { calls++; return booted(); } }), e => e.code === 'INVALID_DEVICE'); + assert.equal(calls, 0); +}); + +test('unknown error text and codes do not enter startup receipts', async () => { + const rows = []; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, onAttempt: row => rows.push(row), command: async () => { throw unavailable('private/path\ncredential'); } }), e => e.code === 'SIMULATOR_QUERY_UNAVAILABLE' && !e.message.includes('private')); + assert.deepEqual(rows, [{ attempt: 1, outcome: 'unavailable', code: 'SIMULATOR_QUERY_UNAVAILABLE', commandClosed: true }]); +}); + +test('cancellation racing a successful closed query cannot confirm startup', async () => { + const abort = new AbortController(), rows = []; let calls = 0; + await assert.rejects(diagnostics.confirmBootedSimulator({ deviceId, signal: abort.signal, onAttempt: row => rows.push(row), command: async () => { calls++; abort.abort(); return booted(); } }), e => e.code === 'ABORT_ERR'); + assert.equal(calls, 1); assert.equal(rows.some(row => row.outcome === 'booted'), false); +}); diff --git a/scripts/test/ios-trust-stalls.test.mjs b/scripts/test/ios-trust-stalls.test.mjs index 2dbf12d9..3eee0795 100644 --- a/scripts/test/ios-trust-stalls.test.mjs +++ b/scripts/test/ios-trust-stalls.test.mjs @@ -87,7 +87,7 @@ test('another thread cannot assign its Security activity to the stalled callback await h.observer.ingest({processID:2309,processImagePath:daemon,bootUUID:boot,threadID:2,timestamp:new Date(epoch).toISOString(),eventMessage:'com.apple.trustd.peer[19815]',activityIdentifier:232431});h.advance(6000);await h.observer.tick();assert.deepEqual(h.collected,[19815]); }); -for (const [name,ci,configuration,expectObserver] of [['CI Debug',true,'Debug',true],['local Debug',false,'Debug',false],['CI Release',true,'Release',false]]) { +for (const [name,ci,configuration,expectObserver,startupDelay=0,suppressReady=false,budget=7000] of [['CI Debug',true,'Debug',true],['local Debug',false,'Debug',false],['CI Release',true,'Release',false],['CI Debug delayed acknowledgement',true,'Debug',true,2000],['CI Debug missing acknowledgement',true,'Debug',true,0,true]]) { test(`paired shell harness preserves Xcode failure and owns helpers for ${name}`,{timeout:10000,skip:process.platform==='win32'&&'POSIX paired harness'},async t=>{ const {spawnSync}=await import('node:child_process'); const directory=fs.mkdtempSync(path.join(os.tmpdir(),'modex-trust-harness-'));t.after(()=>fs.rmSync(directory,{recursive:true,force:true})); @@ -96,13 +96,13 @@ for (const [name,ci,configuration,expectObserver] of [['CI Debug',true,'Debug',t fs.copyFileSync(new URL('../../apps/ios/ModexCompanion/Scripts/test-e2e.sh',import.meta.url),path.join(scriptDir,'test-e2e.sh')); for(const name of ['pnpm','xcodegen'])fs.writeFileSync(path.join(bin,name),'#!/bin/sh\nexit 0\n',{mode:0o755}); fs.writeFileSync(path.join(bin,'node'),`#!${process.execPath} -const fs=require('node:fs'),path=require('node:path');const [file,...args]=process.argv.slice(2);const role=path.basename(file)==='fixture.mjs'?'fixture':'observer';const log=event=>fs.appendFileSync(process.env.MODEX_TEST_TRUST_TRACE,JSON.stringify({role,event,pid:process.pid,args})+'\\n');log('start');if(role==='fixture')fs.writeFileSync(args[0],'{"link":"synthetic"}');else fs.writeFileSync(process.env.MODEX_TEST_TRUST_READY,'ready');setInterval(()=>{},1000);process.on('SIGTERM',()=>{log('stop');process.exit(0)}); +const fs=require('node:fs'),path=require('node:path');const [file,...args]=process.argv.slice(2);const role=path.basename(file)==='fixture.mjs'?'fixture':'observer';const log=event=>fs.appendFileSync(process.env.MODEX_TEST_TRUST_TRACE,JSON.stringify({role,event,pid:process.pid,args})+'\\n');const start=()=>{log('start');if(role==='fixture')fs.writeFileSync(args[0],'{"link":"synthetic"}');else if(process.env.MODEX_TEST_TRUST_SUPPRESS_READY!=='1')fs.writeFileSync(process.env.MODEX_TEST_TRUST_READY,'ready');setInterval(()=>{},1000);process.on('SIGTERM',()=>{log('stop');process.exit(0)});};if(role==='observer'&&Number(process.env.MODEX_TEST_TRUST_STARTUP_DELAY)>0)setTimeout(start,Number(process.env.MODEX_TEST_TRUST_STARTUP_DELAY));else start(); `,{mode:0o755}); fs.writeFileSync(path.join(bin,'xcodebuild'),`#!${process.execPath} -const fs=require('node:fs'),path=require('node:path'),args=process.argv.slice(2);if(args.includes('build-for-testing')){const data=args[args.indexOf('-derivedDataPath')+1];fs.mkdirSync(path.join(data,'Build/Products'),{recursive:true});fs.writeFileSync(path.join(data,'Build/Products/ModexCompanion_fixture.xctestrun'),'fixture');process.exit(0)}if(process.env.MODEX_TEST_TRUST_EXPECT!=='1')process.exit(17);const until=Date.now()+1500;const wait=()=>{if(fs.existsSync(process.env.MODEX_TEST_TRUST_READY)||Date.now()>until)process.exit(17);else setTimeout(wait,10)};wait(); +const fs=require('node:fs'),path=require('node:path'),args=process.argv.slice(2);if(args.includes('build-for-testing')){const data=args[args.indexOf('-derivedDataPath')+1];fs.mkdirSync(path.join(data,'Build/Products'),{recursive:true});fs.writeFileSync(path.join(data,'Build/Products/ModexCompanion_fixture.xctestrun'),'fixture');process.exit(0)}if(process.env.MODEX_TEST_TRUST_EXPECT!=='1')process.exit(17);const until=BigInt(process.env.MODEX_TEST_TRUST_DEADLINE_NS);const wait=()=>{if(fs.existsSync(process.env.MODEX_TEST_TRUST_READY))process.exit(17);if(process.hrtime.bigint()>=until)process.exit(18);setTimeout(wait,10)};wait(); `,{mode:0o755}); - const result=spawnSync('bash',[path.join(scriptDir,'test-e2e.sh')],{encoding:'utf8',timeout:8000,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,GITHUB_ACTIONS:ci?'true':'false',RUNNER_OS:'macOS',MODEX_IOS_CONFIGURATION:configuration,MODEX_IOS_UDID:device,MODEX_IOS_DERIVED_DATA:path.join(directory,'derived'),MODEX_TEST_TRUST_TRACE:trace,MODEX_TEST_TRUST_READY:ready,MODEX_TEST_TRUST_EXPECT:expectObserver?'1':'0'}}); - assert.ifError(result.error);assert.equal(result.status,17,result.stderr);const events=fs.readFileSync(trace,'utf8').trim().split('\n').map(x=>JSON.parse(x)); + const result=spawnSync('bash',[path.join(scriptDir,'test-e2e.sh')],{encoding:'utf8',timeout:8000,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,GITHUB_ACTIONS:ci?'true':'false',RUNNER_OS:'macOS',MODEX_IOS_CONFIGURATION:configuration,MODEX_IOS_UDID:device,MODEX_IOS_DERIVED_DATA:path.join(directory,'derived'),MODEX_TEST_TRUST_TRACE:trace,MODEX_TEST_TRUST_READY:ready,MODEX_TEST_TRUST_EXPECT:expectObserver?'1':'0',MODEX_TEST_TRUST_STARTUP_DELAY:String(startupDelay),MODEX_TEST_TRUST_SUPPRESS_READY:suppressReady?'1':'0',MODEX_TEST_TRUST_DEADLINE_NS:String(process.hrtime.bigint()+BigInt(budget)*1000000n)}}); + assert.ifError(result.error);assert.equal(result.status,suppressReady?18:17,result.stderr);const events=fs.readFileSync(trace,'utf8').trim().split('\n').map(x=>JSON.parse(x)); const roles=expectObserver?['fixture','observer']:['fixture'];assert.deepEqual(events.filter(x=>x.event==='start').map(x=>x.role).sort(),roles); assert.deepEqual(events.filter(x=>x.event==='stop').map(x=>x.role).sort(),roles); const observer=events.find(x=>x.role==='observer');if(expectObserver){assert.deepEqual(observer.args.slice(0,2),['--device',device]);assert.equal(events.filter(x=>x.role==='observer'&&x.event==='start').length,1)}else assert.equal(observer,undefined);