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
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import assert from 'node:assert/strict';
import { test, vi } from 'vitest';
import { parseWaitPositionals } from '@agent-device/command-registry/wait-positionals';
import { createCommandSurfaceAgentDevice } from '@agent-device/command-runtime';
import { localCommandPolicy } from '@agent-device/contracts/command-policy';
import { createLocalArtifactAdapter } from '@agent-device/host-kit/local-artifact-adapter';
import { makeSnapshotState } from '@agent-device/selectors/snapshot-geometry-fixtures';
import { assertAutomationSystem } from './live-automation-scenario.ts';
import type { LiveContext } from './live-harness.ts';

const harness = vi.hoisted(() => ({
runStep: vi.fn(),
verifyCommand: vi.fn(),
verifyBehavior: vi.fn(),
}));
vi.mock('./live-harness.ts', () => harness);

test('catalog readiness waits until the automation screen has changed', async () => {
const previous = makeSnapshotState([
{ index: 0, depth: 0, type: 'android.widget.TextView', label: 'Automation lab' },
{
index: 1,
depth: 0,
type: 'android.widget.Button',
label: 'Continue to catalog',
identifier: 'automation-continue-catalog',
rect: { x: 90, y: 1642, width: 900, height: 124 },
},
]);
const catalog = makeSnapshotState([
{
index: 0,
depth: 0,
type: 'android.view.ViewGroup',
identifier: 'catalog-title',
rect: { x: 47, y: 419, width: 986, height: 286 },
},
{ index: 1, depth: 1, parentIndex: 0, type: 'android.widget.TextView', label: 'Catalog' },
{ index: 2, depth: 0, type: 'android.widget.Button', label: 'Settings', ref: 'e3' },
]);
let captures = 0;
let elapsed = 0;
const device = createCommandSurfaceAgentDevice({
backend: {
platform: 'android',
captureSnapshot: async () => ({ snapshot: captures++ === 0 ? previous : catalog }),
},
artifacts: createLocalArtifactAdapter({ cwd: process.cwd() }),
policy: localCommandPolicy(),
clock: {
now: () => elapsed,
sleep: async (ms) => {
elapsed += ms;
},
},
});
device.sessions.set({ name: 'default' });
const done = new Error('reached Settings navigation');
harness.runStep.mockImplementation(async (_context, _step, args: string[]) => {
const result = (data: unknown) => ({
status: 0,
stdout: '',
stderr: '',
json: { success: true, data },
});
if (args[0] === 'get')
return result({
text: args[2]?.includes('payload') ? '{"source":"android-deep-link"}' : 'cold.start',
});
if (args[0] === 'wait') {
const parsed = parseWaitPositionals(args.slice(1));
assert.ok(parsed && (parsed.kind === 'text' || parsed.kind === 'selector'));
const target =
parsed.kind === 'text'
? { kind: 'text' as const, text: parsed.text, timeoutMs: parsed.timeoutMs ?? 10000 }
: {
kind: 'selector' as const,
selector: parsed.selectorExpression,
timeoutMs: parsed.timeoutMs ?? 10000,
};
const waited = await device.selectors.wait({ session: 'default', target });
assert.equal(captures, 2, 'readiness must not complete on Automation lab');
return result(waited);
}
if (args[0] === 'snapshot')
return result({
nodes: catalog.nodes,
androidSnapshot: {
backend: 'android-helper',
helperTransport: 'persistent-session',
helperSessionReused: true,
},
});
if (args[0] === 'click' && args[1]?.startsWith('@')) throw done;
return result({});
});
await assert.rejects(assertAutomationSystem({} as LiveContext), (error) => error === done);
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function assertAutomationSystem(context: LiveContext): Promise<void
'click',
'id="automation-continue-catalog"',
]);
await assertWaitText(context, 'Catalog');
await assertWaitSelector(context, 'id="catalog-title"');
const catalogSnapshot = await runStep(context, 'capture Android catalog navigation', [
'snapshot',
'-i',
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export default defineConfig({
// The Android failed-step evidence reader: it replays adb output through the probe
// seam, so the crash/process/activity selectors need no emulator to be pinned.
'test/integration/android-emulator-e2e/device-evidence.test.ts',
'test/integration/android-emulator-e2e/live-automation-scenario.test.ts',
'test/integration/android-emulator-e2e/live-ime-window.test.ts',
// The frozen replay-compat corpus (#1417): parse-only, no device or
// subprocess work, so it belongs in the fast lane next to the
Expand Down
Loading