Skip to content

Commit 35e5d06

Browse files
committed
fix: project platform to the public leaf at nested output sites (#979)
The Platform collapse (approach b) projects device.platform through publicPlatformString at emit sites so machine consumers keep seeing the leaf ios/macos and never the internal `apple`. Several nested output fields were missed. Project them and narrow their emitted types to PublicPlatform: - Apple perf memory snapshot support (buildAppleMemorySnapshotSupport) — response.support.platform / artifact.support.platform, plus the sibling sampleAppleFramePerf error data. - Apple xctrace perf capture/result platform surfaced in the perf cpu-profile started/stopped response data. - snapshotDiagnostics.stats.platform (recordSnapshotTiming) surfaced in snapshot/test response data and the slow-snapshot warning string. - doctor target-app evidence.platform + human summary, and doctor target-app-device evidence.booted[].platform. - provider/cloud UNSUPPORTED_OPERATION error.data.platform for cloud Apple devices (reachable via deviceFieldsFromPublicPlatform). Internal 'apple' emissions (selector-matching input, diagnostic emitDiagnostic telemetry, session appLog state, replay .ad flags) are left as-is. Adds focused tests pinning Apple perf memory support to the leaf and a guard asserting no emitted platform field equals 'apple'.
1 parent 2aa0399 commit 35e5d06

12 files changed

Lines changed: 99 additions & 33 deletions

File tree

‎src/cloud-webdriver/runtime.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import type {
1313
ProviderDeviceInstallResult,
1414
ProviderDeviceRuntime,
1515
} from '../provider-device-runtime.ts';
16-
import { deviceFieldsFromPublicPlatform, type DeviceInfo } from '../kernel/device.ts';
16+
import {
17+
deviceFieldsFromPublicPlatform,
18+
publicPlatformString,
19+
type DeviceInfo,
20+
} from '../kernel/device.ts';
1721
import { AppError } from '../kernel/errors.ts';
1822
import { unavailableCloudArtifactsResult } from './artifact-results.ts';
1923
import {
@@ -364,7 +368,7 @@ class CloudWebDriverRuntime implements ProviderDeviceRuntime {
364368
throw new AppError(
365369
'UNSUPPORTED_OPERATION',
366370
unsupportedCapabilityMessage(session.capabilities, 'install'),
367-
{ provider: this.provider, deviceId: device.id, platform: device.platform },
371+
{ provider: this.provider, deviceId: device.id, platform: publicPlatformString(device) },
368372
);
369373
}
370374
const uploadApp = session.prepared.uploadApp ?? this.options.uploadApp;

‎src/commands/capture/index.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('capture command interface', () => {
6464
p95Ms: 1_900,
6565
maxMs: 1_900,
6666
slowThresholdMs: 1_500,
67-
platform: 'apple',
67+
platform: 'ios',
6868
},
6969
warning: 'Warning: ios snapshots are slow in this run: p95 1900ms over 2 captures.',
7070
},

‎src/core/interactors.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DeviceInfo } from '../kernel/device.ts';
1+
import { publicPlatformString, type DeviceInfo } from '../kernel/device.ts';
22
import { AppError } from '../kernel/errors.ts';
33
import { getProviderDeviceInteractor, isActiveProviderDevice } from '../provider-device-runtime.ts';
44
import type { Interactor, RunnerContext } from './interactor-types.ts';
@@ -19,7 +19,7 @@ export async function getInteractor(
1919
throw new AppError(
2020
'UNSUPPORTED_OPERATION',
2121
'Provider device runtime does not have an active interactor for this device.',
22-
{ deviceId: device.id, platform: device.platform },
22+
{ deviceId: device.id, platform: publicPlatformString(device) },
2323
);
2424
}
2525

‎src/daemon/handlers/__tests__/session-replay-vars.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ test('runReplayScriptFile reports snapshot diagnostics from per-action session s
492492
session?.snapshotDiagnostics?.samples.push({
493493
durationMs: captures === 1 ? 400 : 1_900,
494494
backend: 'xctest',
495-
platform: 'apple',
495+
platform: 'ios',
496496
});
497497
return {
498498
ok: true,
@@ -550,7 +550,7 @@ test('runReplayScriptFile reports snapshot diagnostics on replay failure', async
550550
session?.snapshotDiagnostics?.samples.push({
551551
durationMs: captures === 1 ? 450 : 2_100,
552552
backend: 'xctest',
553-
platform: 'apple',
553+
platform: 'ios',
554554
});
555555
if (captures === 1) return { ok: true, data: {} };
556556
return { ok: false, error: { code: 'COMMAND_FAILED', message: 'button missing' } };

‎src/daemon/handlers/session-doctor-app.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { isIosFamily, isMacOs, type DeviceInfo } from '../../kernel/device.ts';
1+
import {
2+
isIosFamily,
3+
isMacOs,
4+
publicPlatformString,
5+
type DeviceInfo,
6+
} from '../../kernel/device.ts';
27
import { AppError, normalizeError } from '../../kernel/errors.ts';
38
import type { SessionState } from '../types.ts';
49
import { appendDoctorCheck } from './session-doctor-output.ts';
@@ -19,8 +24,9 @@ export async function appendAppChecks(
1924
appendDoctorCheck(checks, {
2025
id: 'target-app',
2126
status: 'info',
22-
summary: `Target app installation checks are not supported for ${device.platform}.`,
23-
evidence: { requested: targetApp, platform: device.platform },
27+
// approach (b): emit the PUBLIC leaf platform (ios/macos), never the internal `apple`.
28+
summary: `Target app installation checks are not supported for ${publicPlatformString(device)}.`,
29+
evidence: { requested: targetApp, platform: publicPlatformString(device) },
2430
});
2531
return;
2632
}

‎src/daemon/handlers/session-doctor-device.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '../../core/platform-inventory.ts';
1111
import {
1212
matchesDeviceSelector,
13+
publicPlatformString,
1314
type DeviceInfo,
1415
type DeviceTarget,
1516
type Platform,
@@ -94,7 +95,8 @@ export function resolveDoctorDeviceForAppCheck(
9495
evidence: {
9596
targetApp,
9697
booted: booted.map((device) => ({
97-
platform: device.platform,
98+
// approach (b): emit the PUBLIC leaf platform (ios/macos), never the internal `apple`.
99+
platform: publicPlatformString(device),
98100
id: device.id,
99101
name: device.name,
100102
})),

‎src/daemon/handlers/snapshot-capture.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dispatchCommand, type CommandFlags } from '../../core/dispatch.ts';
2-
import { isMacOs, isMobilePlatform } from '../../kernel/device.ts';
2+
import { isMacOs, isMobilePlatform, publicPlatformString } from '../../kernel/device.ts';
33
import { sleep } from '../../utils/timeouts.ts';
44
import { runMacOsSnapshotAction } from '../../platforms/apple/os/macos/helper.ts';
55
import { snapshotLinux } from '../../platforms/linux/snapshot.ts';
@@ -312,7 +312,8 @@ async function captureSnapshotAttempt(params: CaptureSnapshotParams): Promise<Sn
312312
recordSnapshotTiming(params.session, {
313313
durationMs: Date.now() - startedAt,
314314
backend: data.backend,
315-
platform: params.device.platform,
315+
// approach (b): emit the PUBLIC leaf platform (ios/macos), never the internal `apple`.
316+
platform: publicPlatformString(params.device),
316317
});
317318
return {
318319
data,

‎src/platforms/apple/core/__tests__/perf.test.ts‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ vi.mock('../../../../utils/exec.ts', async (importOriginal) => {
1414
});
1515

1616
import {
17+
buildAppleMemorySnapshotSupport,
1718
captureAppleMemorySnapshot,
1819
parseApplePsOutput,
1920
sampleAppleFramePerf,
@@ -67,6 +68,42 @@ beforeEach(() => {
6768
vi.useRealTimers();
6869
});
6970

71+
function collectPlatformValues(value: unknown): string[] {
72+
if (Array.isArray(value)) return value.flatMap((entry) => collectPlatformValues(entry));
73+
if (value && typeof value === 'object') {
74+
return Object.entries(value).flatMap(([key, entry]) =>
75+
key === 'platform' && typeof entry === 'string'
76+
? [entry, ...collectPlatformValues(entry)]
77+
: collectPlatformValues(entry),
78+
);
79+
}
80+
return [];
81+
}
82+
83+
test('buildAppleMemorySnapshotSupport projects support.platform to the macOS leaf', () => {
84+
// approach (b): response.support.platform must be the PUBLIC leaf, never the internal `apple`.
85+
const support = buildAppleMemorySnapshotSupport(MACOS_DEVICE);
86+
assert.equal(support.platform, 'macos');
87+
assert.equal(support.memgraph, true);
88+
});
89+
90+
test('buildAppleMemorySnapshotSupport projects support.platform to the iOS leaf', () => {
91+
assert.equal(buildAppleMemorySnapshotSupport(IOS_SIMULATOR).platform, 'ios');
92+
assert.equal(buildAppleMemorySnapshotSupport(IOS_DEVICE).platform, 'ios');
93+
});
94+
95+
test('buildAppleMemorySnapshotSupport never emits the internal apple platform', () => {
96+
// Guard: no emitted `platform` field on a representative Apple perf response may equal `apple`.
97+
for (const device of [MACOS_DEVICE, IOS_SIMULATOR, IOS_DEVICE]) {
98+
const platforms = collectPlatformValues(buildAppleMemorySnapshotSupport(device));
99+
assert.ok(platforms.length > 0, 'expected at least one platform field');
100+
assert.ok(
101+
!platforms.includes('apple'),
102+
`apple leaked in support for ${device.name}: ${platforms.join(', ')}`,
103+
);
104+
}
105+
});
106+
70107
test('parseApplePsOutput reads pid cpu rss and command columns', () => {
71108
const rows = parseApplePsOutput(
72109
['123 12.5 45678 /Applications/Test.app/Contents/MacOS/Test --flag', '456 0.0 2048 Test'].join(
@@ -728,7 +765,7 @@ test('stopAppleXctracePerfCapture returns compact artifact metadata', async () =
728765
outPath: tracePath,
729766
appBundleId: 'com.example.app',
730767
deviceId: 'sim-1',
731-
platform: 'apple',
768+
platform: 'ios',
732769
targetPids: [111],
733770
targetProcesses: ['Example'],
734771
startedAt: '2026-04-01T10:00:00.000Z',
@@ -759,7 +796,7 @@ test('stopAppleXctracePerfCapture force-kills xctrace when graceful stop times o
759796
outPath: tracePath,
760797
appBundleId: 'com.example.app',
761798
deviceId: 'sim-1',
762-
platform: 'apple',
799+
platform: 'ios',
763800
targetPids: [111],
764801
targetProcesses: ['Example'],
765802
startedAt: '2026-04-01T10:00:00.000Z',
@@ -810,7 +847,7 @@ test('stopAppleXctracePerfCapture reports confirmed cleanup after forced kill ex
810847
outPath: tracePath,
811848
appBundleId: 'com.example.app',
812849
deviceId: 'sim-1',
813-
platform: 'apple',
850+
platform: 'ios',
814851
targetPids: [111],
815852
targetProcesses: ['Example'],
816853
startedAt: '2026-04-01T10:00:00.000Z',

‎src/platforms/apple/core/perf-xctrace.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { promises as fs } from 'node:fs';
22
import os from 'node:os';
33
import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
5-
import { isIosFamily, isApplePlatform, type DeviceInfo } from '../../../kernel/device.ts';
5+
import {
6+
isIosFamily,
7+
isApplePlatform,
8+
publicPlatformString,
9+
type DeviceInfo,
10+
type PublicPlatform,
11+
} from '../../../kernel/device.ts';
612
import { AppError } from '../../../kernel/errors.ts';
713
import {
814
runCmdBackground,
@@ -38,7 +44,8 @@ export type AppleXctracePerfCapture = {
3844
outPath: string;
3945
appBundleId: string;
4046
deviceId: string;
41-
platform: DeviceInfo['platform'];
47+
// approach (b): the PUBLIC leaf platform (ios/macos) surfaced in perf responses, never `apple`.
48+
platform: PublicPlatform;
4249
targetPids: number[];
4350
targetProcesses: string[];
4451
startedAt: string;
@@ -53,7 +60,8 @@ export type AppleXctracePerfResult = {
5360
outPath: string;
5461
appBundleId: string;
5562
deviceId: string;
56-
platform: DeviceInfo['platform'];
63+
// approach (b): the PUBLIC leaf platform (ios/macos) surfaced in perf responses, never `apple`.
64+
platform: PublicPlatform;
5765
targetPids: number[];
5866
targetProcesses: string[];
5967
startedAt: string;
@@ -102,7 +110,7 @@ export async function startAppleXctracePerfCapture(params: {
102110
outPath: params.outPath,
103111
appBundleId: params.appBundleId,
104112
deviceId: params.device.id,
105-
platform: params.device.platform,
113+
platform: publicPlatformString(params.device),
106114
targetPids: target.pids,
107115
targetProcesses: target.processNames,
108116
startedAt,

‎src/platforms/apple/core/perf.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { promises as fs } from 'node:fs';
22
import os from 'node:os';
33
import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
5-
import { isIosFamily, isMacOs, type DeviceInfo } from '../../../kernel/device.ts';
5+
import {
6+
isIosFamily,
7+
isMacOs,
8+
publicPlatformString,
9+
type DeviceInfo,
10+
type PublicPlatform,
11+
} from '../../../kernel/device.ts';
612
import { AppError } from '../../../kernel/errors.ts';
713
import type { ExecResult } from '../../../utils/exec.ts';
814
import { splitNonEmptyTrimmedLines } from '../../../utils/parsing.ts';
@@ -312,7 +318,7 @@ export async function sampleAppleFramePerf(
312318
'Apple frame-health sampling is currently available only on connected iOS devices.',
313319
{
314320
metric: 'fps',
315-
platform: device.platform,
321+
platform: publicPlatformString(device),
316322
deviceKind: device.kind,
317323
},
318324
);
@@ -392,7 +398,8 @@ export function buildAppleSamplingMetadata(device: DeviceInfo): Record<string, u
392398
}
393399

394400
export function buildAppleMemorySnapshotSupport(device: DeviceInfo): {
395-
platform: DeviceInfo['platform'];
401+
// approach (b): emit the PUBLIC leaf platform (ios/macos), never the internal `apple`.
402+
platform: PublicPlatform;
396403
deviceKind: DeviceInfo['kind'];
397404
memgraph: boolean;
398405
method: typeof APPLE_MEMGRAPH_SNAPSHOT_METHOD;
@@ -401,7 +408,7 @@ export function buildAppleMemorySnapshotSupport(device: DeviceInfo): {
401408
} {
402409
if (isIosFamily(device) && device.kind === 'device') {
403410
return {
404-
platform: device.platform,
411+
platform: publicPlatformString(device),
405412
deviceKind: device.kind,
406413
memgraph: false,
407414
method: APPLE_MEMGRAPH_SNAPSHOT_METHOD,
@@ -412,7 +419,7 @@ export function buildAppleMemorySnapshotSupport(device: DeviceInfo): {
412419
}
413420
if (isIosFamily(device) && device.kind === 'simulator') {
414421
return {
415-
platform: device.platform,
422+
platform: publicPlatformString(device),
416423
deviceKind: device.kind,
417424
memgraph: true,
418425
method: APPLE_MEMGRAPH_SNAPSHOT_METHOD,
@@ -422,7 +429,7 @@ export function buildAppleMemorySnapshotSupport(device: DeviceInfo): {
422429
}
423430
if (isMacOs(device)) {
424431
return {
425-
platform: device.platform,
432+
platform: publicPlatformString(device),
426433
deviceKind: device.kind,
427434
memgraph: true,
428435
method: APPLE_MEMGRAPH_SNAPSHOT_METHOD,
@@ -431,7 +438,7 @@ export function buildAppleMemorySnapshotSupport(device: DeviceInfo): {
431438
};
432439
}
433440
return {
434-
platform: device.platform,
441+
platform: publicPlatformString(device),
435442
deviceKind: device.kind,
436443
memgraph: false,
437444
method: APPLE_MEMGRAPH_SNAPSHOT_METHOD,

0 commit comments

Comments
 (0)