@@ -8,16 +8,11 @@ import {
88 refreshSessionDeviceIfNeeded ,
99 selectorTargetsSessionDevice ,
1010} from '../session-device-resolution.ts' ;
11- import { appleSessionObservation } from '../../platform-runtime-apple-resources.ts' ;
1211import { resolveTargetDevice } from '@agent-device/device-selection/dispatch-resolve' ;
1312import { isActiveProviderDevice } from '../provider-device-admission.ts' ;
1413import { ensureDeviceReady } from '../device/device-ready.ts' ;
1514import { PRE_DISPATCH_REFUSAL_REASONS } from '@agent-device/kernel/errors' ;
1615
17- vi . mock ( '../../platform-runtime-apple-resources.ts' , async ( importOriginal ) => ( {
18- ...( await importOriginal < typeof import ( '../../platform-runtime-apple-resources.ts' ) > ( ) ) ,
19- appleSessionObservation : { observeRunnerSession : vi . fn ( ) } ,
20- } ) ) ;
2116vi . mock ( '@agent-device/device-selection/dispatch-resolve' , ( ) => ( {
2217 resolveTargetDevice : vi . fn ( ) ,
2318} ) ) ;
@@ -28,10 +23,23 @@ vi.mock('../device/device-ready.ts', () => ({
2823 ensureDeviceReady : vi . fn ( async ( ) => { } ) ,
2924} ) ) ;
3025
31- const mockObserveRunnerSession = vi . mocked ( appleSessionObservation . observeRunnerSession ) ;
3226const mockResolveTargetDevice = vi . mocked ( resolveTargetDevice ) ;
3327const mockIsActiveProviderDevice = vi . mocked ( isActiveProviderDevice ) ;
3428const mockEnsureDeviceReady = vi . mocked ( ensureDeviceReady ) ;
29+ const mockObserveRunnerSession = vi . fn ( ) ;
30+
31+ // ADR 0019 section 11: the observation stub crosses the port as a fixture override, never as a
32+ // mock of the platform module behind it.
33+ function platformServicesWithObservation ( ) {
34+ const services = daemonPlatformServicesFixture ( ) ;
35+ return {
36+ ...services ,
37+ appleSessionObservation : {
38+ ...services . appleSessionObservation ,
39+ observeRunnerSession : mockObserveRunnerSession ,
40+ } ,
41+ } ;
42+ }
3543
3644beforeEach ( ( ) => {
3745 mockObserveRunnerSession . mockReset ( ) ;
@@ -68,7 +76,7 @@ async function withMockedPlatform<T>(platform: NodeJS.Platform, fn: () => Promis
6876
6977test ( 'refreshSessionDeviceIfNeeded keeps iOS simulator session device on non-mac hosts' , async ( ) => {
7078 const device = await withMockedPlatform ( 'linux' , async ( ) =>
71- refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , daemonPlatformServicesFixture ( ) ) ,
79+ refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , platformServicesWithObservation ( ) ) ,
7280 ) ;
7381
7482 expect ( device ) . toBe ( iosSimulatorSession . device ) ;
@@ -79,7 +87,7 @@ test('resolveCommandDevice keeps an existing session for a platform-only filter'
7987 'linux' ,
8088 async ( ) =>
8189 await resolveCommandDevice ( {
82- platformServices : daemonPlatformServicesFixture ( ) ,
90+ platformServices : platformServicesWithObservation ( ) ,
8391 session : iosSimulatorSession ,
8492 flags : { platform : 'ios' } ,
8593 } ) ,
@@ -96,7 +104,7 @@ test('resolveCommandDevice does not prepare a sessionless device', async () => {
96104 await resolveCommandDevice ( {
97105 session : undefined ,
98106 flags : { platform : 'ios' } ,
99- platformServices : daemonPlatformServicesFixture ( ) ,
107+ platformServices : platformServicesWithObservation ( ) ,
100108 } ) ;
101109
102110 expect ( mockResolveTargetDevice ) . toHaveBeenCalledOnce ( ) ;
@@ -109,7 +117,7 @@ test('refreshSessionDeviceIfNeeded keeps provider-owned iOS simulators out of lo
109117 const device = await withMockedPlatform ( 'darwin' , async ( ) =>
110118 refreshSessionDeviceIfNeeded (
111119 { ...iosSimulatorSession . device , id : 'limrun:ios:lease-1' } ,
112- daemonPlatformServicesFixture ( ) ,
120+ platformServicesWithObservation ( ) ,
113121 ) ,
114122 ) ;
115123
@@ -124,7 +132,7 @@ test('refreshSessionDeviceIfNeeded skips re-resolve while the iOS runner session
124132 } ) ;
125133
126134 const device = await withMockedPlatform ( 'darwin' , async ( ) =>
127- refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , daemonPlatformServicesFixture ( ) ) ,
135+ refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , platformServicesWithObservation ( ) ) ,
128136 ) ;
129137
130138 expect ( device ) . toEqual ( { ...iosSimulatorSession . device , booted : true } ) ;
@@ -140,7 +148,7 @@ test('refreshSessionDeviceIfNeeded re-resolves when the iOS runner session is go
140148 mockResolveTargetDevice . mockResolvedValue ( resolved ) ;
141149
142150 const device = await withMockedPlatform ( 'darwin' , async ( ) =>
143- refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , daemonPlatformServicesFixture ( ) ) ,
151+ refreshSessionDeviceIfNeeded ( iosSimulatorSession . device , platformServicesWithObservation ( ) ) ,
144152 ) ;
145153
146154 expect ( device ) . toBe ( resolved ) ;
0 commit comments