Skip to content

Commit 78c0ca4

Browse files
authored
refactor(ios): point xcodebuild at the scoped simulator set and delete the XCTestDevices redirect (#2963)
* fix(ios-runner): resolve scoped simulators via -DVTSimulatorSetLocation, not a redirect xcodebuild resolves a simulator in a custom CoreSimulator set through the DVTSimulatorSetLocation Xcode user default, passed as -DVTSimulatorSetLocation=<set>. Every runner xcodebuild phase (build-for-testing and test-without-building) now names the scoped set beside its -destination, so the runner never needs ~/Library/Developer/XCTestDevices. Xcode's first-launch cleanup deletes every device in XCTestDevices, and while it was a symlink into the user's set that cleanup deleted the user's simulators (#2935). Deleted: the XCTestDevices rename/symlink/reconcile machinery, the host-global xctest-device-set.lock, the session redirect handle and its releases, the simulator_set_redirect handoff refusal and the scoped-set adoption refusal. A simulator runner start puts back a symlink or XCTestDevices.agent-device-backup an older version left behind. A destination xcodebuild cannot find for a scoped set fails with details.reason simulator_set_destination_not_found, naming details.simulatorSetPath and details.xcodeVersion, in both xcodebuild phases. Closes #2935 * fix(daemon): keep a scoped simulator set's runner warm on close close stopped the runner of a simulator in a scoped set only because that runner held the XCTestDevices redirect and its host-global lock for its lifetime (#1013). The redirect is gone, so a scoped-set runner is retained under idle-stop like a default-set one. * fix(ios-runner): undo only an XCTestDevices redirect agent-device left behind The legacy cleanup unlinked any XCTestDevices symlink on every simulator startup, so a host that links XCTestDevices to another volume lost the link on a default-set open. A symlink is now removed only when the agent-device backup sits beside it, or when it points at this runner's own scoped simulator set. * fix(ios-runner): scope runner reuse to one simulator set and name the set in destination errors - Reuse and lease adoption now require the same simulator: one udid in one resolved simulator set. The lease records the scoped set; a runner leased or registered for another set is stopped and restarted, never reused. - The runner derives a simulator's set through simulatorAddressFor, which now resolves the set path, instead of restating the simulator predicate. - simulator_set_destination_not_found names the set and the selected Xcode in its message. The Xcode version comes from the toolchain fingerprint owner, so external and adopted sessions report it too; the artifact no longer carries its own copy. The hint points at the error instead of printing field names. - The legacy XCTestDevices restore runs before adoption, so both startup routes pass through it, and a step another daemon already took counts as done instead of failing the startup. * refactor(ios-runner): split the session-serving check and the legacy restore steps into helpers * test(ios-runner): pin the scoped-set destination rule to captured Xcode 26.2 output The simulator_set_destination_not_found fixtures were invented text. They are now the output Xcode 26.2 (17C52) printed for the runner's own build-for-testing and test-without-building argv, with the destination naming a scoped-set udid and -DVTSimulatorSetLocation naming a set that does not hold it, and for the same build without the key. Destination lines that identify the host's hardware and simulators are left out. * refactor(ios-runner): put back a legacy XCTestDevices redirect once, at daemon startup The restore ran on every simulator runner start and reached the session through a runner-xctestrun re-export. It is now one daemon-startup step on the platform owner lifecycle, after daemon.log publication. Without a device to compare against, it removes any symlink at XCTestDevices, as released versions did on every scoped runner start, and restores the agent-device backup. Each repair and any failure is recorded in daemon.log; a failure stops neither the daemon nor a runner start, because the runner no longer reads XCTestDevices.
1 parent 9a09675 commit 78c0ca4

45 files changed

Lines changed: 847 additions & 1399 deletions

Some content is hidden

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

‎packages/platform-apple/src/core/__tests__/simctl.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ test('simulatorAddressFor carries the set of iOS-family simulators only', () =>
106106
});
107107
});
108108

109+
test('simulatorAddressFor names a blank set path as the default set', () => {
110+
assert.deepEqual(simulatorAddressFor({ ...IOS_SIMULATOR, simulatorSetPath: ' ' }), {
111+
udid: 'sim-1',
112+
simulatorSetPath: undefined,
113+
});
114+
});
115+
109116
function compileTimeSimulatorScopeProof(): void {
110117
// @ts-expect-error A simulator address is minted from its DeviceInfo, never written by hand.
111118
const forged: SimulatorAddress = { udid: 'sim-1', simulatorSetPath: undefined };

‎packages/platform-apple/src/core/runner-host.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { AppleRunnerHost } from '../runner/index.ts';
22
import { publishFileSync, acquireProcessLock, withProcessLock } from '@agent-device/host-kit/file';
3-
import { resolveIosSimulatorDeviceSetPath } from '@agent-device/kernel/device-isolation';
43

54
import {
65
isCommandTimeoutError,
@@ -42,7 +41,7 @@ import {
4241
getRunnerDeviceClaimAuthorityProbe,
4342
getRunnerLeaseOwnerStateDir,
4443
} from './runner-owner-state.ts';
45-
import { buildSimctlArgsForDevice } from './simctl.ts';
44+
import { buildSimctlArgsForDevice, simulatorAddressFor } from './simctl.ts';
4645
import { readApplePlistJson, runAppleToolCommand, runXcrun } from './tool-provider.ts';
4746

4847
/**
@@ -86,7 +85,6 @@ export const appleRunnerHost: AppleRunnerHost = {
8685
createTtlMemo,
8786
parseBooleanLiteral,
8887
isRecord,
89-
resolveIosSimulatorDeviceSetPath,
9088
emitRequestProgress,
9189
getRequestSignal,
9290
isRequestCanceled,
@@ -96,6 +94,7 @@ export const appleRunnerHost: AppleRunnerHost = {
9694
runXcrun,
9795
readApplePlistJson,
9896
buildSimctlArgsForDevice,
97+
simulatorAddressFor,
9998
resolveIosPhysicalDeviceControl,
10099
visitXmlPlistEntries,
101100
leaseOwnerStateDir: getRunnerLeaseOwnerStateDir,

‎packages/platform-apple/src/core/simctl.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import type { ScopedSimctlArgs } from '@agent-device/contracts/platform-runtime-
55
import { runXcrun, simctlCommand, type ScopedSimctlCommand } from './tool-provider.ts';
66

77
declare const simulatorAddress: unique symbol;
8-
/** A simulator udid with the set that holds it; minted only from a DeviceInfo. */
8+
/**
9+
* A simulator udid with the resolved set that holds it (undefined for the default set); minted only
10+
* from a DeviceInfo. Two devices name the same simulator only when both fields match.
11+
*/
912
export type SimulatorAddress = Readonly<{ udid: string; simulatorSetPath: string | undefined }> & {
1013
readonly [simulatorAddress]: true;
1114
};
1215

1316
export function simulatorAddressFor(device: DeviceInfo): SimulatorAddress {
1417
const simulatorSetPath =
15-
isIosFamily(device) && device.kind === 'simulator' ? device.simulatorSetPath : undefined;
18+
isIosFamily(device) && device.kind === 'simulator'
19+
? resolveIosSimulatorDeviceSetPath(device.simulatorSetPath)
20+
: undefined;
1621
return Object.freeze({ udid: device.id, simulatorSetPath }) as SimulatorAddress;
1722
}
1823

‎packages/platform-apple/src/runner-operations-facade.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
verifyLeaseRunnerPidIdentity,
1818
} from './core/runner-client.ts';
1919
export { queryAppleRunnerSelector } from './core/runner-selector-query.ts';
20+
export { restoreLegacyXctestDeviceSetRedirect } from './runner/runner-device-set.ts';
2021

2122
export async function cleanupRunnerLeasesForOwner(
2223
owner: Parameters<(typeof import('./core/runner-client.ts'))['cleanupRunnerLeasesForOwner']>[0],

‎packages/platform-apple/src/runner/__tests__/apple-toolchain-fixtures.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, vi } from 'vitest';
22
import { appleRunnerTestHost } from '../test-host.ts';
33
import type { ExecResult } from '@agent-device/host-kit/command';
44

5-
const STUBBED_APPLE_TOOLCHAIN = {
5+
export const STUBBED_APPLE_TOOLCHAIN = {
66
xcodeVersion: '26.2',
77
xcodeBuildVersion: '17C52',
88
sdkVersion: '26.2',

‎packages/platform-apple/src/runner/__tests__/runner-adoption-route.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ afterEach(() => {
126126
function writeDetachedLease(device: DeviceInfo): void {
127127
const lease: RunnerLease = {
128128
...buildRunnerLease({
129-
deviceId: device.id,
129+
device,
130130
sessionId: `${device.id}:${RUNNER_PORT}:1`,
131131
runnerPid: RUNNER_PID,
132132
port: RUNNER_PORT,

‎packages/platform-apple/src/runner/__tests__/runner-adoption.test.ts‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let expectedDerived: string;
109109
function writeStaleLeaseFor(device: DeviceInfo, overrides: Partial<RunnerLease> = {}): RunnerLease {
110110
const lease: RunnerLease = {
111111
...buildRunnerLease({
112-
deviceId: device.id,
112+
device,
113113
sessionId: `${device.id}:50700:1`,
114114
runnerPid: 424242,
115115
port: 50700,
@@ -165,7 +165,7 @@ test('readStaleRunnerLease returns dead-owner leases and skips owned ones', () =
165165
// A lease written by this process is owned, not stale.
166166
writeRunnerLease(
167167
buildRunnerLease({
168-
deviceId: simulator.id,
168+
device: simulator,
169169
sessionId: `${simulator.id}:50700:2`,
170170
runnerPid: 424242,
171171
port: 50700,
@@ -323,12 +323,38 @@ test('adoption accepts a legacy lease whose live pid is runner-shaped', async ()
323323
expect(session?.child.pid).toBe(424242);
324324
});
325325

326-
test('adoption is skipped for devices in a custom simulator set', async () => {
327-
writeStaleLease();
326+
test('a runner for a simulator in a custom simulator set is adopted', async () => {
327+
const scopedDevice = { ...simulator, simulatorSetPath: '/custom/device-set' };
328+
writeStaleLeaseFor(scopedDevice);
328329
mockIsProcessAlive.mockReturnValue(true);
330+
mockSendRunnerCommandOnce.mockResolvedValue(new Response(JSON.stringify({ ok: true })));
329331

330-
const scopedDevice = { ...simulator, simulatorSetPath: '/custom/device-set' };
331-
expect(await tryAdoptRunnerSessionFromLease(scopedDevice, {})).toBeNull();
332+
const session = await tryAdoptRunnerSessionFromLease(scopedDevice, {});
333+
334+
expect(session?.state).toBe('ready');
335+
expect(session?.device.simulatorSetPath).toBe('/custom/device-set');
336+
const restamped = JSON.parse(
337+
fs.readFileSync(path.join(leaseDir, `${scopedDevice.id}.json`), 'utf8'),
338+
) as RunnerLease;
339+
expect(restamped.simulatorSetPath).toBe('/custom/device-set');
340+
});
341+
342+
test('a runner leased for the same udid in another simulator set is never adopted', async () => {
343+
mockIsProcessAlive.mockReturnValue(true);
344+
mockSendRunnerCommandOnce.mockResolvedValue(new Response(JSON.stringify({ ok: true })));
345+
const tenantA = { ...simulator, simulatorSetPath: '/custom/tenant-a' };
346+
const tenantB = { ...simulator, simulatorSetPath: '/custom/tenant-b' };
347+
348+
for (const [leasedFor, requested] of [
349+
[tenantA, tenantB],
350+
[tenantA, simulator],
351+
[simulator, tenantA],
352+
] as const) {
353+
writeStaleLeaseFor(leasedFor);
354+
355+
expect(await tryAdoptRunnerSessionFromLease(requested, {})).toBeNull();
356+
expect(adoptionRefusalReason()).toBe('simulator_set_mismatch');
357+
}
332358
expect(mockSendRunnerCommandOnce).not.toHaveBeenCalled();
333359
});
334360

‎packages/platform-apple/src/runner/__tests__/runner-close-finalization.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
makeRunnerLease,
1515
runnerError,
1616
runnerResponse,
17-
redirectHandle,
1817
} from './runner-session-fixtures.ts';
1918
import { mkdtempForTestSync } from './tmp-dir.ts';
2019
import { bindAppleApplicationLifecycle } from '../../lifecycle.ts';
@@ -39,7 +38,6 @@ import {
3938
// capabilities behind the package's runner host port (`scripts/vitest-apple-runner-host-setup.ts`).
4039

4140
const {
42-
mockAcquireXcodebuildSimulatorSetRedirect,
4341
mockCleanupTempFile,
4442
mockEnsureXctestrunArtifact,
4543
mockGetFreePort,
@@ -58,7 +56,6 @@ const {
5856
mockSignalProcessGroupBestEffort,
5957
mockWaitForRunner,
6058
} = vi.hoisted(() => ({
61-
mockAcquireXcodebuildSimulatorSetRedirect: vi.fn(),
6259
mockCleanupTempFile: vi.fn(),
6360
mockEnsureXctestrunArtifact: vi.fn(),
6461
mockGetFreePort: vi.fn(),
@@ -113,7 +110,6 @@ vi.mock('../runner-xctestrun.ts', async () => {
113110
await vi.importActual<typeof import('../runner-xctestrun.ts')>('../runner-xctestrun.ts');
114111
return {
115112
...actual,
116-
acquireXcodebuildSimulatorSetRedirect: mockAcquireXcodebuildSimulatorSetRedirect,
117113
ensureXctestrunArtifact: mockEnsureXctestrunArtifact,
118114
prepareXctestrunWithEnv: mockPrepareXctestrunWithEnv,
119115
resolveExpectedRunnerCacheMetadata: mockResolveExpectedRunnerCacheMetadata,
@@ -168,7 +164,6 @@ beforeEach(async () => {
168164
});
169165
mockResolveExpectedRunnerCacheMetadata.mockReturnValue({ schemaVersion: 1 });
170166
mockResolveRunnerDerivedPath.mockReturnValue('/tmp/derived');
171-
mockAcquireXcodebuildSimulatorSetRedirect.mockResolvedValue(redirectHandle);
172167
mockRunCmdBackground.mockReturnValue(makeBackgroundRunner(4242));
173168
mockRunAppleToolCommand.mockResolvedValue({ exitCode: 0, stdout: '', stderr: '' });
174169
mockIsProcessAlive.mockReturnValue(true);

‎packages/platform-apple/src/runner/__tests__/runner-device-set-give-back.test.ts‎

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)