@@ -10,7 +10,8 @@ import {
1010 createTestHostEnvironment ,
1111} from '@agent-device/test-kit' ;
1212import { createDaemonRuntimeDeps } from './daemon-composition.ts' ;
13- import { helperRuntimeSlot } from '@agent-device/platform-android/adb-host' ;
13+ import { createRuntimeStateHandle , runtimeSlot } from '@agent-device/host-kit/runtime-slots' ;
14+ import { getAppleRunnerHostEnvironment } from '@agent-device/platform-apple/runner-owner' ;
1415import { setActiveProviderDeviceRuntimes } from './provider-device-runtime.ts' ;
1516
1617const ports = vi . hoisted ( ( ) => ( {
@@ -126,13 +127,14 @@ test('a composition that succeeds leaves the plugins open for the daemon to clos
126127 expect ( ports . shutdownProviders ) . toHaveBeenCalledOnce ( ) ;
127128} ) ;
128129
129- test ( 'a composed daemon registers the Apple runner and Android helper state, one set per composition ' , async ( ) => {
130+ test ( 'each composition binds its own runtime state into the entered handle, not a returned one ' , async ( ) => {
130131 const compose = async ( name : string ) => {
131132 const baseDir = mkdtempForTestSync ( `agent-device-daemon-composition-states-${ name } -` ) ;
132- return await createDaemonRuntimeDeps ( {
133- host : createTestHostEnvironment ( {
134- env : { ...process . env , AGENT_DEVICE_STATE_DIR : baseDir } ,
135- } ) ,
133+ const host = createTestHostEnvironment ( {
134+ env : { ...process . env , AGENT_DEVICE_STATE_DIR : baseDir } ,
135+ } ) ;
136+ const deps = await createDaemonRuntimeDeps ( {
137+ host,
136138 baseDir,
137139 sessionsDir : `${ baseDir } /sessions` ,
138140 assertShutdownAllowed : undefined ,
@@ -142,21 +144,30 @@ test('a composed daemon registers the Apple runner and Android helper state, one
142144 } ,
143145 openWebSessionNames : ( ) => [ ] ,
144146 } ) ;
147+ return { deps, host } ;
145148 } ;
146- const first = await compose ( 'first' ) ;
147- const second = await compose ( 'second' ) ;
148149 const slotKey = Symbol ( 'composition-test' ) ;
149150
150- // Apple's runner state and Android's helper state.
151- expect ( first . runtimeStates ) . toHaveLength ( 2 ) ;
152- expect ( second . runtimeStates ) . toHaveLength ( 2 ) ;
153- // The Android handle scopes the slots the helper modules read.
154- const [ , firstAndroid ] = first . runtimeStates ;
155- const [ , secondAndroid ] = second . runtimeStates ;
156- const inFirst = firstAndroid ! . run ( ( ) => helperRuntimeSlot ( slotKey , ( ) => ( { } ) ) ) ;
157- const inSecond = secondAndroid ! . run ( ( ) => helperRuntimeSlot ( slotKey , ( ) => ( { } ) ) ) ;
151+ // One entered store per runtime (#3794): the daemon enters the handle, then composes into it,
152+ // so each composition's writes — the Apple runner host, and any slot a platform module declares
153+ // — land in that runtime's state and nowhere else.
154+ const first = createRuntimeStateHandle ( ) ;
155+ const second = createRuntimeStateHandle ( ) ;
156+ const firstRun = await first . run ( ( ) => compose ( 'first' ) ) ;
157+ const secondRun = await second . run ( ( ) => compose ( 'second' ) ) ;
158+ expect ( firstRun . deps ) . toBeTypeOf ( 'object' ) ;
159+ expect ( secondRun . deps ) . toBeTypeOf ( 'object' ) ;
160+
161+ const inFirst = first . run ( ( ) => runtimeSlot ( slotKey , ( ) => ( { } ) ) ) ;
162+ const inSecond = second . run ( ( ) => runtimeSlot ( slotKey , ( ) => ( { } ) ) ) ;
158163 expect ( inFirst ) . not . toBe ( inSecond ) ;
159- expect ( firstAndroid ! . run ( ( ) => helperRuntimeSlot ( slotKey , ( ) => ( { } ) ) ) ) . toBe ( inFirst ) ;
164+ expect ( first . run ( ( ) => runtimeSlot ( slotKey , ( ) => ( { } ) ) ) ) . toBe ( inFirst ) ;
165+ expect ( first . run ( getAppleRunnerHostEnvironment ) ) . toBe ( firstRun . host ) ;
166+ expect ( second . run ( getAppleRunnerHostEnvironment ) ) . toBe ( secondRun . host ) ;
167+ // One runtime's host is not the other's: composition entered state, it did not return a handle.
168+ expect ( first . run ( getAppleRunnerHostEnvironment ) ) . not . toBe (
169+ second . run ( getAppleRunnerHostEnvironment ) ,
170+ ) ;
160171} ) ;
161172
162173test ( 'the composed daemon route configures interactors from its host, not from the process (#3794)' , async ( ) => {
0 commit comments