Skip to content

Commit e5a717f

Browse files
committed
refactor: deepen install deployment runtime ownership
1 parent be45ac1 commit e5a717f

53 files changed

Lines changed: 1423 additions & 963 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/contracts/src/app-deployment-runtime.ts‎

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,45 +59,61 @@ export type AppDeploymentRuntimeOperations = Readonly<{
5959
}>;
6060

6161
/**
62-
* Focused native-mechanics bridge. Packages own deploy/redeploy/source semantics; composition
63-
* injects only lower-level artifact, device-tool, and provider-transport capabilities that are
64-
* still shared with legacy callers.
62+
* The Apple package owns deployment sequencing. Composition supplies only these native executor
63+
* calls, each scoped to the request binding that initiated it.
6564
*/
66-
export type AppDeploymentRuntimeHost = Readonly<{
67-
apple: Readonly<{
68-
prepareArtifact(
69-
input: MaterializeAppSourceInput,
70-
options: Readonly<{ appIdentifierHint?: string; signal: AbortSignal }>,
71-
): Promise<MaterializedAppSource>;
72-
install(device: DeviceInfo, installablePath: string): Promise<void>;
73-
uninstall(device: DeviceInfo, app: string): Promise<Readonly<{ bundleId: string }>>;
74-
push(device: DeviceInfo, input: PushNotificationInput): Promise<void>;
75-
}>;
76-
android: Readonly<{
77-
/** Low-level boot wait; the Android deployment package decides when it is needed. */
78-
ensureBooted(device: DeviceInfo, signal: AbortSignal): Promise<void>;
79-
/** Brackets one deploy lifecycle so fuzzy target resolution is clear before and after it. */
80-
withInvalidatedAppResolutionCache<Result>(
81-
device: DeviceInfo,
82-
operation: () => Promise<Result>,
83-
): Promise<Result>;
84-
prepareArtifact(
85-
input: MaterializeAppSourceInput,
86-
options: Readonly<{ resolveIdentity?: boolean; signal: AbortSignal }>,
87-
): Promise<MaterializedAppSource>;
88-
install(
89-
device: DeviceInfo,
90-
installablePath: string,
91-
packageNameHint?: string,
92-
): Promise<string | undefined>;
93-
uninstall(device: DeviceInfo, app: string): Promise<Readonly<{ packageName: string }>>;
94-
appName(packageName: string): Promise<string>;
95-
push(device: DeviceInfo, input: PushNotificationInput): Promise<PushNotificationResult>;
96-
}>;
97-
harmonyos: Readonly<{
98-
resolveBundleName(archivePath: string): Promise<string | undefined>;
99-
install(device: DeviceInfo, archivePath: string): Promise<void>;
100-
open(device: DeviceInfo, bundleId: string): Promise<void>;
101-
sleep(milliseconds: number, signal: AbortSignal): Promise<void>;
102-
}>;
65+
export type AppleAppDeploymentExecutor = Readonly<{
66+
prepareArtifact(
67+
input: MaterializeAppSourceInput,
68+
options: Readonly<{ appIdentifierHint?: string; signal: AbortSignal }>,
69+
): Promise<MaterializedAppSource>;
70+
install(device: DeviceInfo, installablePath: string, signal: AbortSignal): Promise<void>;
71+
uninstall(
72+
device: DeviceInfo,
73+
app: string,
74+
signal: AbortSignal,
75+
): Promise<Readonly<{ bundleId: string }>>;
76+
push(device: DeviceInfo, input: PushNotificationInput, signal: AbortSignal): Promise<void>;
77+
}>;
78+
79+
/**
80+
* The Android package owns deployment sequencing and cache lifetime. Composition supplies only
81+
* concrete ADB/artifact executor calls.
82+
*/
83+
export type AndroidAppDeploymentExecutor = Readonly<{
84+
/** Low-level boot wait; the Android deployment package decides when it is needed. */
85+
ensureBooted(device: DeviceInfo, signal: AbortSignal): Promise<void>;
86+
/** Brackets one deploy lifecycle so fuzzy target resolution is clear before and after it. */
87+
withInvalidatedAppResolutionCache<Result>(
88+
device: DeviceInfo,
89+
operation: () => Promise<Result>,
90+
): Promise<Result>;
91+
prepareArtifact(
92+
input: MaterializeAppSourceInput,
93+
options: Readonly<{ resolveIdentity?: boolean; signal: AbortSignal }>,
94+
): Promise<MaterializedAppSource>;
95+
install(
96+
device: DeviceInfo,
97+
installablePath: string,
98+
options: Readonly<{ packageNameHint?: string; signal: AbortSignal }>,
99+
): Promise<string | undefined>;
100+
uninstall(
101+
device: DeviceInfo,
102+
app: string,
103+
signal: AbortSignal,
104+
): Promise<Readonly<{ packageName: string }>>;
105+
appName(packageName: string): Promise<string>;
106+
push(
107+
device: DeviceInfo,
108+
input: PushNotificationInput,
109+
signal: AbortSignal,
110+
): Promise<PushNotificationResult>;
111+
}>;
112+
113+
/** The HarmonyOS package owns deployment/relaunch semantics above these HDC executor calls. */
114+
export type HarmonyAppDeploymentExecutor = Readonly<{
115+
resolveBundleName(archivePath: string): Promise<string | undefined>;
116+
install(device: DeviceInfo, archivePath: string, signal: AbortSignal): Promise<void>;
117+
open(device: DeviceInfo, bundleId: string, signal: AbortSignal): Promise<void>;
118+
sleep(milliseconds: number, signal: AbortSignal): Promise<void>;
103119
}>;

‎packages/contracts/src/facades/platform.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ export {
3434
} from '../audio-probe-support.ts';
3535
export type { PlatformPlugin } from '../platform-plugin.ts';
3636
export type {
37+
AndroidAppDeploymentExecutor,
3738
AppDeploymentInput,
3839
AppDeploymentResult,
39-
AppDeploymentRuntimeHost,
4040
AppDeploymentRuntimeOperations,
4141
AppDeploymentSource,
42+
AppleAppDeploymentExecutor,
4243
DeployMaterializedAppInput,
44+
HarmonyAppDeploymentExecutor,
4345
MaterializedAppSource,
4446
MaterializeAppSourceInput,
4547
PushNotificationInput,

‎packages/contracts/src/platform-runtime-operations.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { AppLogRuntimeHost, AppLogRuntimeOperations } from './app-log-runtime.ts';
22
import type {
3-
AppDeploymentRuntimeHost,
3+
AndroidAppDeploymentExecutor,
44
AppDeploymentRuntimeOperations,
5+
AppleAppDeploymentExecutor,
6+
HarmonyAppDeploymentExecutor,
57
} from './app-deployment-runtime.ts';
68
import type { NetworkRuntimeHost, NetworkRuntimeOperations } from './network-runtime.ts';
79
import type { ScreenRecordingRuntimeHost } from './screen-recording-runtime-host.ts';
@@ -72,7 +74,10 @@ export function resolveDeviceReadinessRuntimePlan(
7274
export type PlatformRuntimeHost = AppLogRuntimeHost &
7375
NetworkRuntimeHost &
7476
Readonly<{
75-
appDeployment: AppDeploymentRuntimeHost;
77+
/** Focused native ports; deployment semantics remain in the owning family packages. */
78+
appleDeployment: AppleAppDeploymentExecutor;
79+
androidDeployment: AndroidAppDeploymentExecutor;
80+
harmonyDeployment: HarmonyAppDeploymentExecutor;
7681
screenRecording: ScreenRecordingRuntimeHost;
7782
deviceReadiness: DeviceReadinessRuntimeHost;
7883
}>;

‎packages/contracts/src/platform-runtime.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
sameRuntimeOwner,
1111
type BoundDeviceRuntime,
1212
type DeviceBinding,
13-
} from './platform-runtime.ts';
13+
} from './facades/platform.ts';
1414

1515
type TestOperations = {
1616
inspect: (input: Readonly<{ depth: number }>) => Promise<Readonly<{ nodes: number }>>;

‎packages/platform-android/src/deployment/runtime.test.ts‎

Lines changed: 66 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, vi } from 'vitest';
2-
import type { AppDeploymentRuntimeHost } from '@agent-device/contracts/platform';
2+
import type { AndroidAppDeploymentExecutor } from '@agent-device/contracts/platform';
33
import type { DeviceInfo } from '@agent-device/kernel/device';
44
import { androidAppDeploymentFacts, createAndroidAppDeploymentOperations } from './runtime.ts';
55

@@ -46,21 +46,20 @@ test('exposes all Android deployment operations only for admitted kinds', async
4646
const uninstall = vi.fn(async () => ({ packageName: 'com.example.replaced' }));
4747
const appName = vi.fn(async () => 'Example');
4848
const push = vi.fn(async () => ({ action: 'com.example.app.TEST_PUSH', extrasCount: 0 }));
49-
const host = {
50-
android: {
51-
ensureBooted,
52-
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
53-
prepareArtifact,
54-
install,
55-
uninstall,
56-
appName,
57-
push,
58-
},
59-
} as unknown as AppDeploymentRuntimeHost;
49+
const executor = {
50+
ensureBooted,
51+
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
52+
prepareArtifact,
53+
install,
54+
uninstall,
55+
appName,
56+
push,
57+
} as AndroidAppDeploymentExecutor;
58+
const signal = new AbortController().signal;
6059
const operations = createAndroidAppDeploymentOperations({
61-
host,
60+
executor,
6261
device,
63-
signal: new AbortController().signal,
62+
signal,
6463
});
6564

6665
await operations.deployApp?.({ app: '', appPath: '/tmp/app.apk', replaceExisting: false });
@@ -81,6 +80,12 @@ test('exposes all Android deployment operations only for admitted kinds', async
8180
expect(appName).toHaveBeenCalledTimes(2);
8281
expect(push).toHaveBeenCalledOnce();
8382
expect(cleanup).toHaveBeenCalledTimes(2);
83+
expect(uninstall).toHaveBeenCalledWith(device, 'com.example.replaced', signal);
84+
expect(install).toHaveBeenCalledWith(device, '/tmp/app.apk', {
85+
packageNameHint: 'com.example.app',
86+
signal,
87+
});
88+
expect(push).toHaveBeenCalledWith(device, { appId: 'com.example.app', payload: {} }, signal);
8489
expect(prepareArtifact).toHaveBeenNthCalledWith(
8590
1,
8691
{ source: { kind: 'path', path: '/tmp/app.apk' } },
@@ -93,7 +98,7 @@ test('exposes all Android deployment operations only for admitted kinds', async
9398
);
9499
expect(
95100
createAndroidAppDeploymentOperations({
96-
host,
101+
executor,
97102
device: { ...device, kind: 'simulator' },
98103
signal: new AbortController().signal,
99104
}),
@@ -113,20 +118,18 @@ test('preserves the pre-install Android boot wait before artifact identity inspe
113118
cleanup: async () => {},
114119
};
115120
});
116-
const host = {
117-
android: {
118-
ensureBooted,
119-
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
120-
prepareArtifact,
121-
install: async () => 'com.example.app',
122-
uninstall: async () => ({ packageName: 'com.example.app' }),
123-
appName: async () => 'Example',
124-
push: async () => ({}),
125-
},
126-
} as unknown as AppDeploymentRuntimeHost;
121+
const executor = {
122+
ensureBooted,
123+
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
124+
prepareArtifact,
125+
install: async () => 'com.example.app',
126+
uninstall: async () => ({ packageName: 'com.example.app' }),
127+
appName: async () => 'Example',
128+
push: async () => ({}),
129+
} as AndroidAppDeploymentExecutor;
127130
const signal = new AbortController().signal;
128131
const operations = createAndroidAppDeploymentOperations({
129-
host,
132+
executor,
130133
device: { ...device, booted: false },
131134
signal,
132135
});
@@ -151,19 +154,17 @@ test('preserves Android reinstall partial-failure ordering', async () => {
151154
order.push('install');
152155
return 'com.example.replaced';
153156
});
154-
const host = {
155-
android: {
156-
ensureBooted: async () => {},
157-
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
158-
prepareArtifact,
159-
install,
160-
uninstall,
161-
appName: async () => 'Example',
162-
push: async () => ({}),
163-
},
164-
} as unknown as AppDeploymentRuntimeHost;
157+
const executor = {
158+
ensureBooted: async () => {},
159+
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
160+
prepareArtifact,
161+
install,
162+
uninstall,
163+
appName: async () => 'Example',
164+
push: async () => ({}),
165+
} as AndroidAppDeploymentExecutor;
165166
const operations = createAndroidAppDeploymentOperations({
166-
host,
167+
executor,
167168
device,
168169
signal: new AbortController().signal,
169170
});
@@ -208,22 +209,20 @@ test('clears cached fuzzy Android resolution before and after the whole reinstal
208209
cachedResolutions.set('Maps', 'com.example.replacement');
209210
return 'com.example.current';
210211
});
211-
const host = {
212-
android: {
213-
ensureBooted: async () => {},
214-
prepareArtifact: async () => ({
215-
installablePath: '/tmp/replacement.apk',
216-
cleanup: async () => {},
217-
}),
218-
install,
219-
uninstall,
220-
appName: async () => 'Example',
221-
push: async () => ({}),
222-
withInvalidatedAppResolutionCache,
223-
},
224-
} as unknown as AppDeploymentRuntimeHost;
212+
const executor = {
213+
ensureBooted: async () => {},
214+
prepareArtifact: async () => ({
215+
installablePath: '/tmp/replacement.apk',
216+
cleanup: async () => {},
217+
}),
218+
install,
219+
uninstall,
220+
appName: async () => 'Example',
221+
push: async () => ({}),
222+
withInvalidatedAppResolutionCache,
223+
} as AndroidAppDeploymentExecutor;
225224
const operations = createAndroidAppDeploymentOperations({
226-
host,
225+
executor,
227226
device,
228227
signal: new AbortController().signal,
229228
});
@@ -243,22 +242,20 @@ test('clears cached fuzzy Android resolution before and after the whole reinstal
243242

244243
test('keeps ordinary Android install successful when identity is unavailable', async () => {
245244
const appName = vi.fn(async () => 'should not be called');
246-
const host = {
247-
android: {
248-
ensureBooted: async () => {},
249-
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
250-
prepareArtifact: async () => ({
251-
installablePath: '/tmp/app.apk',
252-
cleanup: async () => {},
253-
}),
254-
install: async () => undefined,
255-
uninstall: async () => ({ packageName: 'com.example.app' }),
256-
appName,
257-
push: async () => ({}),
258-
},
259-
} as unknown as AppDeploymentRuntimeHost;
245+
const executor = {
246+
ensureBooted: async () => {},
247+
withInvalidatedAppResolutionCache: withoutInvalidatingAppResolutionCache,
248+
prepareArtifact: async () => ({
249+
installablePath: '/tmp/app.apk',
250+
cleanup: async () => {},
251+
}),
252+
install: async () => undefined,
253+
uninstall: async () => ({ packageName: 'com.example.app' }),
254+
appName,
255+
push: async () => ({}),
256+
} as AndroidAppDeploymentExecutor;
260257
const operations = createAndroidAppDeploymentOperations({
261-
host,
258+
executor,
262259
device,
263260
signal: new AbortController().signal,
264261
});

0 commit comments

Comments
 (0)