Skip to content

Commit d48788c

Browse files
committed
refactor: route boot through readiness runtime
1 parent 73b54c1 commit d48788c

68 files changed

Lines changed: 1250 additions & 530 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.

‎packages/capture-kit/src/app-log-pid-runtime.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export function createPidScopedAppLogRuntimeOwner<
106106
return Object.freeze({
107107
owner,
108108
ownsDevice: (device) => device.platform === options.family,
109+
inspectFacts: async (device) => {
110+
const transport = await host.processTransports.resolve(device);
111+
return createFacts(device, transport, options);
112+
},
109113
bind: async (request) => {
110114
if (request.intent.kind === 'exact-owner' && !sameRuntimeOwner(request.intent.owner, owner)) {
111115
throw new AppError(

‎packages/capture-kit/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export {
2828
} from './app-log-session-artifacts.ts';
2929
export {
3030
createUnavailablePlatformRuntimeBinding,
31+
createUnavailablePlatformRuntimeFacts,
3132
createUnavailablePlatformRuntimeOwner,
3233
} from './platform-runtime-unavailable.ts';
3334
export { mergeNetworkDumps, readRecentNetworkTrafficFromText } from './network-traffic.ts';

‎packages/capture-kit/src/platform-runtime-unavailable.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ test('builds one complete combined unavailable owner without fake operations', a
3333
'appLogInspect',
3434
'appLogReattach',
3535
'appLogStart',
36+
'ensureReady',
37+
'ensureReadyHeadless',
3638
'networkDump',
3739
'screenRecordingCleanup',
3840
'screenRecordingReattach',

‎packages/capture-kit/src/platform-runtime-unavailable.ts‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ import {
1111
type RuntimeOwnerRef,
1212
} from '@agent-device/contracts/platform';
1313

14-
type UnavailablePlatformRuntimeFacts = Readonly<{
14+
export type UnavailablePlatformRuntimeFacts = Readonly<{
1515
appLog: RuntimeOperationUnavailability;
1616
network: RuntimeOperationUnavailability;
1717
screenRecording?: RuntimeOperationUnavailability;
18+
readiness?: RuntimeOperationUnavailability;
1819
}>;
1920

2021
type FrozenUnavailablePlatformRuntimeFacts = Readonly<{
2122
appLog: RuntimeOperationUnavailability;
2223
network: RuntimeOperationUnavailability;
2324
screenRecording: RuntimeOperationUnavailability;
25+
readiness: RuntimeOperationUnavailability;
2426
}>;
2527

2628
/** Builds one honest combined owner for a family with no app-log or network mechanics. */
@@ -33,6 +35,7 @@ export function createUnavailablePlatformRuntimeOwner(
3335
return Object.freeze({
3436
owner,
3537
ownsDevice: (device) => device.platform === family,
38+
inspectFacts: async (device) => createUnavailablePlatformRuntimeFacts(device, owner, facts),
3639
bind: async (request) => {
3740
if (request.intent.kind === 'exact-owner' && !sameRuntimeOwner(request.intent.owner, owner)) {
3841
throw new AppError(
@@ -57,8 +60,23 @@ export function createUnavailablePlatformRuntimeBinding(
5760
owner: RuntimeOwnerRef,
5861
unavailable: UnavailablePlatformRuntimeFacts,
5962
): DeviceBinding<PlatformRuntimeOperations> {
60-
const { appLog, network, screenRecording } = freezeUnavailableFacts(unavailable);
61-
const facts: RuntimeFacts<PlatformRuntimeOperations> = Object.freeze({
63+
const facts = createUnavailablePlatformRuntimeFacts(device, owner, unavailable);
64+
return Object.freeze({
65+
device,
66+
owner,
67+
facts,
68+
operations: Object.freeze({}),
69+
[Symbol.asyncDispose]: async () => undefined,
70+
});
71+
}
72+
73+
export function createUnavailablePlatformRuntimeFacts(
74+
device: DeviceInfo,
75+
owner: RuntimeOwnerRef,
76+
unavailable: UnavailablePlatformRuntimeFacts,
77+
): RuntimeFacts<PlatformRuntimeOperations> {
78+
const { appLog, network, screenRecording, readiness } = freezeUnavailableFacts(unavailable);
79+
return Object.freeze({
6280
device: {
6381
...deviceShape(device),
6482
providerMode: owner.kind === 'local-family' ? 'local' : 'provider-runtime',
@@ -73,15 +91,10 @@ export function createUnavailablePlatformRuntimeBinding(
7391
screenRecordingStart: screenRecording,
7492
screenRecordingReattach: screenRecording,
7593
screenRecordingCleanup: screenRecording,
94+
ensureReady: readiness,
95+
ensureReadyHeadless: readiness,
7696
},
7797
});
78-
return Object.freeze({
79-
device,
80-
owner,
81-
facts,
82-
operations: Object.freeze({}),
83-
[Symbol.asyncDispose]: async () => undefined,
84-
});
8598
}
8699

87100
function freezeUnavailableFacts(
@@ -93,5 +106,6 @@ function freezeUnavailableFacts(
93106
screenRecording: Object.freeze({
94107
...(unavailable.screenRecording ?? unavailable.network),
95108
}),
109+
readiness: Object.freeze({ ...(unavailable.readiness ?? unavailable.network) }),
96110
});
97111
}

‎packages/contracts/src/device-inventory.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type DeviceInventoryRequest = {
3131
/** Internal local-inventory projection filters; not public command grammar. */
3232
kind?: DeviceKind;
3333
booted?: boolean;
34+
/** Internal target-resolution policy; ordinary inventory leaves this absent and lists all AVDs. */
35+
androidAvdSelection?: 'running-only' | 'include-stopped';
3436
};
3537

3638
export type ProviderDeviceInventoryRequest = Omit<DeviceInventoryRequest, 'booted' | 'kind'>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { DeviceInfo } from '@agent-device/kernel/device';
2+
3+
export type EnsureReadyInput = Readonly<{
4+
serial?: string;
5+
androidSerialAllowlist?: readonly string[];
6+
}>;
7+
8+
export type DeviceReadinessRuntimeOperations = Readonly<{
9+
ensureReady(input: EnsureReadyInput): Promise<DeviceInfo>;
10+
ensureReadyHeadless(input: EnsureReadyInput): Promise<DeviceInfo>;
11+
}>;
12+
13+
export type DeviceReadinessRuntimeHost = Readonly<{
14+
apple: Readonly<{
15+
ensureReady(
16+
device: DeviceInfo,
17+
options: Readonly<{ onColdBootStart?: () => void }>,
18+
signal: AbortSignal,
19+
): Promise<void>;
20+
keepAutomationReady(device: DeviceInfo): void;
21+
}>;
22+
android: Readonly<{
23+
ensureReady(
24+
device: DeviceInfo,
25+
input: EnsureReadyInput & Readonly<{ headless: boolean }>,
26+
signal: AbortSignal,
27+
): Promise<DeviceInfo>;
28+
}>;
29+
}>;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ export type {
176176
PlatformRuntimeOwner,
177177
PlatformRuntimeProviderModule,
178178
} from '../platform-runtime-operations.ts';
179+
export {
180+
deviceReadinessRuntimeUses,
181+
ensureReadyHeadlessUse,
182+
ensureReadyUse,
183+
} from '../platform-runtime-operations.ts';
184+
export type {
185+
DeviceReadinessRuntimeHost,
186+
DeviceReadinessRuntimeOperations,
187+
EnsureReadyInput,
188+
} from '../device-readiness-runtime.ts';
179189
export {
180190
appLogAdmissionUse,
181191
appLogRuntimePlanUses,

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@ import type { AppLogRuntimeHost, AppLogRuntimeOperations } from './app-log-runti
22
import type { NetworkRuntimeHost, NetworkRuntimeOperations } from './network-runtime.ts';
33
import type { ScreenRecordingRuntimeHost } from './screen-recording-runtime-host.ts';
44
import type { ScreenRecordingRuntimeOperations } from './screen-recording-runtime.ts';
5+
import type {
6+
DeviceReadinessRuntimeHost,
7+
DeviceReadinessRuntimeOperations,
8+
} from './device-readiness-runtime.ts';
59
import type {
610
DeviceRuntimeOwner,
711
RuntimeOwnerRef,
812
RuntimePlatformModule,
913
} from './platform-runtime.ts';
14+
import { runtimeUse } from './platform-runtime.ts';
1015

1116
export type PlatformRuntimeOperations = AppLogRuntimeOperations &
1217
NetworkRuntimeOperations &
13-
ScreenRecordingRuntimeOperations;
18+
ScreenRecordingRuntimeOperations &
19+
DeviceReadinessRuntimeOperations;
20+
21+
const defineReadinessUse = runtimeUse<PlatformRuntimeOperations>();
22+
23+
export const ensureReadyUse = defineReadinessUse({ required: ['ensureReady'] });
24+
export const ensureReadyHeadlessUse = defineReadinessUse({
25+
required: ['ensureReadyHeadless'],
26+
});
27+
export const deviceReadinessRuntimeUses = Object.freeze([
28+
ensureReadyUse,
29+
ensureReadyHeadlessUse,
30+
] as const);
1431

1532
export type PlatformRuntimeHost = AppLogRuntimeHost &
1633
NetworkRuntimeHost &
17-
Readonly<{ screenRecording: ScreenRecordingRuntimeHost }>;
34+
Readonly<{
35+
screenRecording: ScreenRecordingRuntimeHost;
36+
deviceReadiness: DeviceReadinessRuntimeHost;
37+
}>;
1838

1939
export type PlatformRuntimeOwner = DeviceRuntimeOwner<PlatformRuntimeOperations>;
2040

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export type DeviceBindingRequest = Readonly<{
180180

181181
/** Provider-first request gateway. Ordinary and exact-owner selection stay inside this module. */
182182
export type DeviceRuntimeGateway<Operations extends object> = Readonly<{
183+
inspectFacts(device: DeviceInfo): Promise<RuntimeFacts<Operations>>;
183184
bind(request: DeviceBindingRequest): Promise<DeviceBinding<Operations>>;
184185
shutdown(): Promise<void>;
185186
}>;

‎packages/kernel/src/device.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export type DeviceSelector = {
7070

7171
type DeviceSelectionContext = {
7272
simulatorSetPath?: string;
73-
allowStoppedAndroidAvdPlaceholders?: boolean;
7473
};
7574

7675
export function isApplePlatform(
@@ -268,10 +267,6 @@ export async function resolveDevice(
268267
const explicitlySelected = resolveExplicitDevice(candidates, selector);
269268
if (explicitlySelected) return explicitlySelected;
270269

271-
if (context.allowStoppedAndroidAvdPlaceholders !== true) {
272-
candidates = candidates.filter((device) => !isStoppedAndroidAvdPlaceholder(device));
273-
}
274-
275270
const namedDevice = resolveDeviceByName(candidates, selector.deviceName);
276271
if (namedDevice) return namedDevice;
277272

@@ -344,15 +339,6 @@ function selectPreferredDevice(candidates: DeviceInfo[]): DeviceInfo | undefined
344339
return booted[0] ?? selectable[0];
345340
}
346341

347-
function isStoppedAndroidAvdPlaceholder(device: DeviceInfo): boolean {
348-
return (
349-
device.platform === 'android' &&
350-
device.kind === 'emulator' &&
351-
device.booted === false &&
352-
!/^emulator-\d+$/.test(device.id)
353-
);
354-
}
355-
356342
export function matchesDeviceSelector(
357343
device: DeviceInfo,
358344
selector: DeviceSelector,

0 commit comments

Comments
 (0)