Skip to content
Draft
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
2 changes: 1 addition & 1 deletion packages/command-registry/src/flag-definitions-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const TARGET_FLAG_DEFINITIONS: readonly FlagDefinition[] = [
names: ['--serial'],
type: 'string',
usageLabel: '--serial <serial>',
usageDescription: 'Android, HarmonyOS, or Vega VVD serial',
usageDescription: 'Android, HarmonyOS, or Vega serial',
projectConfig: true,
recorded: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ test('every emitted input schema carries the aligned device-selector description
const expected: Record<string, string> = {
device: 'Device name; ids go in udid or serial.',
udid: 'Apple device or simulator UDID.',
serial: 'Android, HarmonyOS, or Vega VVD serial.',
serial: 'Android, HarmonyOS, or Vega serial.',
};
let pinned = 0;
for (const metadata of listCommandMetadata()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/command-surface/src/common-input-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const COMMON_INPUT_FIELDS = {
serial: {
schema: {
type: 'string',
description: 'Android, HarmonyOS, or Vega VVD serial.',
description: 'Android, HarmonyOS, or Vega serial.',
},
read: (record) => optionalString(record, 'serial'),
flagKey: 'serial',
Expand Down
5 changes: 4 additions & 1 deletion packages/contracts/src/interactor-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ export type KeyboardDismissResult =
visible?: boolean;
mechanism?: string;
}>
| Readonly<{ kind: 'acknowledged' }>;
| Readonly<{ kind: 'acknowledged' }>
// Vega's Back either closes a keyboard that was open or finds none open, and a keyboard that stays
// open after Back throws rather than reporting a failed dismissal, so one boolean is the whole fact.
| Readonly<{ kind: 'vega-back'; dismissed: boolean }>;

/**
* Only the Apple runner echoes visibility around the return-key press; Android and HarmonyOS
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts/src/snapshot-producers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type KnownSnapshotProducer =
| 'harmonyos-uitest'
| 'macos-helper'
| 'linux-atspi'
| 'vega-automation-toolkit'
| 'agent-browser';

export type SnapshotProducer = KnownSnapshotProducer;
Expand Down Expand Up @@ -189,6 +190,15 @@ export const SNAPSHOT_PRODUCERS = {
refs: 'dense',
sparseRootWarning: 'none',
},
'vega-automation-toolkit': {
channels: ['linux-atspi'],
truncation: 'available',
residue: 'source-measured',
quietMs: GENERAL_QUIET_MS,
orderedAcquisition: false,
refs: 'dense',
sparseRootWarning: 'none',
},
'agent-browser': {
channels: ['web'],
truncation: 'available',
Expand Down
36 changes: 36 additions & 0 deletions packages/daemon/src/execution/__tests__/keyboard-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,42 @@ test('iOS dismiss reports the mechanism disclosure and its own message', async (
});
});

test.each([
[true, 'Keyboard dismissed'],
[false, 'No keyboard was open'],
])('Vega dismiss with dismissed %s answers %s', async (dismissed, message) => {
const vegaDevice: DeviceInfo = {
id: 'keyboard-runtime-vega',
name: 'Vega Virtual Device',
platform: 'vega',
kind: 'emulator',
target: 'tv',
booted: true,
};
const harness = runtimeHarness(vegaDevice, 'vega', {
unsupported: unavailable,
dismiss: available,
enter: available,
});
harness.keyboardDismiss.mockResolvedValue({ kind: 'vega-back', dismissed });

const resolved = await resolveBoundKeyboardRuntime({
platformServices: daemonPlatformServicesFixture(),
device: vegaDevice,
positionals: ['dismiss'],
inspectFacts: harness.inspectFacts,
bindDevice: harness.bindDevice,
});
expect(resolved.ok).toBe(true);
if (!resolved.ok) return;
expect(await resolved.execute({})).toEqual({
platform: 'vega',
action: 'dismiss',
dismissed,
message,
});
});

// #1598: the response must disclose which mechanism the runner used to resign the keyboard —
// only the keyboard's own dismiss key is a mechanism the runner vouches for; an unrecognized wire
// value must degrade to the bare message rather than a false claim.
Expand Down
11 changes: 10 additions & 1 deletion packages/daemon/src/execution/keyboard-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ const KEYBOARD_STATUS_PLATFORM_LABEL: Record<

const KEYBOARD_DISMISS_PLATFORM_LABEL: Record<
KeyboardDismissResult['kind'],
'android' | 'harmonyos' | 'ios'
'android' | 'harmonyos' | 'ios' | 'vega'
> = {
'ime-probe': 'android',
mechanism: 'ios',
acknowledged: 'harmonyos',
'vega-back': 'vega',
};

const KEYBOARD_ENTER_PLATFORM_LABEL: Record<
Expand Down Expand Up @@ -198,6 +199,14 @@ async function executeKeyboardDismiss(
if (result.kind === 'acknowledged') {
return { platform, action: 'dismiss', ...successText('Keyboard dismissed') };
}
if (result.kind === 'vega-back') {
return {
platform,
action: 'dismiss',
dismissed: result.dismissed,
...successText(result.dismissed ? 'Keyboard dismissed' : 'No keyboard was open'),
};
}
return {
platform,
action: 'dismiss',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { screenshotCommandSurface as testCreateCommandSurface } from '../__tests
const unavailableCapture = Object.freeze({
available: false,
reason: 'unsupported-platform-leaf' as const,
hint: 'screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.',
hint: 'screenshot is not supported on Vega OS: it exposes an element tree, not an image.',
});

function screenshotRequest(overrides: Partial<DaemonRequest> = {}): DaemonRequest {
Expand Down
1 change: 1 addition & 0 deletions packages/host-kit/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export {
withCommandHost,
withoutCommandExecutorOverride,
} from './internal/exec.ts';
export { createCommandTimeoutError } from './internal/exec-timeout-error.ts';
export { EXEC_COMMAND_PHASE } from './internal/exec-trace.ts';
40 changes: 40 additions & 0 deletions packages/host-kit/src/internal/exec-timeout-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AppError } from '@agent-device/kernel/errors';

/**
* The timeout error {@link isCommandTimeoutError} classifies. A caller that kills a command at its
* own `timeoutMs` reports the same fact `runCmd` does, whichever route the command took. A caller
* that cannot attribute output to the killed command (a shared shell, say) leaves it empty.
*/
export function createCommandTimeoutError(
executable: string,
cmd: string,
args: readonly string[],
timeoutMs: number,
exitCode = 1,
stdout = '',
stderr = '',
): AppError {
// exec-guard-allow: deliberately no processExitError — "timed out after Nms"
// beats whatever partial stderr the killed process left behind.
return new AppError('COMMAND_FAILED', `${executable} timed out after ${timeoutMs}ms`, {
cmd,
args,
stdout,
stderr,
exitCode,
timeoutMs,
});
}

/**
* True only for the COMMAND_FAILED error raised at a command's own `timeoutMs`. Callers classify
* with this rather than matching the message text, so a command whose own output says "timed out"
* is not mistaken for one killed at its deadline.
*/
export function isCommandTimeoutError(error: unknown): error is AppError {
return (
error instanceof AppError &&
error.code === 'COMMAND_FAILED' &&
typeof error.details?.timeoutMs === 'number'
);
}
49 changes: 14 additions & 35 deletions packages/host-kit/src/internal/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import type {
ExecDetachedProcess,
} from './exec-types.ts';
import { createExecTraceContext, type ExecSettlementReason } from './exec-trace.ts';
import { createCommandTimeoutError } from './exec-timeout-error.ts';
import type { EnvMap, HostEnvironment } from '@agent-device/kernel/source-value';

export { isCommandTimeoutError } from './exec-timeout-error.ts';

export type {
CommandExecutorOverride,
ExecDetachedChannel,
Expand Down Expand Up @@ -274,7 +277,17 @@ function runSpawnedCommand(
if (!finish(finalReason)) return;
const finalExitCode = code ?? 1;
if (!abort.didAbort && didTimeout && timeoutMs) {
reject(createTimeoutError(executable, cmd, args, timeoutMs, finalExitCode, stdout, stderr));
reject(
createCommandTimeoutError(
executable,
cmd,
args,
timeoutMs,
finalExitCode,
stdout,
stderr,
),
);
return;
}
const failure = commandCloseFailure(
Expand Down Expand Up @@ -678,40 +691,6 @@ function createStdinError(
);
}

function createTimeoutError(
executable: string,
cmd: string,
args: readonly string[],
timeoutMs: number,
exitCode: number,
stdout: string,
stderr: string,
): AppError {
// exec-guard-allow: deliberately no processExitError — "timed out after Nms"
// beats whatever partial stderr the killed process left behind.
return new AppError('COMMAND_FAILED', `${executable} timed out after ${timeoutMs}ms`, {
cmd,
args,
stdout,
stderr,
exitCode,
timeoutMs,
});
}

/**
* True only for the COMMAND_FAILED error this module raises when it kills a command at
* its own `timeoutMs`. Callers classify with this rather than matching the message text,
* so a command whose own output says "timed out" is not mistaken for one exec killed.
*/
export function isCommandTimeoutError(error: unknown): error is AppError {
return (
error instanceof AppError &&
error.code === 'COMMAND_FAILED' &&
typeof error.details?.timeoutMs === 'number'
);
}

function createExitError(
executable: string,
cmd: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/kernel/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,12 @@ function serialDeviceNotFoundMessage(selector: DeviceSelector): string {
return `No Android device with serial ${selector.serial}`;
}
if (selector.platform === 'vega') {
return `No Vega VVD with serial ${selector.serial}`;
return `No Vega device with serial ${selector.serial}`;
}
if (selector.platform === 'harmonyos') {
return `No HarmonyOS device with serial ${selector.serial}`;
}
return `No Android, HarmonyOS device, or Vega VVD with serial ${selector.serial}`;
return `No Android, HarmonyOS, or Vega device with serial ${selector.serial}`;
}

function throwNoDevicesFound(selector: DeviceSelector, context: DeviceSelectionContext): never {
Expand Down
3 changes: 2 additions & 1 deletion packages/platform-vega/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@agent-device/contracts": "workspace:*",
"@agent-device/host-kit": "workspace:*",
"@agent-device/kernel": "workspace:*",
"@agent-device/provision-kit": "workspace:*"
"@agent-device/provision-kit": "workspace:*",
"@agent-device/xml": "workspace:*"
},
"exports": {
".": {
Expand Down
3 changes: 3 additions & 0 deletions packages/platform-vega/src/__tests__/app-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ test('Vega app lifecycle uses the SDK device commands with an explicit serial',
commands.push(args);
return { exitCode: 0, stdout: '', stderr: '' };
},
runOnDevice: async () => {
throw new Error('no device shell command expected');
},
});

await withVegaToolProvider(provider, async () => {
Expand Down
76 changes: 76 additions & 0 deletions packages/platform-vega/src/__tests__/automation-toolkit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';
import { AppError } from '@agent-device/kernel/errors';
import { callVegaToolkit } from '../automation-toolkit.ts';
import { createLocalVegaToolProvider, withVegaToolProvider } from '../tool-provider.ts';

const DEVICE = { id: 'VirtualDevice' };

function answering(reply: unknown, exitCode = 0) {
return withVegaToolProvider(
createLocalVegaToolProvider({
isAvailable: async () => true,
run: async () => ({ exitCode: 0, stdout: '', stderr: '' }),
runOnDevice: async () => ({
exitCode,
stdout: typeof reply === 'string' ? reply : JSON.stringify(reply),
stderr: '',
}),
}),
() => callVegaToolkit(DEVICE, 'click', { id: 7 }),
);
}

test('a toolkit reply is answered by its result', async () => {
assert.equal(await answering({ jsonrpc: '2.0', id: 1, result: true }), true);
});

test('a result of null is an answer, not a missing one: a stale element id answers getAttributes so', async () => {
assert.equal(await answering({ jsonrpc: '2.0', id: 1, result: null }), null);
});

test('a zero result is an answer, not a missing one: an unmatched find answers so', async () => {
assert.equal(await answering({ jsonrpc: '2.0', id: 1, result: 0 }), 0);
});

test('a refused call reports the message the toolkit itself gave', async () => {
await assert.rejects(
answering({ id: 1, error: { code: -32601, message: 'METHOD_NOT_FOUND: nope' } }),
(error: unknown) =>
error instanceof AppError &&
error.message.includes('refused click') &&
error.details?.reason === 'METHOD_NOT_FOUND: nope',
);
});

test('an error member that is null is not a refusal and does not throw a raw TypeError', async () => {
assert.equal(await answering({ jsonrpc: '2.0', id: 1, error: null, result: false }), false);
});

test('a reply with neither result nor error refuses rather than answering undefined', async () => {
await assert.rejects(
answering({ jsonrpc: '2.0', id: 1 }),
(error: unknown) =>
error instanceof AppError &&
error.code === 'COMMAND_FAILED' &&
/neither a result nor an error/.test(error.message),
);
});

test('a reply that is not JSON refuses without quoting the device output back', async () => {
const leaked = '<html>500 Internal Server Error {"partial":"secret-page-source"}</html>';
await assert.rejects(
answering(leaked),
(error: unknown) =>
error instanceof AppError &&
!JSON.stringify(error.details).includes('secret-page-source') &&
!JSON.stringify(error.details).includes('500 Internal Server Error'),
);
});

test('a device command that failed is reported before its reply is read', async () => {
await assert.rejects(
answering({ result: true }, 1),
/The Vega Automation Toolkit failed to click/,
);
});
Loading
Loading