1+ import fs from 'node:fs' ;
2+ import path from 'node:path' ;
13import { expect , test , vi } from 'vitest' ;
4+ import { withDiagnosticsScope } from '@agent-device/host-kit/diagnostics' ;
25import type { DeviceInfo } from '@agent-device/kernel/device' ;
36import { createRequestCanceledError } from '@agent-device/kernel/errors' ;
47
@@ -11,6 +14,7 @@ vi.mock('./system-surface-presence.ts', () => ({
1114import { areIosSnapshotComparisonIdentitiesEqual } from '@agent-device/capture-kit/ios-snapshot-planning' ;
1215import { IOS_SYSTEM_SURFACE_HOSTS } from '@agent-device/contracts/ios-system-surface' ;
1316import { simulatorAddressFor } from './core/simctl.ts' ;
17+ import { mkdtempForTest } from './__tests__/tmp-dir.ts' ;
1418import { createLocalAppleToolProvider , withAppleToolProvider } from './core/tool-provider.ts' ;
1519import { platformRuntimeHostFixture } from './runtime.fixtures.ts' ;
1620import { createAppleSnapshotRoute } from './snapshot-route.ts' ;
@@ -285,8 +289,28 @@ test('typed bridge failure falls back once and disables retries for that app gen
285289 resolveTarget : vi . fn ( async ( ) => target ) ,
286290 } ) ;
287291
288- const first = await route . capture ( ios , input , signal ( ) , fallback ) ;
289- const second = await route . capture ( ios , input , signal ( ) , fallback ) ;
292+ const logPath = path . join ( await mkdtempForTest ( 'ios-route-' ) , 'request.ndjson' ) ;
293+ const [ first , second ] = await withDiagnosticsScope (
294+ { command : 'snapshot' , debug : true , logPath } ,
295+ async ( ) => {
296+ const first = await route . capture ( ios , input , signal ( ) , fallback ) ;
297+ const second = await route . capture ( ios , input , signal ( ) , fallback ) ;
298+ return [ first , second ] as const ;
299+ } ,
300+ ) ;
301+
302+ expect (
303+ fs
304+ . readFileSync ( logPath , 'utf8' )
305+ . trim ( )
306+ . split ( '\n' )
307+ . map ( ( line ) => JSON . parse ( line ) )
308+ . filter ( ( event ) => event . phase === 'ios_snapshot_route_fallback' )
309+ . map ( ( event ) => event . data ) ,
310+ ) . toEqual ( [
311+ { reason : 'bridge-disconnected' , deviceId : ios . id , generation : target . generation } ,
312+ { reason : 'circuit-disabled' , deviceId : ios . id , generation : target . generation } ,
313+ ] ) ;
290314
291315 expect ( source . acquire ) . toHaveBeenCalledOnce ( ) ;
292316 expect ( fallback ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments