Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion packages/maestro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"@agent-device/host-kit": "workspace:*",
"@agent-device/kernel": "workspace:*",
"@agent-device/provision-kit": "workspace:*",
"@agent-device/selectors": "workspace:*"
"@agent-device/selectors": "workspace:*",
"@eslint-community/regexpp": "4.12.2"
},
"exports": {
".": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,71 +113,95 @@ test('scrolls until the target is fully visible in the screen viewport', async (
expect(result.observation?.identity).toMatch(/^maestro-observation-/);
});

test('uses Maestro swipeFromCenter semantics inside the visible vertical container', async () => {
const requests: MaestroDaemonOperationRequest[] = [];
let snapshots = 0;
const port = createDaemonMaestroRuntimePort({
...makeRuntimeEnvelope({ flags: { platform: 'ios', replayBackend: 'maestro' } }),
invoke: async (request) => {
requests.push(request);
if (request.command !== 'snapshot') return { ok: true, data: {} };
snapshots += 1;
return {
ok: true,
data: {
createdAt: snapshots,
nodes: [
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } },
{
index: 1,
parentIndex: 0,
type: 'ScrollView',
rect: { x: 0, y: 100, width: 402, height: 650 },
},
...(snapshots < 3
? []
: [
{
index: 2,
parentIndex: 1,
type: 'Button',
identifier: 'home-open-form',
rect: { x: 20, y: 600, width: 180, height: 44 },
},
]),
],
},
};
},
dependencies: makeDependencies(),
platform: 'ios',
});
test.each([
{ name: 'absent target', undecidable: false, findsTarget: true },
{ name: 'undecidable target', undecidable: true, findsTarget: true },
{ name: 'undecidable target through the deadline', undecidable: true, findsTarget: false },
])(
'swipes inside the visible vertical container with an $name',
async ({ undecidable, findsTarget }) => {
const requests: MaestroDaemonOperationRequest[] = [];
let scrolled = false;
const port = createDaemonMaestroRuntimePort({
...makeRuntimeEnvelope({ flags: { platform: 'ios', replayBackend: 'maestro' } }),
invoke: async (request) => {
requests.push(request);
if (request.command === 'gesture') scrolled = true;
if (request.command !== 'snapshot') return { ok: true, data: {} };
return {
ok: true,
data: {
createdAt: 0,
nodes: [
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } },
{
index: 1,
parentIndex: 0,
type: 'ScrollView',
rect: { x: 0, y: 100, width: 402, height: 650 },
},
...(scrolled && findsTarget
? [
{
index: 2,
parentIndex: 1,
type: 'Button',
label: 'Open form',
rect: { x: 20, y: 600, width: 180, height: 44 },
},
]
: undecidable
? [
{
index: 2,
parentIndex: 1,
type: 'Text',
label: 'Terms and conditions\n'.repeat(800),
},
]
: []),
],
},
};
},
dependencies: makeDependencies(),
platform: 'ios',
});

await port.execute({
command: {
kind: 'scrollUntilVisible',
source: { line: 2 },
element: { id: 'home-open-form' },
direction: 'down',
timeout: 2_000,
},
generation: 0,
env: {},
invalidateObservation() {},
});
const result = port.execute({
command: {
kind: 'scrollUntilVisible',
source: { line: 2 },
element: { text: '.*Open form' },
direction: 'down',
timeout: 2_000,
},
generation: 0,
env: {},
invalidateObservation() {},
});

const gesture = requests.find(({ command }) => command === 'gesture');
expect(gesture).toMatchObject({
input: {
kind: 'pan',
origin: { x: 201, y: 425 },
delta: { x: 0, y: -260 },
durationMs: 601,
},
dispatch: { gestureViewport: { x: 0, y: 100, width: 402, height: 650 } },
});
expect(requests.some(({ command }) => command === 'scroll')).toBe(false);
});
if (findsTarget) {
await expect(result).resolves.toMatchObject({ observation: { matched: true } });
} else {
await expect(result).rejects.toMatchObject({
details: { reason: 'maestro_selector_regex_indeterminate' },
});
}

const gesture = requests.find(({ command }) => command === 'gesture');
expect(gesture).toMatchObject({
input: {
kind: 'pan',
origin: { x: 201, y: 425 },
delta: { x: 0, y: -260 },
durationMs: 601,
},
dispatch: { gestureViewport: { x: 0, y: 100, width: 402, height: 650 } },
});
expect(requests.some(({ command }) => command === 'scroll')).toBe(false);
},
);

test('ignores a larger scroll container that does not intersect the application viewport', async () => {
const requests: MaestroDaemonOperationRequest[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
maestroSnapshotSignature,
observeTypedMaestroCondition,
resolveTypedMaestroTarget,
scrollUntilTypedMaestroTarget,
waitForTypedSnapshotStability,
} from '../daemon-runtime-port-observation.ts';
import {
Expand Down Expand Up @@ -223,6 +224,124 @@ test('matches iOS Maestro ids on semantic nodes suppressed from interactive pres
).resolves.toMatchObject({ matched: true, visible: true, candidateCount: 1, ref: 'e2' });
});

test('retries an indeterminate regex observation until a later snapshot has a confirmed match', async () => {
const clock = { value: 0 };
let captures = 0;
const header = { index: 1, type: 'Text', label: 'Header\n'.repeat(10_000) };
const root = { index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } };
const ready = {
index: 2,
type: 'Text',
label: 'Ready',
rect: { x: 20, y: 40, width: 120, height: 44 },
};

const match = await observeTypedMaestroCondition({
condition: { kind: 'visible', selector: { text: '.*Ready' } },
timeoutMs: MAESTRO_OBSERVATION_POLL_MS,
context: { generation: 0, env: {} },
snapshot: async () => makeSnapshot(captures++ === 0 ? [root, header] : [root, header, ready]),
dependencies: makeDependencies(clock),
platform: 'android',
});

expect(match).toMatchObject({ matched: true, visible: true, ref: 'e3' });
expect(captures).toBe(2);
});

test('polls an indeterminate relational selector until its parent appears', async () => {
const clock = { value: 0 };
let captures = 0;
const root = { index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } };
const header = { index: 1, type: 'Text', label: 'Header\n'.repeat(10_000) };
const parent = {
index: 2,
type: 'Text',
label: 'Ready',
rect: { x: 20, y: 40, width: 120, height: 44 },
};
const row = {
index: 3,
parentIndex: 2,
type: 'Text',
identifier: 'row',
rect: { x: 20, y: 90, width: 120, height: 44 },
};

const match = await observeTypedMaestroCondition({
condition: { kind: 'visible', selector: { id: 'row', childOf: { text: '.*Ready' } } },
timeoutMs: MAESTRO_OBSERVATION_POLL_MS,
context: { generation: 0, env: {} },
snapshot: async () => makeSnapshot(captures++ === 0 ? [root, header] : [root, parent, row]),
dependencies: makeDependencies(clock),
platform: 'android',
});

expect(match).toMatchObject({ matched: true, visible: true, ref: 'e4' });
expect(captures).toBe(2);
});

test.each([
{
name: 'oversized multiline label',
selector: { text: '.*Ready' },
node: { index: 0, type: 'Text', label: 'Header\n'.repeat(10_000) },
},
{
name: 'clipped field in a complete snapshot',
selector: { text: 'Order is ready' },
node: { index: 0, type: 'EditText', label: 'Order is', value: 'Order is', textClipped: true },
},
])('does not report notVisible with a $name', async ({ selector, node }) => {
await expect(
observeTypedMaestroCondition({
condition: { kind: 'notVisible', selector },
timeoutMs: 0,
context: { generation: 0, env: {} },
snapshot: async () => ({ ...makeSnapshot([node]), truncated: false }),
dependencies: makeDependencies(),
platform: 'android',
}),
).rejects.toMatchObject({
details: { reason: 'maestro_selector_regex_indeterminate' },
});
});

test('scrolls past an indeterminate snapshot to a confirmed target', async () => {
const clock = { value: 0 };
let captures = 0;
let scrolls = 0;
const root = { index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } };
const header = { index: 1, type: 'Text', label: 'Header\n'.repeat(10_000) };
const ready = {
index: 2,
type: 'Text',
label: 'Ready',
rect: { x: 20, y: 40, width: 120, height: 44 },
};

const match = await scrollUntilTypedMaestroTarget({
selector: { text: '.*Ready' },
direction: 'down',
timeoutMs: MAESTRO_OBSERVATION_POLL_MS,
context: { generation: 0, env: {} },
snapshot: async () => {
captures += 1;
return makeSnapshot([root, header]);
},
scroll: async () => {
scrolls += 1;
return makeSnapshot([root, header, ready]);
},
dependencies: makeDependencies(clock),
platform: 'android',
});

expect(match).toMatchObject({ matched: true, visible: true, ref: 'e3' });
expect(captures).toBe(1);
expect(scrolls).toBe(1);
});

test('reports iOS Maestro evidence refs in semantic snapshot space after earlier suppression', async () => {
const snapshot = makeSnapshot([
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } },
Expand Down
Loading
Loading