Skip to content

Commit be48a28

Browse files
committed
test(alerts): pin the press cutoff's dispatched disclosure; review nits
The independent review of f584e8a returned merge-ready with three follow-up-scale findings, batched here: - The documented `dispatched: 'unknown'` press-cutoff failure had no test. Pinned in the Android suite with the real transport shape: the adb fake hangs the tap until the 2s action window closes and dies with the signal; the failure must disclose unknown, never 'no'. Mutation-checked: flipping the disclosure to 'no' fails the pin. - The `[timeout]` positional is honored by `alert wait` only — the Apple acting legs pass fixed runner budgets and the tree legs run their own lookup/confirm windows; commands.md now says the argument is wait-only per backend instead of leaving the silence to surprise callers. - `void device;` in limrunAlertOperationFacts follows the `_device` convention; the two byte-identical visible-after-press exits collapse into one helper, keeping the two hints that genuinely differ (latest read hung vs budget ended unresolved). No behavior change for any message, reason, or tap.
1 parent 71087fb commit be48a28

4 files changed

Lines changed: 61 additions & 24 deletions

File tree

‎packages/platform-android/src/__tests__/alert.test.ts‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import { isRequestCanceledError } from '@agent-device/kernel/errors';
66
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
77
import { button, node, text } from './alert-fixtures.ts';
88

9-
const runAndroidAdb = vi.fn(async (_device: DeviceInfo, _args: readonly string[]) => ({
10-
exitCode: 0,
11-
stdout: '',
12-
stderr: '',
13-
}));
9+
type FakeShellOptions = { signal?: AbortSignal };
10+
const runAndroidAdb = vi.fn(
11+
async (_device: DeviceInfo, _args: readonly string[], _options?: FakeShellOptions) => ({
12+
exitCode: 0,
13+
stdout: '',
14+
stderr: '',
15+
}),
16+
);
1417
const runAndroidShell = vi.fn(
15-
async (device: DeviceInfo, words: ShellWord[]) =>
16-
await runAndroidAdb(device, deviceShellArgv('adb', 'shell', words)),
18+
async (device: DeviceInfo, words: ShellWord[], options?: FakeShellOptions) =>
19+
await runAndroidAdb(device, deviceShellArgv('adb', 'shell', words), options),
1720
);
1821
vi.mock('../adb.ts', () => ({ runAndroidAdb, runAndroidShell }));
1922

@@ -198,6 +201,38 @@ test('wait with a spent budget still reports an alert that is already visible',
198201
assert.equal(result.alert?.title, 'Automation confirmation');
199202
});
200203

204+
test('a press cut off mid-flight discloses that it may or may not have landed', async () => {
205+
// The one typed exit that must never collapse into 'no': the adb child is killed between
206+
// the tap's dispatch and its rejection, so the device may already have received it. The
207+
// press hangs until the action window's 2 s closes, then the child dies with the signal.
208+
runAndroidAdb.mockClear();
209+
const tapSignals: (AbortSignal | undefined)[] = [];
210+
runAndroidAdb.mockImplementationOnce(async (_device, args, options) => {
211+
if (args.includes('tap')) {
212+
tapSignals.push(options?.signal);
213+
await new Promise<void>((_resolve, reject) => {
214+
options?.signal?.addEventListener('abort', () => reject(new Error('adb killed')), {
215+
once: true,
216+
});
217+
});
218+
}
219+
return { exitCode: 0, stdout: '', stderr: '' };
220+
});
221+
222+
await assert.rejects(
223+
handleAndroidAlert(device, 'dismiss', { captureNodes: dialogUntilPressed() }),
224+
(error: unknown) =>
225+
error instanceof Error &&
226+
error.message ===
227+
'alert dismiss was cut off while pressing; the press may or may not have landed' &&
228+
(error as { details?: { dispatched?: unknown; reason?: unknown } }).details?.dispatched ===
229+
'unknown' &&
230+
(error as { details?: { reason?: unknown } }).details?.reason === 'alert-window-expired',
231+
);
232+
assert.equal(tapSignals.length, 1);
233+
assert.equal(tapSignals[0]?.aborted, true);
234+
});
235+
201236
test('the read-first capture rides the caller cancellation and dies with it', async () => {
202237
// Android's transport is cancellable, so the invariant here is the actual child-process cut:
203238
// the capture seam receives the leg's live AbortSignal, and aborting the caller cuts the

‎packages/platform-android/src/alert.ts‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,7 @@ async function confirmTreeAlertDismissed<
523523
// when no completed post-press read named it — the 2482e24 Android smoke case, where the
524524
// confirm phase never got one answer — may the leg say the press went unconfirmed.
525525
if (isAlertWindowExpired(error)) {
526-
if (lastCaptureNamesAlert) {
527-
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
528-
alert: dismissed,
529-
reason: ALERT_WINDOW_EXPIRED_REASON,
530-
hint: 'The alert button was pressed but the dialog was visible on the last check that answered. Inspect alert get --json, then press the visible button by label/ref or retry.',
531-
});
532-
}
526+
if (lastCaptureNamesAlert) throw visibleAfterPressFailure(action, dismissed);
533527
throw new AppError(
534528
'COMMAND_FAILED',
535529
`alert ${action} pressed the button but the dismissal could not be confirmed`,
@@ -543,13 +537,7 @@ async function confirmTreeAlertDismissed<
543537
throw error;
544538
}
545539
if (settled) return;
546-
if (lastCaptureNamesAlert) {
547-
throw new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
548-
alert: dismissed,
549-
reason: ALERT_WINDOW_EXPIRED_REASON,
550-
hint: 'The alert button was pressed but the dialog was visible on the last check that answered. Inspect alert get --json, then press the visible button by label/ref or retry.',
551-
});
552-
}
540+
if (lastCaptureNamesAlert) throw visibleAfterPressFailure(action, dismissed);
553541
throw new AppError(
554542
'COMMAND_FAILED',
555543
`alert ${action} pressed the button but the dismissal could not be confirmed`,
@@ -561,6 +549,21 @@ async function confirmTreeAlertDismissed<
561549
);
562550
}
563551

552+
/**
553+
* The stuck-alert failure: a post-press capture that answered named the same dialog again, so
554+
* the press did not dismiss what the latest completed read still saw on screen.
555+
*/
556+
function visibleAfterPressFailure<TAlert extends AlertInfo & { buttons: string[] }>(
557+
action: 'accept' | 'dismiss',
558+
dismissed: TAlert,
559+
): AppError {
560+
return new AppError('COMMAND_FAILED', `alert ${action} did not dismiss the visible alert`, {
561+
alert: dismissed,
562+
reason: ALERT_WINDOW_EXPIRED_REASON,
563+
hint: 'The alert button was pressed but the dialog was visible on the last check that answered. Inspect alert get --json, then press the visible button by label/ref or retry.',
564+
});
565+
}
566+
564567
/** Alert identity across a dismissal re-check: the same title and the same button row, in order. */
565568
function sameTreeAlert(
566569
left: AlertInfo & { buttons: string[] },

‎packages/provider-limrun/src/interaction-operations.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,9 @@ export function limrunClipboardOperationFacts(
276276
* both legs of a live session.
277277
*/
278278
export function limrunAlertOperationFacts(
279-
device: DeviceInfo,
279+
_device: DeviceInfo,
280280
liveSessionUnavailable?: RuntimeOperationUnavailability,
281281
) {
282-
void device;
283282
const cell = liveSessionUnavailable ?? available;
284283
return Object.freeze({
285284
...alertRuntimeOperationFacts({ read: cell, wait: cell, accept: cell, dismiss: cell }),

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ agent-device alert dismiss
397397
- `wait_stable_timeout`: the UI did not settle.
398398
- Branch on `readableCaptures`, `waitedMs`, `matches`, and `firstMatch` instead of parsing error text. `firstMatch` carries identity and text only; absence failures make no visibility or rect claim.
399399
- Polling wait timeouts, and a replayed wait refused with `wait_landmark_identity_mismatch`, also carry `captures`, `readableCaptures`, and `polls` so you can see where the budget went. Each poll has `startedMs`, `durationMs`, and an `outcome`: `readable`, `unreadable`, `retriable`, `deadline`, `runner-restart`, or `readiness`. Long waits keep the first 5 and last 25 polls. A wait that never saw a readable capture reports the error its polls hit, with that error's code and retry details, instead of a generic timeout; `wait stable` and a never-readable strict absence keep their own diagnostics. `logPath` links the full request log.
400-
- `alert` (same as `alert get`) inspects or handles system alerts on iOS simulator, macOS desktop, and Android permission dialogs. On iOS it also covers app-owned modal popups with native blocking markers. `alert wait <ms>` takes a budget up to 2147483647 ms (~24.8 days); larger is refused as `INVALID_ARGS` before anything runs.
400+
- `alert` (same as `alert get`) inspects or handles system alerts on iOS simulator, macOS desktop, and Android permission dialogs. On iOS it also covers app-owned modal popups with native blocking markers. The `[timeout]` argument applies to `alert wait` only, on every backend: `alert wait <ms>` takes a budget up to 2147483647 ms (~24.8 days), larger is refused as `INVALID_ARGS` before anything runs, while `get`/`accept`/`dismiss` run their own fixed per-backend budgets and ignore it.
401401
- On the snapshot-derived backends (Android, Limrun iOS) `alert get --json` answers with a typed `status`: `visible`, `none`, or `undecided` (an alert-shaped capture that resolves to no single alert). Branch on `status`, not on the message.
402402
- On those backends, when `alert accept`/`dismiss` fails, `error.details.reason` names why. Before any press, `dispatched: no` and the reason is `alert-not-found` (the action budget passed with no alert seen), `alert-window-expired` (the budget closed before a capture or the press could resolve), `alert_capture_undecided`, or `alert_button_undecided` (the sheet is too ambiguous to act on). After a press, `dispatched` is absent and the reason is `alert-window-expired`; “did not dismiss the visible alert” means the latest post-press capture that answered named the same dialog again, “could not be confirmed” means the press went out but the latest read was unresolvable or never answered, so the dialog may already be gone; `dispatched: unknown` means the press itself was cut off and may have landed. Run `alert get` before acting again.
403403
- On Android, an alert capture that outlives its budget is stopped in flight. On Limrun the transport cannot cancel a request: the command refuses a late answer and presses nothing, but a hung capture can keep running after the command has already failed. If Limrun alert commands stall, restart the instance session.

0 commit comments

Comments
 (0)