|
1 | | -import { |
2 | | - commandDeveloperDir, |
3 | | - isCommandTimeoutError, |
4 | | - requireExecSuccess, |
5 | | - runCmd, |
6 | | - runCmdBackground, |
7 | | - runCmdStreaming, |
8 | | -} from '@agent-device/host-kit/command'; |
9 | | -import { emitDiagnostic, withDiagnosticTimer } from '@agent-device/host-kit/diagnostics'; |
10 | | -import { acquireProcessLock, publishFileSync, withProcessLock } from '@agent-device/host-kit/file'; |
11 | | -import { |
12 | | - classifyOwnerLiveness, |
13 | | - isProcessAlive, |
14 | | - isProcessGroupAlive, |
15 | | - readHostCpuArchSync, |
16 | | - readProcessCommand, |
17 | | - readProcessStartTime, |
18 | | - signalPidsBestEffort, |
19 | | - signalProcessGroupBestEffort, |
20 | | -} from '@agent-device/host-kit/process'; |
21 | | -import { |
22 | | - emitRequestProgress, |
23 | | - getRequestSignal, |
24 | | - isRequestCanceled, |
25 | | -} from '@agent-device/host-kit/request'; |
26 | | -import { Deadline, isEnvTruthy, retryWithPolicy } from '@agent-device/host-kit/retry'; |
27 | | -import { runtimeSlot } from '@agent-device/host-kit/runtime-slots'; |
28 | | -import { findProjectRoot, readVersion } from '@agent-device/host-kit/version'; |
29 | | - |
30 | 1 | /** |
31 | 2 | * The real host-kit capabilities a package suite takes as its host defaults, under the names the |
32 | 3 | * Apple runner host port uses for them. A suite that must not import host-kit itself (the runner |
33 | 4 | * port is the one place its package reaches host-kit) assembles its host from these and from its own |
34 | 5 | * explicit adapters, so retry, lock, process and request-cancellation semantics stay genuine. |
| 6 | + * |
| 7 | + * Loaded on demand: the test-kit entry is imported by suites that mock host-kit modules, and a static |
| 8 | + * import of every capability would make those mocks incomplete. |
35 | 9 | */ |
36 | | -export const realHostKitCapabilities = { |
37 | | - runCmdStreaming, |
38 | | - runCmdBackground, |
39 | | - requireExecSuccess, |
40 | | - isCommandTimeoutError, |
41 | | - commandDeveloperDir, |
42 | | - emitDiagnostic, |
43 | | - withDiagnosticTimer, |
44 | | - retryWithPolicy, |
45 | | - isEnvTruthy, |
46 | | - deadlineFromTimeoutMs: (timeoutMs: number, nowMs?: number) => |
47 | | - Deadline.fromTimeoutMs(timeoutMs, nowMs), |
48 | | - isProcessAlive, |
49 | | - isProcessGroupAlive, |
50 | | - readProcessStartTime, |
51 | | - readProcessCommand, |
52 | | - signalPidsBestEffort, |
53 | | - signalProcessGroupBestEffort, |
54 | | - classifyOwnerLiveness, |
55 | | - readHostCpuArchSync, |
56 | | - findProjectRoot, |
57 | | - readVersion, |
58 | | - acquireProcessLock, |
59 | | - withProcessLock, |
60 | | - publishFileSync, |
61 | | - emitRequestProgress, |
62 | | - getRequestSignal, |
63 | | - isRequestCanceled, |
64 | | - runnerRuntimeSlot: runtimeSlot, |
65 | | -} as const; |
| 10 | +export async function loadRealHostKitCapabilities() { |
| 11 | + const [command, diagnostics, file, processModule, request, retry, runtimeSlots, version] = |
| 12 | + await Promise.all([ |
| 13 | + import('@agent-device/host-kit/command'), |
| 14 | + import('@agent-device/host-kit/diagnostics'), |
| 15 | + import('@agent-device/host-kit/file'), |
| 16 | + import('@agent-device/host-kit/process'), |
| 17 | + import('@agent-device/host-kit/request'), |
| 18 | + import('@agent-device/host-kit/retry'), |
| 19 | + import('@agent-device/host-kit/runtime-slots'), |
| 20 | + import('@agent-device/host-kit/version'), |
| 21 | + ]); |
| 22 | + return { |
| 23 | + runCmdStreaming: command.runCmdStreaming, |
| 24 | + runCmdBackground: command.runCmdBackground, |
| 25 | + requireExecSuccess: command.requireExecSuccess, |
| 26 | + isCommandTimeoutError: command.isCommandTimeoutError, |
| 27 | + commandDeveloperDir: command.commandDeveloperDir, |
| 28 | + emitDiagnostic: diagnostics.emitDiagnostic, |
| 29 | + withDiagnosticTimer: diagnostics.withDiagnosticTimer, |
| 30 | + retryWithPolicy: retry.retryWithPolicy, |
| 31 | + isEnvTruthy: retry.isEnvTruthy, |
| 32 | + deadlineFromTimeoutMs: (timeoutMs: number, nowMs?: number) => |
| 33 | + retry.Deadline.fromTimeoutMs(timeoutMs, nowMs), |
| 34 | + isProcessAlive: processModule.isProcessAlive, |
| 35 | + isProcessGroupAlive: processModule.isProcessGroupAlive, |
| 36 | + readProcessStartTime: processModule.readProcessStartTime, |
| 37 | + readProcessCommand: processModule.readProcessCommand, |
| 38 | + signalPidsBestEffort: processModule.signalPidsBestEffort, |
| 39 | + signalProcessGroupBestEffort: processModule.signalProcessGroupBestEffort, |
| 40 | + classifyOwnerLiveness: processModule.classifyOwnerLiveness, |
| 41 | + readHostCpuArchSync: processModule.readHostCpuArchSync, |
| 42 | + findProjectRoot: version.findProjectRoot, |
| 43 | + readVersion: version.readVersion, |
| 44 | + acquireProcessLock: file.acquireProcessLock, |
| 45 | + withProcessLock: file.withProcessLock, |
| 46 | + publishFileSync: file.publishFileSync, |
| 47 | + emitRequestProgress: request.emitRequestProgress, |
| 48 | + getRequestSignal: request.getRequestSignal, |
| 49 | + isRequestCanceled: request.isRequestCanceled, |
| 50 | + runnerRuntimeSlot: runtimeSlots.runtimeSlot, |
| 51 | + } as const; |
| 52 | +} |
66 | 53 |
|
67 | 54 | /** The real host command runner, for a suite adapter that runs one genuine tool (such as `plutil`). */ |
68 | | -export const runRealHostCommand = runCmd; |
| 55 | +export async function runRealHostCommand( |
| 56 | + ...args: Parameters<typeof import('@agent-device/host-kit/command').runCmd> |
| 57 | +) { |
| 58 | + const { runCmd } = await import('@agent-device/host-kit/command'); |
| 59 | + return await runCmd(...args); |
| 60 | +} |
| 61 | + |
| 62 | +/** Keeps a daemon deadline on the request's cancellation signal until its work settles. */ |
| 63 | +export async function withRequestDeadline( |
| 64 | + ...args: Parameters<typeof import('@agent-device/host-kit/request').withRequestDeadline> |
| 65 | +) { |
| 66 | + const { withRequestDeadline: run } = await import('@agent-device/host-kit/request'); |
| 67 | + return await run(...args); |
| 68 | +} |
0 commit comments