|
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 | + first.run(() => setAppleRunnerHostEnvironment(createLiveTestHostEnvironment())); |
| 18 | + second.run(() => setAppleRunnerHostEnvironment(createLiveTestHostEnvironment())); |
17 | 19 |
|
18 | 20 | first.run(() => { |
19 | 21 | setRunnerLeaseOwnerStateDir(' /state/first '); |
20 | | - runnerRuntimeSlot(SLOT, () => new Map<string, string>()).set('device', 'first'); |
| 22 | + runtimeSlot(SLOT, () => new Map<string, string>()).set('device', 'first'); |
21 | 23 | }); |
22 | 24 | second.run(() => { |
23 | 25 | setRunnerLeaseOwnerStateDir('/state/second'); |
24 | 26 | }); |
25 | 27 |
|
26 | 28 | expect(first.run(() => getRunnerLeaseOwnerStateDir())).toBe('/state/first'); |
27 | 29 | 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); |
| 30 | + expect(first.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).get('device'))).toBe( |
| 31 | + 'first', |
| 32 | + ); |
| 33 | + expect(second.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
32 | 34 | // Nothing leaked into the standalone state the code outside any runtime reads. |
33 | 35 | expect(getRunnerLeaseOwnerStateDir()).toBeUndefined(); |
34 | 36 | }); |
35 | 37 |
|
36 | 38 | test('disposing a runtime drops its registries', () => { |
37 | | - const runtime = createAppleRunnerRuntimeState(createLiveTestHostEnvironment()); |
38 | | - runtime.run(() => runnerRuntimeSlot(SLOT, () => new Map([['device', 'owned']]))); |
| 39 | + const runtime = createRuntimeStateHandle(); |
| 40 | + runtime.run(() => runtimeSlot(SLOT, () => new Map([['device', 'owned']]))); |
39 | 41 |
|
40 | 42 | runtime.dispose(); |
41 | 43 |
|
42 | | - expect(runtime.run(() => runnerRuntimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
| 44 | + expect(runtime.run(() => runtimeSlot(SLOT, () => new Map<string, string>()).size)).toBe(0); |
43 | 45 | }); |
44 | 46 |
|
45 | 47 | // A configuration read outside every composed runtime has no host to answer from; it refuses |
|
0 commit comments