Skip to content

Commit 927f068

Browse files
committed
review: extract shared alert-test fixtures, trim narrated docblock
- Extract node/text/button RawSnapshotNode builders (near-duplicated between alert.test.ts and alert-detection.test.ts) into a sibling alert-fixtures.ts, reconciling the two button() signatures by keeping the optional `permission` param. Both suites now import from it. Planted red: bumped the shared button() rect width and reran both suites — 2 of 7 tests failed on the changed tap coordinates (alert.test.ts's dismiss/accept cases), confirming the fixtures are live-wired; reverted, suite back to 7/7 green. - Trim captureWaitTimeoutScreenshot's docblock in runtime.ts to the caller-facing contract only ("never throws, returns undefined on a failed capture"); the surface-dump rationale already lives in the PR body's Summary.
1 parent d6cb962 commit 927f068

4 files changed

Lines changed: 47 additions & 80 deletions

File tree

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from 'vitest';
22
import assert from 'node:assert/strict';
33
import { chooseAndroidAlertButton, findAndroidAlertCandidate } from '../alert-detection.ts';
4-
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
4+
import { button, node, text } from './alert-fixtures.ts';
55

66
test('chooseAndroidAlertButton prefers platform ids over ambiguous labels', () => {
77
const candidate = findAndroidAlertCandidate([
@@ -58,41 +58,3 @@ test('chooseAndroidAlertButton accepts a single neutral button', () => {
5858

5959
assert.equal(chooseAndroidAlertButton(candidate?.buttons ?? [], 'accept')?.label, 'Later');
6060
});
61-
62-
function node(
63-
index: number,
64-
type: string,
65-
overrides: Partial<RawSnapshotNode> = {},
66-
): RawSnapshotNode {
67-
return {
68-
index,
69-
parentIndex: index === 0 ? undefined : 0,
70-
type,
71-
bundleId: 'com.example.app',
72-
...overrides,
73-
};
74-
}
75-
76-
function text(index: number, label: string, identifier: string, parentIndex = 0): RawSnapshotNode {
77-
return node(index, 'android.widget.TextView', { label, identifier, parentIndex });
78-
}
79-
80-
function button(
81-
index: number,
82-
label: string,
83-
identifier: string,
84-
origin: { x: number; y: number },
85-
permission = false,
86-
parentIndex = 0,
87-
): RawSnapshotNode {
88-
const packageName = permission ? 'com.google.android.permissioncontroller' : 'com.example.app';
89-
const id = permission ? `com.android.permissioncontroller:id/${identifier}` : identifier;
90-
return node(index, 'android.widget.Button', {
91-
label,
92-
identifier: id,
93-
bundleId: packageName,
94-
parentIndex,
95-
rect: { ...origin, width: 128, height: 52 },
96-
hittable: true,
97-
});
98-
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
2+
3+
export function node(
4+
index: number,
5+
type: string,
6+
overrides: Partial<RawSnapshotNode> = {},
7+
): RawSnapshotNode {
8+
return {
9+
index,
10+
parentIndex: index === 0 ? undefined : 0,
11+
type,
12+
bundleId: 'com.example.app',
13+
...overrides,
14+
};
15+
}
16+
17+
export function text(
18+
index: number,
19+
label: string,
20+
identifier: string,
21+
parentIndex = 0,
22+
): RawSnapshotNode {
23+
return node(index, 'android.widget.TextView', { label, identifier, parentIndex });
24+
}
25+
26+
export function button(
27+
index: number,
28+
label: string,
29+
identifier: string,
30+
origin: { x: number; y: number },
31+
permission = false,
32+
parentIndex = 0,
33+
): RawSnapshotNode {
34+
const packageName = permission ? 'com.google.android.permissioncontroller' : 'com.example.app';
35+
const id = permission ? `com.android.permissioncontroller:id/${identifier}` : identifier;
36+
return node(index, 'android.widget.Button', {
37+
label,
38+
identifier: id,
39+
bundleId: packageName,
40+
parentIndex,
41+
rect: { ...origin, width: 128, height: 52 },
42+
hittable: true,
43+
});
44+
}

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, vi } from 'vitest';
22
import assert from 'node:assert/strict';
33
import type { DeviceInfo } from '@agent-device/kernel/device';
4-
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
4+
import { button, node, text } from './alert-fixtures.ts';
55

66
const runAndroidAdb = vi.fn(async (_device: DeviceInfo, _args: string[]) => ({
77
exitCode: 0,
@@ -77,38 +77,3 @@ test('a fallback Back dismissal (no matching button) carries no coordinates', as
7777
assert.equal(result.kind === 'alertHandled' ? result.button : undefined, 'Back');
7878
assert.deepEqual(runAndroidAdb.mock.calls[0]?.[1], ['shell', 'input', 'keyevent', '4']);
7979
});
80-
81-
function node(
82-
index: number,
83-
type: string,
84-
overrides: Partial<RawSnapshotNode> = {},
85-
): RawSnapshotNode {
86-
return {
87-
index,
88-
parentIndex: index === 0 ? undefined : 0,
89-
type,
90-
bundleId: 'com.example.app',
91-
...overrides,
92-
};
93-
}
94-
95-
function text(index: number, label: string, identifier: string, parentIndex = 0): RawSnapshotNode {
96-
return node(index, 'android.widget.TextView', { label, identifier, parentIndex });
97-
}
98-
99-
function button(
100-
index: number,
101-
label: string,
102-
identifier: string,
103-
origin: { x: number; y: number },
104-
parentIndex = 0,
105-
): RawSnapshotNode {
106-
return node(index, 'android.widget.Button', {
107-
label,
108-
identifier,
109-
bundleId: 'com.example.app',
110-
parentIndex,
111-
rect: { ...origin, width: 128, height: 52 },
112-
hittable: true,
113-
});
114-
}

‎test/integration/live-device-e2e/runtime.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,7 @@ export function createLiveDeviceHarness<
185185
}
186186
}
187187

188-
/**
189-
* Best-effort evidence for a `wait` timeout: the daemon's own surface dump caps at a handful of
190-
* labels, so a screenshot is the only artifact that shows the whole screen the wait gave up on.
191-
* A failed capture must not mask the original wait failure, so this never throws.
192-
*/
188+
/** Best-effort: never throws, returns undefined on a failed capture. */
193189
async function captureWaitTimeoutScreenshot(context: Context): Promise<string | undefined> {
194190
const screenshotPath = path.join(
195191
context.artifactDir,

0 commit comments

Comments
 (0)