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
15 changes: 15 additions & 0 deletions src/compat/maestro/__tests__/replay-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ test('parseMaestroReplayFlow preserves selector state and absolute swipe command
assert.deepEqual(parsed.actionLines, [3, 6]);
});

test('parseMaestroReplayFlow maps extendedWaitUntil.notVisible through Maestro visibility assertions', () => {
const parsed = parseMaestroReplayFlow(`appId: com.callstack.agentdevicelab
---
- extendedWaitUntil:
notVisible:
text: Loading
timeout: 1200
`);

assert.deepEqual(
parsed.actions.map((entry) => [entry.command, entry.positionals]),
[['__maestroAssertNotVisible', ['label="Loading" || text="Loading" || id="Loading"', '1200']]],
);
});

test('parseMaestroReplayFlow rejects deferred Maestro utility commands loudly', () => {
assert.throws(
() => parseMaestroReplayFlow('---\n- assertTrue: "${READY}"\n'),
Expand Down
90 changes: 86 additions & 4 deletions src/compat/maestro/__tests__/runtime-assertions.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import assert from 'node:assert/strict';
import { afterEach, test, vi } from 'vitest';
import { invokeMaestroAssertNotVisible, invokeMaestroAssertVisible } from '../runtime-assertions.ts';
import {
invokeMaestroAssertNotVisible,
invokeMaestroAssertVisible,
} from '../runtime-assertions.ts';
import type { DaemonRequest, DaemonResponse } from '../../../daemon/types.ts';

afterEach(() => {
vi.restoreAllMocks();
vi.useRealTimers();
});

test('invokeMaestroAssertVisible takes a terminal snapshot when the last miss started before the deadline', async () => {
Expand Down Expand Up @@ -56,6 +60,56 @@ test('invokeMaestroAssertVisible takes a terminal snapshot when the last miss st
}
});

test('invokeMaestroAssertVisible retries transient snapshot failures until a later match', async () => {
vi.useFakeTimers();

let snapshots = 0;
const responsePromise = invokeMaestroAssertVisible({
baseReq: {
token: 't',
session: 's',
flags: { platform: 'android' },
},
positionals: ['label="Ready"', '1000'],
invoke: async (): Promise<DaemonResponse> => {
snapshots += 1;
if (snapshots === 1) {
return {
ok: false,
error: { code: 'SNAPSHOT_FAILED', message: 'Snapshot temporarily unavailable.' },
};
}
return {
ok: true,
data: {
createdAt: 2,
nodes: [
{
index: 1,
ref: 'e1',
type: 'android.widget.TextView',
label: 'Ready',
rect: { x: 10, y: 20, width: 120, height: 40 },
depth: 8,
},
],
},
};
},
});

await vi.advanceTimersByTimeAsync(250);
const response = await responsePromise;

assert.equal(response.ok, true);
assert.equal(snapshots, 2);
if (response.ok) {
assert.ok(response.data);
assert.equal(response.data.nodeLabel, 'Ready');
assert.equal(response.data.waitedMs, 250);
}
});

test('invokeMaestroAssertNotVisible passes after a slow hidden sample exhausts the timeout', async () => {
vi.spyOn(Date, 'now').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(3500);

Expand All @@ -80,9 +134,10 @@ test('invokeMaestroAssertNotVisible passes after a slow hidden sample exhausts t
});

assert.equal(response.ok, true);
assert.deepEqual(calls.map((call) => [call.command, call.positionals]), [
['snapshot', []],
]);
assert.deepEqual(
calls.map((call) => [call.command, call.positionals]),
[['snapshot', []]],
);
if (response.ok) {
assert.ok(response.data);
assert.equal(response.data.stableSamples, 1);
Expand Down Expand Up @@ -125,3 +180,30 @@ test('invokeMaestroAssertNotVisible ignores matched nodes without visible rects'
assert.equal(response.data.stableSamples, 1);
}
});

test('invokeMaestroAssertNotVisible accepts timeout overrides for short extended waits', async () => {
vi.spyOn(Date, 'now').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(300);

const response = await invokeMaestroAssertNotVisible({
baseReq: {
token: 't',
session: 's',
flags: {},
},
positionals: ['id="toast"', '1'],
invoke: async (): Promise<DaemonResponse> => ({
ok: true,
data: {
createdAt: 1,
nodes: [],
},
}),
});

assert.equal(response.ok, true);
if (response.ok) {
assert.ok(response.data);
assert.equal(response.data.stableSamples, 1);
assert.equal(response.data.timeoutMs, 1);
}
});
2 changes: 1 addition & 1 deletion src/compat/maestro/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function convertExtendedWaitUntil(
const selector = maestroSelector(target, 'extendedWaitUntil', [], context);
const timeoutMs = String(readTimeoutMs(value, 30000));
if (value.notVisible !== undefined) {
return [action('wait', [timeoutMs]), action('is', ['hidden', selector])];
return [action(MAESTRO_RUNTIME_COMMAND.assertNotVisible, [selector, timeoutMs])];
}
return [action(MAESTRO_RUNTIME_COMMAND.assertVisible, [selector, timeoutMs])];
}
Expand Down
Loading
Loading