Skip to content

Commit d8a7d03

Browse files
authored
refactor: route application lifecycle through runtime facts (#1759)
* refactor: route application lifecycle through runtime facts Moves the canonical `open`, `prepare`, `close` and internal `runtime` descriptors behind package-owned lifecycle bindings admitted from device runtime facts, while daemon request/session policy and public response construction stay put. Based on main, which already carries the boot unit, the parametrized cutover gate and the apps unit. Readiness is package-owned there, so the Apple and Android bindings call ensureAppleReady/ensureAndroidReady rather than a root readiness bag; ensureAppleReady gained an onColdBootStart hook so open keeps warming the runner cache in parallel with a cold boot, and a narrow markBooted port publishes readiness' fresh observation so a flow still makes one simctl listing. Cutover rows take R24-R27, clear of the accepted catalog and the sibling install stack, and cutoverTableDefects rejects a duplicate rule id. Two defects this unit introduced are fixed here rather than shipped: `open <app> <url>` dropped the URL on a first open, and test-IME activation was first fatal on an unobtainable helper and then over-caught. Helper unavailability is a typed non-activation outcome now; fence, lock and post-record failures propagate. The duplication the unit had accumulated is gone: one runtime-admission module instead of five per-command copies, one direct-lifecycle binding factory instead of six hand-rolled packages, one transport-hint predicate, one session finalization path, and no identity-wrapper module. * fix: allocate lifecycle cutover rows after deployment * chore: preserve lifecycle union reconstruction * fix: reconcile lifecycle runtime stack * refactor: tighten lifecycle runtime topology * refactor: remove superseded runtime adapters * fix: preserve stacked runtime cutovers * test: preserve migrated runtime ownership * test: move Android deployment retry ownership * test: extract runtime hint fixtures * fix: preserve lifecycle stack invariants * fix: complete lifecycle runtime cutover * fix: remove lifecycle cutover residue
1 parent 66cca1a commit d8a7d03

213 files changed

Lines changed: 14608 additions & 6956 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { expect, test } from 'vitest';
2+
import type { DeviceInfo } from '@agent-device/kernel/device';
3+
import type { Interactor } from './interactor-types.ts';
4+
import type { OpenApplicationInput } from './application-lifecycle-runtime.ts';
5+
import {
6+
bindDirectApplicationLifecycle,
7+
bindLocalApplicationLifecycleInteractor,
8+
invokeApplicationOpen,
9+
} from './application-lifecycle-interaction.ts';
10+
11+
const IOS_SIMULATOR: DeviceInfo = {
12+
platform: 'apple',
13+
appleOs: 'ios',
14+
id: 'ios-simulator',
15+
name: 'iPhone',
16+
kind: 'simulator',
17+
booted: true,
18+
};
19+
20+
const LINUX_DEVICE: DeviceInfo = {
21+
platform: 'linux',
22+
id: 'linux-local',
23+
name: 'Linux',
24+
kind: 'device',
25+
booted: true,
26+
};
27+
28+
const WEB_DEVICE: DeviceInfo = {
29+
platform: 'web',
30+
id: 'web-local',
31+
name: 'Browser',
32+
kind: 'device',
33+
booted: true,
34+
};
35+
36+
function interactorWithOpen(open: Interactor['open'] = async () => undefined): Interactor {
37+
return {
38+
open,
39+
openDevice: async () => undefined,
40+
close: async () => undefined,
41+
setSetting: async () => undefined,
42+
} as unknown as Interactor;
43+
}
44+
45+
function openInput(overrides: Partial<OpenApplicationInput> = {}): OpenApplicationInput {
46+
return {
47+
target: 'com.example.app',
48+
positionals: ['com.example.app'],
49+
appBundleId: 'com.example.app',
50+
surface: 'app',
51+
hasExistingSession: false,
52+
relaunch: false,
53+
prewarmRunnerBeforeOpen: false,
54+
enableTestIme: false,
55+
stateDir: '/state',
56+
runtimeHints: {},
57+
execution: {},
58+
...overrides,
59+
};
60+
}
61+
62+
test('direct lifecycle owners preserve the daemon runtime launch URL follow-up', async () => {
63+
const calls: Array<{ app: string; options: unknown }> = [];
64+
const interactor = interactorWithOpen(async (app, options) => {
65+
calls.push({ app, options });
66+
});
67+
const binding = bindLocalApplicationLifecycleInteractor({
68+
device: WEB_DEVICE,
69+
signal: new AbortController().signal,
70+
resolveInteractor: async () => interactor,
71+
});
72+
const lifecycle = bindDirectApplicationLifecycle({
73+
binding,
74+
owner: 'Linux',
75+
openTargetIdentity: 'app-name',
76+
});
77+
78+
await lifecycle.openApplication(
79+
openInput({
80+
runtimeLaunchUrl: 'example://after-open',
81+
execution: { clearAppState: true, launchArgs: ['--first-launch'] },
82+
}),
83+
);
84+
85+
expect(calls.map(({ app }) => app)).toEqual(['com.example.app', 'example://after-open']);
86+
expect(calls[0]?.options).toMatchObject({
87+
appBundleId: 'com.example.app',
88+
launchArgs: ['--first-launch'],
89+
});
90+
expect(calls[1]?.options).toMatchObject({ appBundleId: 'com.example.app' });
91+
expect(calls[1]?.options).toHaveProperty('launchArgs', undefined);
92+
});
93+
94+
test.each([
95+
{
96+
name: 'more than two positionals',
97+
device: IOS_SIMULATOR,
98+
positionals: ['com.example.app', 'example://one', 'example://two'],
99+
execution: {},
100+
message: /at most two arguments/,
101+
},
102+
{
103+
name: 'launch console without an app',
104+
device: IOS_SIMULATOR,
105+
positionals: [],
106+
execution: { launchConsole: 'stdout' },
107+
message: /launch-console requires an app target/,
108+
},
109+
{
110+
name: 'launch arguments without an app',
111+
device: IOS_SIMULATOR,
112+
positionals: [],
113+
execution: { launchArgs: ['--flag'] },
114+
message: /launch-args requires an app target/,
115+
},
116+
{
117+
name: 'launch console outside an iOS simulator',
118+
device: LINUX_DEVICE,
119+
positionals: ['org.example.App'],
120+
execution: { launchConsole: 'stdout' },
121+
message: /iOS simulator/i,
122+
},
123+
{
124+
name: 'launch arguments on Linux',
125+
device: LINUX_DEVICE,
126+
positionals: ['org.example.App'],
127+
execution: { launchArgs: ['--flag'] },
128+
message: /not supported on Linux/,
129+
},
130+
{
131+
name: 'a URL in the app position when a second URL is present',
132+
device: IOS_SIMULATOR,
133+
positionals: ['example://first', 'example://second'],
134+
execution: {},
135+
message: /requires an app target as the first argument/,
136+
},
137+
{
138+
name: 'an invalid second URL',
139+
device: IOS_SIMULATOR,
140+
positionals: ['com.example.app', 'not-a-url'],
141+
execution: {},
142+
message: /requires a valid URL target/,
143+
},
144+
{
145+
name: 'launch console with a direct URL pair',
146+
device: IOS_SIMULATOR,
147+
positionals: ['com.example.app', 'example://home'],
148+
execution: { launchConsole: 'stdout' },
149+
message: /direct app/i,
150+
},
151+
{
152+
name: 'clear app state with a deep-link target',
153+
device: IOS_SIMULATOR,
154+
positionals: ['example://home'],
155+
execution: { clearAppState: true },
156+
message: /requires an app target, not a deep link/,
157+
},
158+
])('rejects invalid open input: $name', async ({ device, positionals, execution, message }) => {
159+
await expect(
160+
invokeApplicationOpen({
161+
device,
162+
interactor: interactorWithOpen(),
163+
positionals,
164+
execution,
165+
}),
166+
).rejects.toThrow(message);
167+
});

0 commit comments

Comments
 (0)