Files
callstack__agent-device/packages/platform-apple/src/simulator-state.ts
Michał Pierzchała 5855dfc2e0 refactor: route shutdown through device runtime (#1757)
* refactor: route shutdown through device runtime

* fix: cover shutdown cutover review gaps

* fix: propagate shutdown cancellation

* fix: move shutdown mechanics to platform owners

* fix: pass device to shutdown fact fixture

* test: cover shutdown facts in session state fixtures

* test: simplify Android shutdown assertions

* fix: preserve Apple shutdown cancellation
2026-08-16 15:13:08 +02:00

37 lines
1.0 KiB
TypeScript

import type { DeviceInfo } from '@agent-device/kernel/device';
import type { AppleToolHost } from '@agent-device/contracts/platform';
export async function getSimulatorState(
appleTools: AppleToolHost,
device: DeviceInfo,
signal: AbortSignal,
timeoutMs: number,
): Promise<string | null> {
const result = await appleTools.run(
{
tool: 'simctl',
args: simctlArgs(device, ['list', 'devices', '-j']),
allowFailure: true,
timeoutMs,
},
signal,
);
if (result.exitCode !== 0) return null;
try {
const payload = JSON.parse(result.stdout) as {
devices?: Record<string, Array<{ udid: string; state: string }>>;
};
return (
Object.values(payload.devices ?? {})
.flat()
.find(({ udid }) => udid === device.id)?.state ?? null
);
} catch {
return null;
}
}
export function simctlArgs(device: DeviceInfo, args: readonly string[]): string[] {
return device.simulatorSetPath ? ['--set', device.simulatorSetPath, ...args] : [...args];
}