Skip to content

Commit fef0b12

Browse files
thymikeeclaude
andauthored
chore: hoist shared snapshot/selector test fixtures into a single canonical location (#2419)
* chore: hoist shared snapshot/selector test fixtures into @agent-device/selectors PR #2397 left two copies of the snapshot-state builder and duplicated geometry/touch-point arbitraries (root's src/__tests__/test-utils/ and the package's internal/__tests__/), because packages cannot import root src/. Move the canonical versions into a new @agent-device/selectors/test-fixtures subpath and have both root and the selectors package import from it, leaving buildNodes and the root-only replay/gesture arbitraries in place. Fixes #2402 Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01USabYbQjD16A2UkkvMpf5x * chore: exempt test-fixtures.ts's test-only arbitraries from dead-code check PROPERTY_RUNS, scrollingContainerTypeArb, distinctRectPairArb, and interactionTouchPointScenarioArb are consumed only by *.test.ts files, which Fallow's --production analysis does not see, matching the existing pattern for other workspace-package symbols reached only from the test tree. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01USabYbQjD16A2UkkvMpf5x * chore: consolidate makeSnapshotState into capture-kit, rename fixtures file An adversarial review of the #2402 fixture-hoisting change found a third copy of makeSnapshotState in packages/capture-kit/src/snapshot-state.fixtures.ts, predating PR #2397. Since @agent-device/selectors already depends on capture-kit, make capture-kit's copy canonical (exported as ./snapshot-state-fixtures) and have the selectors package's fixtures module re-export it instead of duplicating it a third time. Also rename packages/selectors/src/test-fixtures.ts to snapshot-geometry.fixtures.ts (subpath ./snapshot-geometry-fixtures) to match every other test-fixture module's *.fixtures.ts convention in this repo, which lets it fall under .fallowrc.json's existing blanket **/*.fixtures.ts dead-code exemption instead of needing a bespoke per-symbol entry. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01USabYbQjD16A2UkkvMpf5x --------- Co-authored-by: Claude <[email protected]>
1 parent e7d97f7 commit fef0b12

47 files changed

Lines changed: 200 additions & 330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/agents/testing.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Before creating fixtures, look in `src/__tests__/test-utils/`. Import named buil
6969
that defines them (`session-factories.ts`, `device-fixtures.ts`, `store-factory.ts`); avoid importing
7070
unrelated helpers through a barrel. Shared `DeviceInfo`, session, snapshot, store, runtime-fact,
7171
and mocked-binary values belong in a sibling fixture module, not in repeated test literals.
72+
`PROPERTY_RUNS` and the interaction touch-point/rect arbitraries live in
73+
`@agent-device/selectors/snapshot-geometry-fixtures` — the canonical location root tests and the
74+
selectors package both build on — not in `src/__tests__/test-utils/`. `makeSnapshotState` itself
75+
canonically lives in `@agent-device/capture-kit/snapshot-state-fixtures`, re-exported from there.
7276

7377
Use `mkdtempForTest` or `mkdtempForTestSync`. Global setup redirects `TMPDIR` for the run and
7478
removes it after every worker exits — skip per-test cleanup. An interrupted run may leave a

‎packages/capture-kit/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@
182182
"types": "./src/snapshot-state.ts",
183183
"default": "./src/snapshot-state.ts"
184184
},
185+
"./snapshot-state-fixtures": {
186+
"types": "./src/snapshot-state.fixtures.ts",
187+
"default": "./src/snapshot-state.fixtures.ts"
188+
},
185189
"./snapshot-timeout-policy": {
186190
"types": "./src/snapshot/snapshot-timeout-policy.ts",
187191
"default": "./src/snapshot/snapshot-timeout-policy.ts"

‎packages/selectors/package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"sideEffects": false,
66
"type": "module",
7-
"description": "Shared selector matching, argument, and replay semantics for agent-device. `.` is string-only; `./ast` is the published parser surface behind `agent-device/selectors`; `./engine` is the resolve/list surface reserved for the selector-pipeline owner (R19); `./parameterized-recorded-fill` parameterizes recorded fill payloads against their selectors; the interaction-resolution subpaths (`./selector-pipeline`, `./interaction-targeting`, `./interaction-touch-point`, `./press-retarget`, `./absence-observation*`, …) host the engine execution surface owned by the pipeline.",
7+
"description": "Shared selector matching, argument, and replay semantics for agent-device. `.` is string-only; `./ast` is the published parser surface behind `agent-device/selectors`; `./engine` is the resolve/list surface reserved for the selector-pipeline owner (R19); `./parameterized-recorded-fill` parameterizes recorded fill payloads against their selectors; the interaction-resolution subpaths (`./selector-pipeline`, `./interaction-targeting`, `./interaction-touch-point`, `./press-retarget`, `./absence-observation*`, …) host the engine execution surface owned by the pipeline; `./snapshot-geometry-fixtures` is the canonical home for the geometry/touch-point test fixtures this package and root tests both build on (it re-exports `makeSnapshotState` from `@agent-device/capture-kit/snapshot-state-fixtures`, its own canonical home).",
88
"dependencies": {
99
"@agent-device/ad-script": "workspace:*",
1010
"@agent-device/capture-kit": "workspace:*",
@@ -72,6 +72,10 @@
7272
"types": "./src/selector-pipeline-policy.ts",
7373
"default": "./src/selector-pipeline-policy.ts"
7474
},
75+
"./snapshot-geometry-fixtures": {
76+
"types": "./src/snapshot-geometry.fixtures.ts",
77+
"default": "./src/snapshot-geometry.fixtures.ts"
78+
},
7579
"./touch-semantics": {
7680
"types": "./src/touch-semantics.ts",
7781
"default": "./src/touch-semantics.ts"

‎packages/selectors/src/absence-observation.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert/strict';
22
import { test } from 'vitest';
3-
import { makeSnapshotState } from './internal/__tests__/snapshot-builders.ts';
3+
import { makeSnapshotState } from './snapshot-geometry.fixtures.ts';
44
import {
55
absenceCaptureOptionMessage,
66
absenceCaptureOptionRefusal,

‎packages/selectors/src/interaction-targeting.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import fc from 'fast-check';
33
import { test } from 'vitest';
44
import {
55
distinctRectPairArb,
6+
makeSnapshotState,
67
PROPERTY_RUNS,
78
scrollingContainerTypeArb,
8-
} from './internal/__tests__/property-arbitraries.ts';
9-
import { makeSnapshotState } from './internal/__tests__/snapshot-builders.ts';
9+
} from './snapshot-geometry.fixtures.ts';
1010
import {
1111
classifyActionableTouchCandidates,
1212
createActionableTouchResolver,

‎packages/selectors/src/interaction-touch-point.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import type { Point, Rect } from '@agent-device/kernel/snapshot';
44
import { test } from 'vitest';
55
import {
66
interactionTouchPointScenarioArb,
7+
makeSnapshotState,
78
PROPERTY_RUNS,
8-
} from './internal/__tests__/property-arbitraries.ts';
9-
import { makeSnapshotState } from './internal/__tests__/snapshot-builders.ts';
9+
} from './snapshot-geometry.fixtures.ts';
1010
import { resolveInteractionTouchPoint } from './interaction-touch-point.ts';
1111

1212
function containsPoint(rect: Rect, point: Point): boolean {

‎packages/selectors/src/internal/__tests__/property-arbitraries.ts‎

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,6 @@
11
import fc from 'fast-check';
2-
import { attachRefs, type Rect, type SnapshotNode } from '@agent-device/kernel/snapshot';
32
import type { SelectorKey, SelectorTerm } from '../parse.ts';
43

5-
export const PROPERTY_RUNS = 100;
6-
7-
// ---------------------------------------------------------------------------
8-
// Rects / viewports
9-
// ---------------------------------------------------------------------------
10-
11-
export const scrollingContainerTypeArb = fc.constantFrom(
12-
'XCUIElementTypeScrollView',
13-
'XCUIElementTypeTable',
14-
'XCUIElementTypeCollectionView',
15-
'android.widget.ListView',
16-
'androidx.recyclerview.widget.RecyclerView',
17-
);
18-
19-
export const distinctRectPairArb: fc.Arbitrary<{ ancestor: Rect; target: Rect }> = fc
20-
.record({
21-
x: fc.integer({ min: -200, max: 200 }),
22-
y: fc.integer({ min: -200, max: 200 }),
23-
width: fc.integer({ min: 1, max: 1200 }),
24-
height: fc.integer({ min: 1, max: 1200 }),
25-
})
26-
.chain((ancestor) =>
27-
fc.constantFrom<keyof Rect>('x', 'y', 'width', 'height').map((field) => ({
28-
ancestor,
29-
target: { ...ancestor, [field]: ancestor[field] + 1 },
30-
})),
31-
);
32-
33-
export type InteractionTouchPointScenario = {
34-
nodes: SnapshotNode[];
35-
permutedNodes: SnapshotNode[];
36-
target: SnapshotNode;
37-
bound: Rect;
38-
competitorRects: Rect[];
39-
};
40-
41-
const halfPixel = (value: number): number => value / 2;
42-
const touchPointAxisStepsArb = fc.oneof(
43-
fc.integer({ min: 4, max: 46 }),
44-
fc.integer({ min: 48, max: 800 }),
45-
);
46-
47-
const touchPointTargetRectArb = fc
48-
.record({
49-
x: fc.integer({ min: -200, max: 200 }),
50-
y: fc.integer({ min: -200, max: 200 }),
51-
// Exercise dense desktop rows as well as standard mobile touch targets.
52-
width: touchPointAxisStepsArb,
53-
height: touchPointAxisStepsArb,
54-
})
55-
.map(({ x, y, width, height }) => ({
56-
x: halfPixel(x),
57-
y: halfPixel(y),
58-
width: halfPixel(width),
59-
height: halfPixel(height),
60-
}));
61-
62-
function containedRectArb(container: Rect): fc.Arbitrary<Rect> {
63-
const widthSteps = Math.round(container.width * 2);
64-
const heightSteps = Math.round(container.height * 2);
65-
return fc
66-
.record({
67-
width: fc.integer({ min: 2, max: widthSteps - 2 }),
68-
height: fc.integer({ min: 2, max: heightSteps - 2 }),
69-
})
70-
.chain(({ width, height }) =>
71-
fc
72-
.record({
73-
x: fc.integer({ min: 0, max: widthSteps - width }),
74-
y: fc.integer({ min: 0, max: heightSteps - height }),
75-
})
76-
.map(({ x, y }) => ({
77-
x: container.x + halfPixel(x),
78-
y: container.y + halfPixel(y),
79-
width: halfPixel(width),
80-
height: halfPixel(height),
81-
})),
82-
);
83-
}
84-
85-
export const interactionTouchPointScenarioArb: fc.Arbitrary<InteractionTouchPointScenario> =
86-
touchPointTargetRectArb.chain((targetRect) =>
87-
fc
88-
.tuple(
89-
fc.array(containedRectArb(targetRect), { minLength: 1, maxLength: 6 }),
90-
containedRectArb(targetRect),
91-
)
92-
.chain(([competitorRects, bound]) => {
93-
const nodes = attachRefs([
94-
{
95-
index: 0,
96-
depth: 0,
97-
type: 'Link',
98-
label: 'Generated parent',
99-
rect: targetRect,
100-
hittable: true,
101-
},
102-
...competitorRects.map((rect, offset) => ({
103-
index: offset + 1,
104-
depth: 1,
105-
parentIndex: 0,
106-
type: 'Button',
107-
label: `Generated child ${offset + 1}`,
108-
rect,
109-
hittable: true,
110-
})),
111-
]);
112-
return fc
113-
.shuffledSubarray(nodes, { minLength: nodes.length, maxLength: nodes.length })
114-
.map((permutedNodes) => ({
115-
nodes,
116-
permutedNodes,
117-
target: nodes[0]!,
118-
bound,
119-
competitorRects,
120-
}));
121-
}),
122-
);
123-
1244
const SELECTOR_KEY_VALUE_KINDS = {
1255
id: 'text',
1266
role: 'text',

‎packages/selectors/src/internal/__tests__/snapshot-builders.ts‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎packages/selectors/src/internal/parse.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { test } from 'vitest';
33
import assert from 'node:assert/strict';
44
import {
55
formatSelectorChainExpression,
6-
PROPERTY_RUNS,
76
selectorChainArb,
87
} from './__tests__/property-arbitraries.ts';
8+
import { PROPERTY_RUNS } from '../snapshot-geometry.fixtures.ts';
99
import { parseSelectorChain } from './parse.ts';
1010
import type { SelectorTerm } from './parse.ts';
1111

‎packages/selectors/src/selector-pipeline.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
22
import { test } from 'vitest';
33
import type { RawSnapshotNode, SnapshotNode } from '@agent-device/kernel/snapshot';
44
import { SELECTOR_RESOLUTION_POLICIES } from '@agent-device/selectors';
5-
import { makeSnapshotState } from './internal/__tests__/snapshot-builders.ts';
5+
import { makeSnapshotState } from './snapshot-geometry.fixtures.ts';
66
import {
77
listSelectorPipelineMatches,
88
resolveSelectorPipeline,

0 commit comments

Comments
 (0)