@@ -2,6 +2,8 @@ import assert from 'node:assert/strict';
22import fs from 'node:fs' ;
33import path from 'node:path' ;
44
5+ import { DEFAULT_ALERT_TIMEOUT_MS } from '@agent-device/contracts/interaction' ;
6+
57import { PUBLIC_COMMANDS } from '../../../src/command-catalog.ts' ;
68import {
79 assertElementText ,
@@ -13,6 +15,7 @@ import { clearStateLaunchUrlMaestroFlow } from './live-fixtures.ts';
1315import { type LiveContext , runStep , verifyBehavior , verifyCommand } from './live-harness.ts' ;
1416
1517const C = PUBLIC_COMMANDS ;
18+ const ALERT_WAIT_TIMEOUT = String ( DEFAULT_ALERT_TIMEOUT_MS ) ;
1619const FIXTURE_HOME_TITLE = 'Agent Device Tester' ;
1720const AUTOMATION_DEEP_LINK =
1821 'agent-device-test-app:///automation?event=cold.start&payload=%7B%22source%22%3A%22deep-link%22%7D' ;
@@ -33,6 +36,22 @@ async function observeFixtureHome(context: LiveContext) {
3336 return snapshot ;
3437}
3538
39+ async function assertAutomationAlertTriggerVisible ( context : LiveContext ) : Promise < void > {
40+ const visible = await runStep ( context , 'assert automation-open-alert is visible' , [
41+ 'is' ,
42+ 'visible' ,
43+ 'id="automation-open-alert"' ,
44+ ] ) ;
45+ assert . equal ( visible . json ?. data ?. pass , true , JSON . stringify ( visible . json ) ) ;
46+ }
47+
48+ async function openNativeAlert ( context : LiveContext , step : string ) : Promise < void > {
49+ await assertAutomationAlertTriggerVisible ( context ) ;
50+ await runStep ( context , step , [ 'click' , 'id="automation-open-alert"' ] ) ;
51+ // The canary proves JS ran and the state update is observable; alert wait proves native presentation.
52+ await assertWaitText ( context , 'Alert result: opened' ) ;
53+ }
54+
3655export async function assertAutomationInput ( context : LiveContext ) : Promise < void > {
3756 const opened = await runStep ( context , 'cold launch fixture' , [
3857 'open' ,
@@ -153,15 +172,28 @@ export async function assertAutomationInput(context: LiveContext): Promise<void>
153172 'id="automation-open-alert"' ,
154173 'Open automation alert' ,
155174 ) ;
156- await runStep ( context , 'open native alert' , [ 'click' , 'id="automation-open-alert"' ] ) ;
157- await assertWaitText ( context , 'Alert result: opened' ) ;
158- const alert = await runStep ( context , 'wait for native alert' , [ 'alert' , 'wait' , '10000' ] ) ;
175+ await openNativeAlert ( context , 'open native alert' ) ;
176+ const alert = await runStep ( context , 'wait for native alert' , [
177+ 'alert' ,
178+ 'wait' ,
179+ ALERT_WAIT_TIMEOUT ,
180+ ] ) ;
159181 assertJsonContains ( alert , 'Automation confirmation' , 'alert wait should return fixture alert' ) ;
160182 await runStep ( context , 'inspect native alert' , [ 'alert' , 'get' ] ) ;
161183 await runStep ( context , 'dismiss native alert' , [ 'alert' , 'dismiss' ] ) ;
162184 await assertWaitText ( context , 'Alert result: cancelled' ) ;
163185
164- await runStep ( context , 'reopen native alert' , [ 'click' , 'id="automation-open-alert"' ] ) ;
186+ await openNativeAlert ( context , 'reopen native alert' ) ;
187+ const reopenedAlert = await runStep ( context , 'wait for reopened native alert' , [
188+ 'alert' ,
189+ 'wait' ,
190+ ALERT_WAIT_TIMEOUT ,
191+ ] ) ;
192+ assertJsonContains (
193+ reopenedAlert ,
194+ 'Automation confirmation' ,
195+ 'alert wait should return the reopened fixture alert' ,
196+ ) ;
165197 await runStep ( context , 'accept native alert' , [ 'alert' , 'accept' ] ) ;
166198 await assertWaitText ( context , 'Alert result: accepted' ) ;
167199 verifyCommand ( context , C . alert , 'alert wait/get/dismiss/accept produce both fixture outcomes' ) ;
0 commit comments