|
1 | 1 | import { expect, test } from 'vitest'; |
2 | 2 | import { promises as fs } from 'node:fs'; |
3 | 3 | 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'; |
4 | 6 | import type { DaemonInvokeFn, DaemonRequest } from '../../../daemon-request.ts'; |
5 | 7 | import { createDaemonMaestroRuntimePort } from '../daemon-runtime-port.ts'; |
6 | 8 | import { makeBaseRequest, makeDependencies } from './daemon-runtime-port-fixtures.ts'; |
@@ -401,3 +403,78 @@ function solidPng(value: number): Buffer { |
401 | 403 | image.data.fill(value); |
402 | 404 | return PNG.sync.write(image); |
403 | 405 | } |
| 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