Skip to content

Commit 613e66b

Browse files
committed
refactor(host): compose platforms with the runtime host at the root (#3794)
1 parent ef01a7b commit 613e66b

93 files changed

Lines changed: 954 additions & 421 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.

‎scripts/clean-daemon.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ if (retirement.status === 'retained') {
4141
if (retirement.status === 'retired') {
4242
const { cleanupRunnerLeasesForOwner } =
4343
await import('@agent-device/platform-apple/runner/operations');
44+
const { setAppleRunnerHostEnvironment } =
45+
await import('@agent-device/platform-apple/runner-owner');
46+
const host = captureHostEnvironment(process);
47+
// Runner configuration reads take the runtime's host (#3794); this script is the whole
48+
// process here, so it seeds the runner state with the same host it enters as a command host.
49+
setAppleRunnerHostEnvironment(host);
4450
await withCommandHost(
45-
{ host: captureHostEnvironment(process), requestEnv: undefined },
51+
{ host, requestEnv: undefined },
4652
async () => await cleanupRunnerLeasesForOwner(retirement.termination.identity),
4753
);
4854
}

‎scripts/write-xcuitest-cache-metadata.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ async function writeXcuitestCacheMetadata(
7373
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
7474
try {
7575
const host = captureHostEnvironment(process);
76+
// Runner configuration reads take the runtime's host (#3794); this script is the whole
77+
// process here, so it seeds the runner state with the same host it enters as a command host.
78+
const { setAppleRunnerHostEnvironment } =
79+
await import('@agent-device/platform-apple/runner-owner');
80+
setAppleRunnerHostEnvironment(host);
7681
await withCommandHost(
7782
{ host, requestEnv: undefined },
7883
async () => await writeXcuitestCacheMetadata(process.argv.slice(2), host.cwd),

‎src/__tests__/cli-record-flag-delivery.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ async function runArgv(argv: string[]): Promise<SeenRequest[]> {
4646
client,
4747
command: argv[0] as CommandName,
4848
positionals: parsed.positionals,
49+
env: process.env,
4950
flags: parsed.flags,
5051
});
5152
} catch {

‎src/__tests__/command-descriptor-post-action-observation.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ test('post-action observation CLI output formatters follow descriptor traits', a
266266
for (const [command, format] of Object.entries(formatters)) {
267267
let text: string;
268268
try {
269-
text = String((await format({ input: {}, result: settledResult })).text ?? '');
269+
text = String(
270+
(await format({ env: process.env, input: {}, result: settledResult })).text ?? '',
271+
);
270272
} catch {
271273
// Formatters expecting a differently-shaped result (device lists) are
272274
// orthogonal to settle rendering — but a settle-capable formatter must

‎src/__tests__/daemon-composition/platform-resource-cleanup-snapshot-helper.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ vi.mock('@agent-device/platform-android/mechanics', async (importOriginal) => {
1212
};
1313
});
1414

15-
import { ANDROID_EMULATOR, IOS_SIMULATOR } from '@agent-device/test-kit';
16-
import { platformResourceCleanup } from '../../platform-runtime-resource-cleanup.ts';
15+
import {
16+
ANDROID_EMULATOR,
17+
IOS_SIMULATOR,
18+
createLiveTestHostEnvironment,
19+
} from '@agent-device/test-kit';
20+
import { createPlatformResourceCleanup } from '../../platform-runtime-resource-cleanup.ts';
21+
22+
const platformResourceCleanup = createPlatformResourceCleanup(createLiveTestHostEnvironment());
1723

1824
beforeEach(() => {
1925
vi.clearAllMocks();

‎src/__tests__/daemon-composition/platform-services-fixture.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type ClaimRecoveryGatewayFactory } from '@agent-device/daemon-contracts
22
import { createDaemonPlatformServices } from '../../platform-runtime-daemon-services.ts';
33
import { createClaimRecoveryGatewayFor } from '../../platform-runtime-claim-recovery.ts';
44
import type { DaemonPlatformServices } from '@agent-device/daemon';
5+
import { createLiveTestHostEnvironment } from '@agent-device/test-kit';
56

67
/**
78
* The port the production composition root builds, handed to a test the same way the shared router
@@ -22,5 +23,5 @@ export function composedPlatformServicesFixture(
2223
* passes its own factory.
2324
*/
2425
export function composedClaimRecoveryGatewayFixture(): ClaimRecoveryGatewayFactory {
25-
return createClaimRecoveryGatewayFor(process.env);
26+
return createClaimRecoveryGatewayFor(createLiveTestHostEnvironment());
2627
}

‎src/__tests__/platform-runtime-apple-application-tools.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ vi.mock('@agent-device/platform-apple/runner/operations', async (importOriginal)
1919
// loses the mock this way starts the real local XCTest runner — whose stale-process cleanup
2020
// `pkill`s xcodebuild on the developer's host, failing whichever test is running when it lands.
2121
test('concurrent runner ports share one module resolution, so the mock always applies', async () => {
22-
const tools = createAppleApplicationTools();
22+
const tools = createAppleApplicationTools(process.env);
2323

2424
await Promise.all([
2525
tools.detachRunnerSessionsForShutdown(),

‎src/__tests__/platform-runtime-claim-recovery.test.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { createDurableResourceEnvelope } from '@agent-device/capture-kit';
1010
import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime';
1111
import { runStaleDeviceClaimRelease } from '../platform-runtime-claim-recovery.ts';
1212
import { runCliCapture } from './cli-capture.ts';
13-
import { mkdtempForTestSync, pinOwnProcessStartTime } from '@agent-device/test-kit';
13+
import {
14+
createLiveTestHostEnvironment,
15+
mkdtempForTestSync,
16+
pinOwnProcessStartTime,
17+
} from '@agent-device/test-kit';
1418

1519
pinOwnProcessStartTime(hostProcess);
1620

@@ -283,16 +287,20 @@ test('recovery is composed per claim from the stale owner state dir, never the c
283287
process.env.AGENT_DEVICE_CLAIMS_DIR = claimsDir;
284288

285289
const composedFor: string[] = [];
286-
const outcomes = await runStaleDeviceClaimRelease({}, process.env, (stateDir) => {
287-
composedFor.push(stateDir);
288-
return {
289-
reconcile: async (claim) => {
290-
assert.equal(claim.stateDir, stateDir);
291-
return { status: 'reconciled' };
292-
},
293-
dispose: async () => {},
294-
};
295-
});
290+
const outcomes = await runStaleDeviceClaimRelease(
291+
{},
292+
createLiveTestHostEnvironment(),
293+
(stateDir) => {
294+
composedFor.push(stateDir);
295+
return {
296+
reconcile: async (claim) => {
297+
assert.equal(claim.stateDir, stateDir);
298+
return { status: 'reconciled' };
299+
},
300+
dispose: async () => {},
301+
};
302+
},
303+
);
296304

297305
assert.deepEqual([...composedFor].sort(), [ownerDirA, ownerDirB].sort());
298306
assert.equal(outcomes.filter((outcome) => outcome.status === 'released').length, 2);

‎src/agent-device-client.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ export function createAgentDeviceClient(
486486
symbols: async (options) => {
487487
const { symbolicateCrashArtifact } =
488488
await import('@agent-device/platform-apple/debug-symbols');
489-
return symbolicateCrashArtifact({ cwd: options.cwd ?? config.cwd, ...options });
489+
return symbolicateCrashArtifact({
490+
...options,
491+
cwd: options.cwd ?? config.cwd ?? host.cwd,
492+
});
490493
},
491494
},
492495
recording: {

‎src/cli.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ async function runCliOnHost(argv: string[], deps: CliDeps, host: HostEnvironment
190190
await runWebCommand(positionals, {
191191
flags: ctx.effectiveFlags,
192192
stateDir: ctx.daemonPaths.baseDir,
193+
host,
193194
}),
194195
);
195196
return;

0 commit comments

Comments
 (0)