Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/client/src/__tests__/client-normalizers-device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,57 @@ test('normalizeOpenDevice preserves Vega identifier shaping', () => {
assert.equal('ios' in (vega ?? {}), false);
assert.equal('android' in (vega ?? {}), false);
});

// #4525: the SDK reads the OS a session or an open ran on off the same payload the CLI prints.
test('normalizeOpenDevice carries the device kind, model and OS version a daemon reports', () => {
const ios = normalizeOpenDevice({
platform: 'ios',
id: 'SIM-001',
device: 'iPhone 17',
kind: 'simulator',
model: 'iPhone 17',
osVersion: '27.0',
device_udid: 'SIM-001',
});
assert.equal(ios?.kind, 'simulator');
assert.equal(ios?.model, 'iPhone 17');
assert.equal(ios?.osVersion, '27.0');

// A daemon that reports nothing states nothing: no field is invented for it.
const unreported = normalizeOpenDevice({
platform: 'android',
id: 'emulator-5554',
device: 'pixel-9',
});
assert.equal('kind' in (unreported ?? {}), false);
assert.equal('model' in (unreported ?? {}), false);
assert.equal('osVersion' in (unreported ?? {}), false);

// An empty string is not an OS version, and an unknown kind is not a kind.
const malformed = normalizeOpenDevice({
platform: 'android',
id: 'emulator-5554',
device: 'pixel-9',
kind: 'phone',
osVersion: '',
});
assert.equal('kind' in (malformed ?? {}), false);
assert.equal('osVersion' in (malformed ?? {}), false);
});

test('normalizeSession carries the session device kind, model and OS version', () => {
const session = normalizeSession({
name: 'qa',
createdAt: 1,
platform: 'android',
target: 'mobile',
id: 'emulator-5554',
device: 'pixel-9',
kind: 'emulator',
model: 'sdk_gphone64_arm64',
osVersion: '16',
});
assert.equal(session.device.kind, 'emulator');
assert.equal(session.device.model, 'sdk_gphone64_arm64');
assert.equal(session.device.osVersion, '16');
});
16 changes: 15 additions & 1 deletion packages/client/src/client-normalizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
isRecord,
readDeviceTarget,
readNullableString,
readOptionalDeviceKind,
readOptionalString,
readRequiredDeviceKind,
readRequiredNumber,
Expand Down Expand Up @@ -124,7 +125,11 @@ export function normalizeDevice(value: unknown): AgentDeviceDevice {
};
}

/** Reads the optional presentation-only hardware model and OS version of a listed device. */
/**
* Reads the optional presentation-only hardware model and OS version a daemon response carries,
* for both a listed device and the device of an open session. Absent means the host or provider
* reported nothing; it is never inferred here.
*/
function readDeviceDescription(
record: Record<string, unknown>,
): Pick<AgentDeviceDevice, 'model' | 'osVersion'> {
Expand All @@ -150,6 +155,7 @@ export function normalizeSession(value: unknown): AgentDeviceSession {
const { record, platform, id, name, target } = readClientDeviceIdentity(value, 'name');
const deviceName = readRequiredString(record, 'device');
const appleOs = readAppleOs(record);
const kind = readOptionalDeviceKind(record, 'kind');
const identifiers = {
session: name,
...buildDeviceIdentifiers(platform, id, deviceName),
Expand All @@ -167,6 +173,10 @@ export function normalizeSession(value: unknown): AgentDeviceSession {
name: deviceName,
// Additive Apple-OS discriminant; present only when the daemon emits it (Apple devices).
...(appleOs ? { appleOs } : {}),
// Model and OS version are the daemon's discovery read; a session whose host reported
// neither carries neither.
...readDeviceDescription(record),
...(kind ? { kind } : {}),
identifiers,
...buildClientDevicePlatformFields(platform, id, {
simulatorSetPath: readNullableString(record, 'ios_simulator_device_set'),
Expand Down Expand Up @@ -240,6 +250,7 @@ export function normalizeOpenDevice(
return undefined;
}
const target = readDeviceTarget(value, 'target');
const kind = readOptionalDeviceKind(value, 'kind');
const serial = isSerialAddressablePlatform(platform)
? (readOptionalString(value, 'serial') ?? id)
: undefined;
Expand All @@ -252,6 +263,9 @@ export function normalizeOpenDevice(
target,
id,
name,
// The daemon echoes what discovery or the provider reported; an absent field stays absent.
...readDeviceDescription(value),
...(kind ? { kind } : {}),
identifiers,
...buildClientDevicePlatformFields(
platform,
Expand Down
100 changes: 100 additions & 0 deletions packages/command-output/src/output/result-serialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,106 @@ test('serializeOpenResult includes android serial for open payloads', () => {
});
});

// #4525: a CI integration records the OS a capture ran on from this result alone.
test('serializeOpenResult reports the device kind, model and OS version the host reported', () => {
const ios = serializeOpenResult({
session: 'ios',
device: {
platform: 'ios',
target: 'mobile',
id: 'SIM-001',
name: 'iPhone 17',
kind: 'simulator',
model: 'iPhone 17',
osVersion: '27.0',
identifiers: { session: 'ios', deviceId: 'SIM-001', deviceName: 'iPhone 17' },
ios: { udid: 'SIM-001' },
},
identifiers: { session: 'ios', deviceId: 'SIM-001', deviceName: 'iPhone 17' },
});
assert.deepEqual(
{
platform: ios.platform,
device: ios.device,
kind: ios.kind,
model: ios.model,
osVersion: ios.osVersion,
},
{
platform: 'ios',
device: 'iPhone 17',
kind: 'simulator',
model: 'iPhone 17',
osVersion: '27.0',
},
);

const android = serializeOpenResult({
session: 'android',
device: {
platform: 'android',
target: 'mobile',
id: 'emulator-5554',
name: 'pixel-9',
kind: 'emulator',
model: 'sdk_gphone64_arm64',
osVersion: '16',
identifiers: { session: 'android', deviceId: 'emulator-5554', serial: 'emulator-5554' },
android: { serial: 'emulator-5554' },
},
identifiers: { session: 'android', deviceId: 'emulator-5554', serial: 'emulator-5554' },
});
assert.equal(android.kind, 'emulator');
assert.equal(android.model, 'sdk_gphone64_arm64');
assert.equal(android.osVersion, '16');
assert.equal(android.serial, 'emulator-5554');

// A rented cloud device keeps what its provider reported, on the same keys.
const remote = serializeOpenResult({
session: 'remote',
device: {
platform: 'ios',
target: 'mobile',
id: 'browserstack:ios:lease-1',
name: 'iPhone 15',
kind: 'device',
osVersion: '17.2',
identifiers: {
session: 'remote',
deviceId: 'browserstack:ios:lease-1',
deviceName: 'iPhone 15',
},
ios: { udid: 'browserstack:ios:lease-1' },
},
identifiers: { session: 'remote', deviceId: 'browserstack:ios:lease-1' },
});
assert.equal(remote.kind, 'device');
assert.equal(remote.osVersion, '17.2');
// The provider reported no hardware model, so the field stays out rather than naming one.
assert.equal('model' in remote, false);
});

test('serializeSessionListEntry reports the session device kind and OS version', () => {
const data = serializeSessionListEntry({
name: 'qa',
createdAt: 123,
device: {
platform: 'ios',
target: 'mobile',
id: 'SIM-001',
name: 'iPhone 17',
kind: 'simulator',
osVersion: '27.0',
identifiers: { session: 'qa', deviceId: 'SIM-001', deviceName: 'iPhone 17' },
ios: { udid: 'SIM-001' },
},
identifiers: { session: 'qa', deviceId: 'SIM-001', deviceName: 'iPhone 17' },
});

assert.equal(data.kind, 'simulator');
assert.equal(data.osVersion, '27.0');
});

test('serializeOpenResult carries an answered launch confirmation', () => {
const data = serializeOpenResult({
session: 'qa',
Expand Down
3 changes: 3 additions & 0 deletions packages/command-output/src/output/result-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function serializeSessionDevice(
target: device.target,
device: device.name,
id: device.id,
...(device.kind ? { kind: device.kind } : {}),
...(device.model ? { model: device.model } : {}),
...(device.osVersion ? { osVersion: device.osVersion } : {}),
...(device.platform === 'ios'
? {
device_udid: device.ios?.udid ?? device.id,
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts/src/client-device-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export type AgentDeviceSessionDevice = {
* Apple devices; `platform` still carries the leaf (`ios`/`macos`).
*/
appleOs?: AppleOS;
/** Simulator/emulator/physical split. Absent only from a daemon older than the field. */
kind?: DeviceKind;
/** Hardware model, for example `iPhone 17 Pro` or `Pixel 9`, when the host or provider reports it. */
model?: string;
/** OS version, for example `26.1` or `16`, when the host or provider reports it. Never inferred. */
osVersion?: string;
identifiers: AgentDeviceIdentifiers;
ios?: {
udid: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/resources/macos-app-lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ const HOST_OPEN_RESULT_KEYS = [
'device',
'id',
'kind',
'model',
'osVersion',
'serial',
'device_udid',
'ios_simulator_device_set',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { test, expect } from 'vitest';
import { daemonPlatformServicesFixture } from '../../../../__tests__/support/platform-services-fixture.ts';
import { makeSessionStore } from '../../../../__tests__/support/store-factory.ts';
import { makeSession } from '../../../../__tests__/support/handlers/session-test-harness.ts';
import { handleSessionInventoryCommands } from '../inventory.ts';
import type { DaemonRequest } from '../../../../core/daemon-request.ts';
import { bindTestCommandHost, createTestHostEnvironment } from '@agent-device/test-kit';
import type { SessionStore } from '../../../../core/session-store.ts';

bindTestCommandHost();

// #4525: a remote CI integration records which OS a capture ran on from the command result alone,
// so `session list` reports the device kind beside the model and OS version its host discovery read.
test('session_list reports the session device kind, model and OS version', async () => {
const sessionStore = makeSessionStore('agent-device-inventory-session-device-');
sessionStore.publish(
'ios-1',
makeSession('ios-1', {
platform: 'apple',
appleOs: 'ios',
id: 'SIM-001',
name: 'iPhone 17',
kind: 'simulator',
model: 'iPhone 17',
osVersion: '27.0',
booted: true,
}),
);
sessionStore.publish(
'android-1',
makeSession('android-1', {
platform: 'android',
id: 'emulator-5554',
name: 'pixel-9',
kind: 'emulator',
model: 'sdk_gphone64_arm64',
osVersion: '16',
booted: true,
}),
);
// A host that read no description (for example a stopped AVD) states nothing about the OS.
sessionStore.publish(
'android-stopped',
makeSession('android-stopped', {
platform: 'android',
id: 'emulator-5556',
name: 'pixel-8',
kind: 'emulator',
}),
);

const sessions = await listSessions(sessionStore);
const ios = sessions.find((session) => session.name === 'ios-1');
expect(ios?.kind).toBe('simulator');
expect(ios?.model).toBe('iPhone 17');
expect(ios?.osVersion).toBe('27.0');

const android = sessions.find((session) => session.name === 'android-1');
expect(android?.kind).toBe('emulator');
expect(android?.model).toBe('sdk_gphone64_arm64');
expect(android?.osVersion).toBe('16');

const stopped = sessions.find((session) => session.name === 'android-stopped');
expect(stopped?.kind).toBe('emulator');
expect(stopped && 'osVersion' in stopped).toBe(false);
expect(stopped && 'model' in stopped).toBe(false);
});

async function listSessions(sessionStore: SessionStore): Promise<Array<Record<string, unknown>>> {
const req: DaemonRequest = {
token: 't',
session: 'default',
command: 'session_list',
positionals: [],
};
const response = await handleSessionInventoryCommands({
host: createTestHostEnvironment(),
req,
sessionName: 'default',
sessionStore,
platformServices: daemonPlatformServicesFixture(),
});
expect(response?.ok).toBe(true);
if (!response?.ok) throw new Error('expected session_list to succeed');
return response.data?.sessions as Array<Record<string, unknown>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ test('buildOpenResult exposes the Vega serial without leaking an internal platfo
assert.equal(result.target, 'tv');
});

const IOS_OPEN_RESULT_BASE = {
sessionName: 'ios-launch-url',
sessionStateDir: '/tmp/state',
runnerLogPath: '/tmp/runner.log',
requestLogPath: '/tmp/request.ndjson',
eventLogPath: '/tmp/events.ndjson',
surface: 'app' as const,
device: IOS_SIMULATOR,
runtimeHintCount: () => 0,
sessionReused: false,
};

// #4525: `open --json` is the one source a remote CI integration reads the capture OS from.
test('buildOpenResult reports the OS version and model the host reported, and omits what it did not', () => {
const described = buildOpenResult({
...IOS_OPEN_RESULT_BASE,
device: { ...IOS_SIMULATOR, model: 'iPhone 17 Pro', osVersion: '27.0' },
});
assert.equal(described.kind, 'simulator');
assert.equal(described.model, 'iPhone 17 Pro');
assert.equal(described.osVersion, '27.0');

// A host or provider that reports nothing gets no field: the reader cannot tell a
// guessed OS from a read one, so silence is the only honest answer.
const unreported = buildOpenResult({ ...IOS_OPEN_RESULT_BASE, device: IOS_SIMULATOR });
assert.equal(unreported.kind, 'simulator');
assert.equal('model' in unreported, false);
assert.equal('osVersion' in unreported, false);
});

test('buildOpenResult exposes typed device-selection evidence once at response level', () => {
const result = buildOpenResult({
sessionName: 'ios-selection',
Expand Down Expand Up @@ -58,17 +88,7 @@ test('buildOpenResult exposes typed device-selection evidence once at response l
});

test('buildOpenResult reports an answered launch confirmation and omits one that never appeared', () => {
const base = {
sessionName: 'ios-launch-url',
sessionStateDir: '/tmp/state',
runnerLogPath: '/tmp/runner.log',
requestLogPath: '/tmp/request.ndjson',
eventLogPath: '/tmp/events.ndjson',
surface: 'app' as const,
device: IOS_SIMULATOR,
runtimeHintCount: () => 0,
sessionReused: false,
};
const base = IOS_OPEN_RESULT_BASE;

assert.equal(
buildOpenResult({ ...base, launchConfirmation: { launchConfirmation: 'accepted' } })
Expand Down
Loading
Loading