Skip to content

Commit e46c0f1

Browse files
committed
test(snapshot): derive fixture kind from the final type and pin literal roles (#2656)
1 parent a0672e9 commit e46c0f1

8 files changed

Lines changed: 16 additions & 30 deletions

File tree

‎packages/capture-kit/src/snapshot/__tests__/snapshot-lines-kind-conformance.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ const ANDROID_FIXTURE: RawSnapshotNode[] = [
2424
{ index: 3, type: 'android.widget.EditText', label: 'Promo code', parentIndex: 0 },
2525
];
2626

27-
function assertKindMatchesPresentedRole(fixture: RawSnapshotNode[]): void {
28-
for (const node of attachRefs(fixture)) {
27+
function assertKindMatchesPresentedRole(fixture: RawSnapshotNode[], expected: string[]): void {
28+
const attached = attachRefs(fixture);
29+
assert.deepEqual(
30+
attached.map((node) => node.kind),
31+
expected,
32+
);
33+
for (const node of attached) {
2934
const line = formatSnapshotLine(node, 0, false);
3035
const presentedRole = /^@?\S*\s*\[([^\]]+)\]/.exec(line)?.[1];
3136
assert.equal(node.kind, presentedRole, `kind mismatch for ${node.type}: line was "${line}"`);
3237
}
3338
}
3439

3540
test('kind equals the presenter role for every node of an iOS fixture tree', () => {
36-
assertKindMatchesPresentedRole(IOS_FIXTURE);
41+
assertKindMatchesPresentedRole(IOS_FIXTURE, ['application', 'button', 'text', 'text-field']);
3742
});
3843

3944
test('kind equals the presenter role for every node of an Android fixture tree', () => {
40-
assertKindMatchesPresentedRole(ANDROID_FIXTURE);
45+
assertKindMatchesPresentedRole(ANDROID_FIXTURE, ['group', 'button', 'text', 'text-field']);
4146
});

‎packages/contracts/src/snapshot-visibility.test.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import type { SnapshotNode } from '@agent-device/kernel/snapshot';
33
import { createSnapshotVisibility } from './snapshot-visibility.ts';
44
import { formatRole } from '@agent-device/kernel/snapshot';
55

6-
function snapshotNodes(
7-
nodes: Array<Omit<SnapshotNode, 'ref' | 'kind'> & { kind?: string }>,
8-
): SnapshotNode[] {
6+
function snapshotNodes(nodes: Array<Omit<SnapshotNode, 'ref' | 'kind'>>): SnapshotNode[] {
97
return nodes.map((node) => ({
108
ref: `@e${node.index}`,
11-
kind: formatRole(node.type ?? 'Element'),
129
...node,
10+
kind: formatRole(node.type ?? 'Element'),
1311
}));
1412
}
1513

@@ -18,14 +16,12 @@ test('rootless effective visibility never resolves a target-dependent containing
1816
{
1917
index: 0,
2018
type: 'android.widget.FrameLayout',
21-
kind: formatRole('android.widget.FrameLayout'),
2219
rect: { x: 0, y: 0, width: 1080, height: 2400 },
2320
},
2421
...Array.from({ length: 64 }, (_, offset) => ({
2522
index: offset + 1,
2623
parentIndex: 0,
2724
type: 'android.widget.TextView',
28-
kind: formatRole('android.widget.TextView'),
2925
rect: { x: 20, y: offset * 30, width: 200, height: 24 },
3026
})),
3127
]);
@@ -49,21 +45,18 @@ test('effective visibility keeps explicit-root and nearest-scroll clipping seman
4945
index: 1,
5046
parentIndex: 0,
5147
type: 'Button',
52-
kind: formatRole('Button'),
5348
rect: { x: 120, y: 20, width: 20, height: 20 },
5449
},
5550
{
5651
index: 2,
5752
parentIndex: 0,
5853
type: 'ScrollView',
59-
kind: formatRole('ScrollView'),
6054
rect: { x: 0, y: 0, width: 50, height: 50 },
6155
},
6256
{
6357
index: 3,
6458
parentIndex: 2,
6559
type: 'Button',
66-
kind: formatRole('Button'),
6760
rect: { x: 0, y: 60, width: 20, height: 20 },
6861
},
6962
]);

‎packages/kernel/src/snapshot-attach-refs.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('attachRefs', () => {
2323
expect(attached.map((n) => n.ref)).toEqual(['e1', 'e7', 'e3']);
2424
});
2525

26-
test('publishes the presenter role as kind, on every platform vocabulary, on every node (#2656)', () => {
26+
test('publishes the presenter role as kind, for Android and Apple vocabularies, on every node (#2656)', () => {
2727
const attached = attachRefs([
2828
node(0, { type: 'android.widget.Button' }),
2929
node(1, { type: 'XCUIElementTypeButton' }),

‎packages/maestro/src/daemon-port/__tests__/daemon-runtime-port-positional.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import { expect, test } from 'vitest';
22
import { resolveTypedMaestroTarget } from '../daemon-runtime-port-observation.ts';
33
import { makeSnapshot } from './daemon-runtime-port-fixtures.ts';
4-
import { formatRole } from '@agent-device/kernel/snapshot';
54

65
test('nested positional relations never use atomic iOS selector dispatch', () => {
76
const snapshot = makeSnapshot([
87
{
98
index: 0,
109
type: 'StaticText',
11-
kind: formatRole('StaticText'),
1210
identifier: 'header',
1311
rect: { x: 20, y: 20, width: 100, height: 30 },
1412
},
1513
{
1614
index: 1,
1715
type: 'Other',
18-
kind: formatRole('Other'),
1916
identifier: 'card',
2017
rect: { x: 20, y: 100, width: 300, height: 180 },
2118
},
2219
{
2320
index: 2,
2421
parentIndex: 1,
2522
type: 'TextField',
26-
kind: formatRole('TextField'),
2723
identifier: 'field',
2824
rect: { x: 40, y: 160, width: 180, height: 40 },
2925
},
@@ -50,7 +46,6 @@ test('an empty recursive relation also opts out of atomic iOS dispatch', () => {
5046
{
5147
index: 0,
5248
type: 'TextField',
53-
kind: formatRole('TextField'),
5449
identifier: 'field',
5550
rect: { x: 40, y: 160, width: 180, height: 40 },
5651
},

‎packages/maestro/src/internal/__tests__/runtime-selector-resolution.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, test } from 'vitest';
2-
import { formatRole } from '@agent-device/kernel/snapshot';
32
import type { SnapshotNode } from '@agent-device/kernel/snapshot';
43
import type { MaestroSelector } from '../program-ir.ts';
54
import { createMaestroSnapshotResolver } from '../runtime-selector-resolution.ts';
@@ -12,7 +11,6 @@ test('computes recursive selector sets once per snapshot instead of once per can
1211
ref: `candidate-${offset}`,
1312
identifier: 'candidate',
1413
parentIndex: 0,
15-
kind: formatRole('Element'),
1614
rect: { x: 20, y: 200 + offset, width: 40, height: 30 },
1715
}));
1816
const snapshot = makeSnapshot([

‎packages/maestro/src/internal/__tests__/runtime-target-fixtures.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import type { SnapshotNode, SnapshotState } from '@agent-device/kernel/snapshot'
33

44
export type SnapshotNodeFixture = Omit<SnapshotNode, 'ref' | 'kind'> & {
55
ref?: string;
6-
kind?: string;
76
};
87

98
export function makeSnapshot(nodes: SnapshotNodeFixture[]): SnapshotState {
109
return {
1110
createdAt: Date.now(),
1211
nodes: nodes.map((node) => ({
1312
ref: `e${node.index}`,
14-
kind: formatRole(node.type ?? 'Element'),
1513
...node,
14+
kind: formatRole(node.type ?? 'Element'),
1615
})),
1716
};
1817
}

‎packages/selectors/src/target-evidence.test.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from 'vitest';
22
import assert from 'node:assert/strict';
3-
import { formatRole } from '@agent-device/kernel/snapshot';
3+
import { attachRefs } from '@agent-device/kernel/snapshot';
44
import type { RawSnapshotNode, SnapshotNode } from '@agent-device/kernel/snapshot';
55
import { computeTargetEvidence } from './target-evidence.ts';
66
import {
@@ -13,11 +13,7 @@ import {
1313
} from '@agent-device/ad-script';
1414

1515
function toSnapshotNodes(raw: RawSnapshotNode[]): SnapshotNode[] {
16-
return raw.map((node, position) => ({
17-
...node,
18-
ref: `e${position + 1}`,
19-
kind: formatRole(node.type ?? 'Element'),
20-
}));
16+
return attachRefs(raw);
2117
}
2218

2319
function findByLabel(nodes: SnapshotNode[], label: string): SnapshotNode {

‎website/docs/docs/snapshots.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ agent-device snapshot -i
8989

9090
## Structured node fields (`--json`)
9191

92-
Every node in `snapshot --json` output carries both `type` and `kind`:
92+
Every node in `snapshot --json` output carries `kind`, next to `type` when the platform reports one:
9393

9494
- `type` is the raw platform class, verbatim: `Button` / `StaticText` from XCUI, `android.widget.Button`
9595
from the Android hierarchy. It differs by platform for the same UI role.

0 commit comments

Comments
 (0)