Skip to content

Commit f80dc2c

Browse files
committed
fix(conformance): isolate post-tap settling from app launch
1 parent 527a56a commit f80dc2c

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

‎packages/maestro/test/conformance/differential/flows/settle-after-tap.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ appId: com.callstack.agentdevicelab
77
- launchApp:
88
clearState: true
99
- assertVisible: Agent Device Tester
10+
# Discharge launch stabilization before measuring the inline post-tap settle.
11+
- waitForAnimationToEnd
1012
- tapOn:
1113
text: Settings
1214
retryTapIfNoChange: true

‎packages/maestro/test/conformance/differential/invariants.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ function assertSettleFlowSemantics(source: string): void {
185185
parsed.commands.filter((command) => command.kind === 'tap'),
186186
[{ kind: 'tap', longPress: false, repeat: 1, target: { selector: { text: 'Settings' } } }],
187187
);
188-
const tap = program.commands.find((command) => command.kind === 'tapOn');
188+
const tapIndex = program.commands.findIndex((command) => command.kind === 'tapOn');
189+
assert.equal(program.commands[tapIndex - 1]?.kind, 'waitForAnimationToEnd');
190+
const tap = program.commands[tapIndex];
189191
assert.equal(tap?.kind, 'tapOn');
190192
assert.equal(tap?.retryTapIfNoChange, true);
191193
assert.equal(
@@ -199,7 +201,7 @@ function assertSettleFlowSemantics(source: string): void {
199201
);
200202
}
201203

202-
test('the settle detector reaches its tap without an unrelated setup command', () => {
204+
test('the settle detector isolates its tap from launch stabilization', () => {
203205
assertSettleFlowSemantics(fs.readFileSync(SETTLE_FLOW_PATH, 'utf8'));
204206
});
205207

@@ -208,6 +210,7 @@ test('the settle flow guard rejects a changed tap target, disabled retry, or ins
208210
assert.throws(() => assertSettleFlowSemantics(flow.replace('text: Settings', 'text: Home')));
209211
assert.throws(() => assertSettleFlowSemantics(flow.replace(/\n\s*retryTapIfNoChange: true/, '')));
210212
assert.throws(() => assertSettleFlowSemantics(flow.replace('- tapOn:', '- scroll\n- tapOn:')));
213+
assert.throws(() => assertSettleFlowSemantics(flow.replace('- waitForAnimationToEnd\n', '')));
211214
});
212215

213216
// --- metricAtLeast: proves a code path actually ran, not just that it passed ---

‎src/daemon/adapters/maestro/__tests__/daemon-runtime-port-targets.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { expect, test } from 'vitest';
22
import { promises as fs } from 'node:fs';
33
import { PNG } from '@agent-device/capture-kit/png';
4+
import { executeMaestroFlow, inspectMaestroFlow } from '@agent-device/maestro';
5+
import { noMaestroIncludeSources } from '../../../../__tests__/test-utils/replay-script-source.ts';
46
import type { DaemonInvokeFn, DaemonRequest } from '../../../daemon-request.ts';
57
import { createDaemonMaestroRuntimePort } from '../daemon-runtime-port.ts';
68
import { makeBaseRequest, makeDependencies } from './daemon-runtime-port-fixtures.ts';
@@ -401,3 +403,78 @@ function solidPng(value: number): Buffer {
401403
image.data.fill(value);
402404
return PNG.sync.write(image);
403405
}
406+
407+
test('the differential settle flow excludes a slow launch boundary from tap metrics', async () => {
408+
const flowPath = 'packages/maestro/test/conformance/differential/flows/settle-after-tap.yaml';
409+
const source = await fs.readFile(flowPath, 'utf8');
410+
const clock = { value: 0 };
411+
let captures = 0;
412+
let clicked = false;
413+
const screenshot = PNG.sync.write(new PNG({ width: 1, height: 1 }));
414+
const port = createDaemonMaestroRuntimePort({
415+
baseReq: makeBaseRequest({ flags: { platform: 'ios', replayBackend: 'maestro' } }),
416+
platform: 'ios',
417+
dependencies: makeDependencies(clock),
418+
invoke: async (request) => {
419+
if (request.command === 'click') clicked = true;
420+
if (request.command === 'screenshot') {
421+
await fs.writeFile(request.positionals[0]!, screenshot);
422+
}
423+
if (request.command !== 'snapshot') return { ok: true, data: {} };
424+
captures += 1;
425+
clock.value += 2_100;
426+
return {
427+
ok: true,
428+
data: {
429+
createdAt: captures,
430+
nodes: [
431+
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 } },
432+
{
433+
index: 1,
434+
parentIndex: 0,
435+
type: 'Text',
436+
label: 'Agent Device Tester',
437+
rect: { x: 0, y: 0, width: 300, height: 30 },
438+
},
439+
{
440+
index: 2,
441+
parentIndex: 0,
442+
type: 'Button',
443+
label: 'Settings',
444+
rect: { x: 20, y: 40, width: 120, height: 44 },
445+
},
446+
{
447+
index: 3,
448+
parentIndex: 0,
449+
type: 'Text',
450+
value: clicked ? 'ready' : `launch frame ${captures}`,
451+
},
452+
...(clicked
453+
? [
454+
{
455+
index: 4,
456+
parentIndex: 0,
457+
type: 'Button',
458+
identifier: 'open-inert-surface',
459+
rect: { x: 20, y: 100, width: 120, height: 44 },
460+
},
461+
]
462+
: []),
463+
],
464+
},
465+
};
466+
},
467+
});
468+
let tapMetrics: unknown;
469+
const result = await executeMaestroFlow(inspectMaestroFlow(source, flowPath), port, {
470+
readSource: noMaestroIncludeSources,
471+
observer: {
472+
actionCompleted: (event) => {
473+
if (event.action === 'tapOn') tapMetrics = event.runtimeMetrics;
474+
},
475+
},
476+
});
477+
expect(result, JSON.stringify(result)).toMatchObject({ ok: true });
478+
expect(clicked).toBe(true);
479+
expect(tapMetrics).toMatchObject({ hierarchyCaptures: 2, settleLatches: 1, settleTimeouts: 0 });
480+
});

0 commit comments

Comments
 (0)