|
1 | 1 | import { expect, test } from 'vitest'; |
2 | 2 | import { createLiveTestHostEnvironment } from '@agent-device/test-kit'; |
3 | 3 | import { AppError } from '@agent-device/kernel/errors'; |
| 4 | +import { createRuntimeStateHandle, runtimeSlot } from '@agent-device/host-kit/runtime-slots'; |
4 | 5 | import { appleRunnerHost } from './runner-host.ts'; |
5 | 6 | import { |
6 | | - createAppleRunnerRuntimeState, |
7 | 7 | getRunnerLeaseOwnerStateDir, |
8 | | - runnerRuntimeSlot, |
| 8 | + setAppleRunnerHostEnvironment, |
9 | 9 | setRunnerLeaseOwnerStateDir, |
10 | 10 | } from './runner-owner-state.ts'; |
11 | 11 |
|
12 | 12 | const SLOT = Symbol('test-slot'); |
13 | 13 |
|
14 | 14 | test('each runtime keeps its own owner state and registries', () => { |
15 | | - const first = createAppleRunnerRuntimeState(createLiveTestHostEnvironment()); |
16 | | - const second = createAppleRunnerRuntimeState(createLiveTestHostEnvironment()); |
| 15 | + const first = createRuntimeStateHandle(); |
| 16 | + const second = createRuntimeStateHandle(); |
| 17 | + const firstHost = createLiveTestHostEnvironment(); |
| 18 | + const secondHost = createLiveTestHostEnvironment(); |
| 19 | + first.run(() => setAppleRunnerHostEnvironment(firstHost)); |
| 20 | + second.run(() => setAppleRunnerHostEnvironment(secondHost)); |
17 | 21 |
|
18 | 22 | first.run(() => { |
19 | 23 | setRunnerLeaseOwnerStateDir(' /state/first '); |
20 | | - runnerRuntimeSlot(SLOT, () => new Map<string, string>()).set('device', 'first'); |
| 24 | + runtimeSlot(SLOT, () => new Map<string, string>()).set('device', 'first'); |
21 | 25 | }); |
22 | 26 | second.run(() => { |
23 | 27 | setRunnerLeaseOwnerStateDir('/state/second'); |
24 | 28 | }); |
25 | 29 |
|
26 | 30 | expect(first.run(() => getRunnerLeaseOwnerStateDir())).toBe('/state/first'); |
27 | 31 | expect(second.run(() => getRunnerLeaseOwnerStateDir())).toBe('/state/second'); |
28 | | - expect( |
29 | | - first.run(() => runnerRuntimeSlot(SLOT, () => new Map<string, string>()).get('device')), |
30 | | - ).toBe('first'); |
31 | | - expect(second.run(() => runnerRuntimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
| 32 | + // Each runtime's runner host port answers from the host bound in that runtime, never the other's. |
| 33 | + expect(first.run(() => appleRunnerHost.hostEnvironment())).toBe(firstHost); |
| 34 | + expect(second.run(() => appleRunnerHost.hostEnvironment())).toBe(secondHost); |
| 35 | + expect(first.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).get('device'))).toBe( |
| 36 | + 'first', |
| 37 | + ); |
| 38 | + expect(second.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
32 | 39 | // Nothing leaked into the standalone state the code outside any runtime reads. |
33 | 40 | expect(getRunnerLeaseOwnerStateDir()).toBeUndefined(); |
34 | 41 | }); |
35 | 42 |
|
36 | 43 | test('disposing a runtime drops its registries', () => { |
37 | | - const runtime = createAppleRunnerRuntimeState(createLiveTestHostEnvironment()); |
38 | | - runtime.run(() => runnerRuntimeSlot(SLOT, () => new Map([['device', 'owned']]))); |
| 44 | + const runtime = createRuntimeStateHandle(); |
| 45 | + runtime.run(() => runtimeSlot(SLOT, () => new Map([['device', 'owned']]))); |
39 | 46 |
|
40 | 47 | runtime.dispose(); |
41 | 48 |
|
42 | | - expect(runtime.run(() => runnerRuntimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
| 49 | + expect(runtime.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
43 | 50 | }); |
44 | 51 |
|
45 | 52 | // A configuration read outside every composed runtime has no host to answer from; it refuses |
|
0 commit comments