Skip to content

Commit 99f3a6f

Browse files
thymikeeclaude
andcommitted
refactor(test-kit): export the target classification fixture and use it from replay-port and daemon
bottomTabsRealCaptureFixture and recordArticleEvidence become test-kit named exports; the local toSnapshotNodes folds into test-kit's buildNodes. recordArticleEvidence takes the evidence function as a parameter, so test-kit does not depend on selectors. replay-port declares test-kit as a devDependency and drops its target-classification-fixtures export. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 474ea90 commit 99f3a6f

8 files changed

Lines changed: 53 additions & 42 deletions

File tree

‎packages/daemon/src/sessions/__tests__/replay-repair/session-replay-repair-empty-tail.test.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ import { storeSessionForTest } from '../../../__tests__/support/store-factory.ts
2424
* `caution`/`manual` divergence is no longer a dead end.
2525
*/
2626
import { test, expect, vi, beforeEach } from 'vitest';
27-
import { mkdtempForTestSync } from '@agent-device/test-kit';
27+
import {
28+
bottomTabsRealCaptureFixture,
29+
buildNodes,
30+
mkdtempForTestSync,
31+
recordArticleEvidence,
32+
} from '@agent-device/test-kit';
33+
import { computeTargetEvidence } from '@agent-device/selectors/target-evidence';
2834

2935
vi.mock('@agent-device/device-selection/dispatch-resolve', async (importOriginal) => {
3036
const actual =
@@ -52,11 +58,6 @@ import {
5258
writeReplayFile,
5359
} from '../replay-runtime/session-replay-runtime.fixtures.ts';
5460
import { freshEvidence, makeRecordingReplayInvoke } from './session-replay-repair.fixtures.ts';
55-
import {
56-
bottomTabsRealCaptureFixture,
57-
recordArticleEvidence,
58-
toSnapshotNodes,
59-
} from '@agent-device/replay-port/target-classification-fixtures';
6061

6162
/** Repair-transaction status, or `undefined` outside a repair publication. */
6263
function sessionRepairStatus(session: SessionState | undefined) {
@@ -90,7 +91,7 @@ test('a record-and-heal divergence on the LAST step resumes with an empty tail a
9091
sessionName,
9192
makeIosSession(sessionName, { appBundleId: 'com.example.app' }),
9293
);
93-
const evidence = await recordArticleEvidence();
94+
const evidence = recordArticleEvidence(computeTargetEvidence);
9495
const filePath = writeReplayFile(root, [
9596
'open "Demo" --relaunch',
9697
`# agent-device:target-v1 ${JSON.stringify(evidence)}`,
@@ -561,7 +562,7 @@ test('an unauthorized --from one past the plan end is rejected on an ARMED sessi
561562
sessionName,
562563
makeIosSession(sessionName, { appBundleId: 'com.example.app' }),
563564
);
564-
const evidence = await recordArticleEvidence();
565+
const evidence = recordArticleEvidence(computeTargetEvidence);
565566
const filePath = writeReplayFile(root, [
566567
'open "Demo" --relaunch',
567568
`# agent-device:target-v1 ${JSON.stringify(evidence)}`,
@@ -574,7 +575,7 @@ test('an unauthorized --from one past the plan end is rejected on an ARMED sessi
574575
// `state-repair` (the app-state sub-flow), never `record-and-heal`. No
575576
// `pendingRecordAndHeal` watermark is ever stamped for this session.
576577
mockDispatchCommand.mockResolvedValue({
577-
nodes: toSnapshotNodes([
578+
nodes: buildNodes([
578579
{
579580
index: 0,
580581
type: 'Application',
@@ -647,7 +648,7 @@ test('a stale --plan-digest on an empty-tail resume is rejected WITHOUT consumin
647648
sessionName,
648649
makeIosSession(sessionName, { appBundleId: 'com.example.app' }),
649650
);
650-
const evidence = await recordArticleEvidence();
651+
const evidence = recordArticleEvidence(computeTargetEvidence);
651652
const filePath = writeReplayFile(root, [
652653
'open "Demo" --relaunch',
653654
`# agent-device:target-v1 ${JSON.stringify(evidence)}`,

‎packages/daemon/src/sessions/__tests__/replay-target/session-replay-dispatch-selector-miss.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
* zero-match selector) instead of returning it.
2121
*/
2222
import { test, expect, vi, beforeEach } from 'vitest';
23-
import { mkdtempForTestSync } from '@agent-device/test-kit';
23+
import {
24+
bottomTabsRealCaptureFixture,
25+
mkdtempForTestSync,
26+
recordArticleEvidence,
27+
} from '@agent-device/test-kit';
28+
import { computeTargetEvidence } from '@agent-device/selectors/target-evidence';
2429

2530
vi.mock('@agent-device/device-selection/dispatch-resolve', async (importOriginal) => {
2631
const actual =
@@ -42,10 +47,6 @@ import {
4247
baseReplayRequest as baseReq,
4348
writeReplayFile,
4449
} from '../replay-runtime/session-replay-runtime.fixtures.ts';
45-
import {
46-
bottomTabsRealCaptureFixture,
47-
recordArticleEvidence,
48-
} from '@agent-device/replay-port/target-classification-fixtures';
4950
import {
5051
captureSnapshotThroughLegacyDispatchFixture,
5152
legacyDispatchCapture,
@@ -111,7 +112,7 @@ function assertDivergenceShape(
111112
test('(a) an ANNOTATED press whose dispatch throws a selector-miss yields REPLAY_DIVERGENCE, not COMMAND_FAILED', async () => {
112113
const root = mkdtempForTestSync('agent-device-replay-dispatch-miss-annotated-');
113114
const { sessionStore, sessionName } = setupSession(root);
114-
const evidence = await recordArticleEvidence();
115+
const evidence = recordArticleEvidence(computeTargetEvidence);
115116
const filePath = writeReplayFile(root, [
116117
`# agent-device:target-v1 ${JSON.stringify(evidence)}`,
117118
'click id="article"',

‎packages/replay-port/package.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@
124124
"types": "./src/daemon-port/target-classification.ts",
125125
"default": "./src/daemon-port/target-classification.ts"
126126
},
127-
"./target-classification-fixtures": {
128-
"types": "./src/target-classification.fixtures.ts",
129-
"default": "./src/target-classification.fixtures.ts"
130-
},
131127
"./target-token": {
132128
"types": "./src/daemon-port/target-token.ts",
133129
"default": "./src/daemon-port/target-token.ts"
@@ -144,5 +140,8 @@
144140
"types": "./src/replay-script-source.fixtures.ts",
145141
"default": "./src/replay-script-source.fixtures.ts"
146142
}
143+
},
144+
"devDependencies": {
145+
"@agent-device/test-kit": "workspace:*"
147146
}
148147
}

‎packages/replay-port/src/daemon-port/__tests__/target-classification.test.ts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
import {
1717
bottomTabsRealCaptureFixture,
1818
recordArticleEvidence,
19-
toSnapshotNodes,
20-
} from '@agent-device/replay-port/target-classification-fixtures';
19+
buildNodes,
20+
} from '@agent-device/test-kit';
2121

2222
/** Verified outcomes carry the verified member + matchCount (for the post-resolution guard). */
2323
function assertVerified(
@@ -33,7 +33,7 @@ function assertVerified(
3333
const PLATFORM = 'ios' as const;
3434

3535
test('classifyReplayTarget: real-capture fixture verifies by @ref when the tree is unchanged', async () => {
36-
const recorded = await recordArticleEvidence();
36+
const recorded = recordArticleEvidence(computeTargetEvidence);
3737
const replayNodes = bottomTabsRealCaptureFixture();
3838
const winner = replayNodes.find((node) => node.label === 'Article, unselected');
3939
assert.ok(winner);
@@ -50,7 +50,7 @@ test('classifyReplayTarget: real-capture fixture verifies by @ref when the tree
5050
});
5151

5252
test('classifyReplayTarget: real-capture fixture — a relabeled node is identity-mismatch (path 3)', async () => {
53-
const recorded = await recordArticleEvidence();
53+
const recorded = recordArticleEvidence(computeTargetEvidence);
5454
const replayNodes = bottomTabsRealCaptureFixture();
5555
const winner = replayNodes.find((node) => node.label === 'Article, unselected');
5656
assert.ok(winner);
@@ -99,7 +99,7 @@ function saveButtonRecorded(overrides: Partial<TargetAnnotationV1> = {}): Target
9999
}
100100

101101
function saveButtonTree(): SnapshotNode[] {
102-
return toSnapshotNodes([
102+
return buildNodes([
103103
{ index: 0, type: 'Window', depth: 0 },
104104
{ index: 1, type: 'Toolbar', label: 'Editor', depth: 1, parentIndex: 0 },
105105
{
@@ -116,7 +116,7 @@ function saveButtonTree(): SnapshotNode[] {
116116

117117
test('classifyReplayTarget path 2: selector-miss when the recorded target is gone', () => {
118118
const recorded = saveButtonRecorded();
119-
const nodes = toSnapshotNodes([
119+
const nodes = buildNodes([
120120
{ index: 0, type: 'Window', depth: 0 },
121121
{ index: 1, type: 'Toolbar', label: 'Editor', depth: 1, parentIndex: 0 },
122122
]);
@@ -152,7 +152,7 @@ test('classifyReplayTarget path 4: verified via @ref on an unchanged tree', () =
152152
});
153153

154154
test('classifyReplayTarget uses the later chain alternative that resolution selected after an earlier tie', () => {
155-
const nodes = toSnapshotNodes([
155+
const nodes = buildNodes([
156156
{
157157
index: 0,
158158
type: 'Button',
@@ -231,7 +231,7 @@ test('classifyReplayTarget path 5: a unique-but-wrong rebind is caught even when
231231
// Two "Go back" buttons at different depths: the label-only selector
232232
// matches both, but only one carries the recorded id. The disambiguation
233233
// heuristic (deepest-then-smallest-area) prefers the decoy.
234-
const nodes = toSnapshotNodes([
234+
const nodes = buildNodes([
235235
{ index: 0, type: 'Window', rect: { x: 0, y: 0, width: 400, height: 800 }, depth: 0 },
236236
{
237237
index: 1,
@@ -279,7 +279,7 @@ test('classifyReplayTarget path 5: a unique-but-wrong rebind is caught even when
279279
// ---------------------------------------------------------------------------
280280

281281
function duplicateRowTree(): SnapshotNode[] {
282-
return toSnapshotNodes([
282+
return buildNodes([
283283
{ index: 0, type: 'Window', depth: 0 },
284284
{ index: 1, type: 'ScrollView', identifier: 'list', depth: 1, parentIndex: 0 },
285285
// Two anonymous section wrappers (role only, no label) — a real
@@ -439,7 +439,7 @@ test('classifyReplayTarget: document-order determinism for equal rect centers',
439439
// tie-break were nondeterministic or reversed, the winner (e3) would not
440440
// match `orderedRegion[0]` and this would report a mismatch instead of
441441
// verified.
442-
const nodes = toSnapshotNodes([
442+
const nodes = buildNodes([
443443
{ index: 0, type: 'ScrollView', identifier: 'list', depth: 0 },
444444
{ index: 1, type: 'Other', depth: 1, parentIndex: 0 },
445445
{ index: 2, type: 'Other', depth: 1, parentIndex: 0 },
@@ -508,7 +508,7 @@ function androidSharedIdListFixture(
508508
parentIndex: wrapperIndex,
509509
});
510510
});
511-
return toSnapshotNodes(raw);
511+
return buildNodes(raw);
512512
}
513513

514514
test('#1269 e2e: a demoted shared-id row rebinds by role+label after the shared-id rows reorder on replay', () => {
@@ -663,7 +663,7 @@ test('#1280 e2e: a retargeted press on a row container rebinds its labeled desce
663663
// ---------------------------------------------------------------------------
664664

665665
test('#2498 e2e: a read recorded on a collapsed wrapper chain verifies on the same tree', () => {
666-
const nodes = toSnapshotNodes(UNVERIFIED_HITTABILITY_WRAPPER_CHAIN_NODES);
666+
const nodes = buildNodes(UNVERIFIED_HITTABILITY_WRAPPER_CHAIN_NODES);
667667
const reports = nodes.filter((node) => node.identifier === 'scoring_home_button');
668668
const control = resolveElementReportedTwice(nodes, reports);
669669
assert.ok(control, 'dispatch resolves the toolbar button, not the item host that reports it');
@@ -684,7 +684,7 @@ test('#2498 e2e: a read recorded on a collapsed wrapper chain verifies on the sa
684684
});
685685

686686
test('#2498 e2e: matches in distinct subtrees stay a refusal, not a collapse to one of them', () => {
687-
const nodes = toSnapshotNodes(ELEMENT14_DISTINCT_SUBTREE_NODES);
687+
const nodes = buildNodes(ELEMENT14_DISTINCT_SUBTREE_NODES);
688688
const recordedWinner = nodes.find((node) => node.type === 'XCUIElementTypeButton');
689689
assert.ok(recordedWinner);
690690
const recorded = computeTargetEvidence({ node: recordedWinner, preActionNodes: nodes });

‎packages/replay-port/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
{ "path": "../maestro" },
2323
{ "path": "../replay-test" },
2424
{ "path": "../selectors" },
25-
{ "path": "../session-journal" }
25+
{ "path": "../session-journal" },
26+
{ "path": "../test-kit" }
2627
]
2728
}

‎packages/test-kit/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export {
7777
unavailableDeploymentSnapshotAndShutdownOperationFacts,
7878
} from './runtime-operation-facts.ts';
7979
export { buildNodes } from './snapshot-builders.ts';
80+
export {
81+
bottomTabsRealCaptureFixture,
82+
recordArticleEvidence,
83+
} from './target-classification-fixtures.ts';
8084
export { mkdtempForTest, mkdtempForTestSync } from './tmp-dir.ts';
8185
export { likelyPlayableWebmContainer } from './video-fixtures.ts';
8286
export {

‎packages/test-kit/src/target-classification-fixtures.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import assert from 'node:assert/strict';
2-
import type { RawSnapshotNode, SnapshotNode } from '@agent-device/kernel/snapshot';
2+
import type { SnapshotNode } from '@agent-device/kernel/snapshot';
33
import type { TargetAnnotationV1 } from '@agent-device/contracts/replay';
4-
5-
export function toSnapshotNodes(raw: RawSnapshotNode[]): SnapshotNode[] {
6-
return raw.map((node, position) => ({ ...node, ref: `e${position + 1}` }));
7-
}
4+
import { buildNodes } from './snapshot-builders.ts';
85

96
export function bottomTabsRealCaptureFixture(): SnapshotNode[] {
10-
return toSnapshotNodes([
7+
return buildNodes([
118
{
129
index: 0,
1310
type: 'Application',
@@ -80,8 +77,12 @@ export function bottomTabsRealCaptureFixture(): SnapshotNode[] {
8077
]);
8178
}
8279

83-
export async function recordArticleEvidence(): Promise<TargetAnnotationV1> {
84-
const { computeTargetEvidence } = await import('@agent-device/selectors/target-evidence');
80+
export function recordArticleEvidence(
81+
computeTargetEvidence: (capture: {
82+
node: SnapshotNode;
83+
preActionNodes: SnapshotNode[];
84+
}) => TargetAnnotationV1 | undefined,
85+
): TargetAnnotationV1 {
8586
const nodes = bottomTabsRealCaptureFixture();
8687
const winner = nodes.find((node) => node.label === 'Article, unselected');
8788
if (!winner) throw new Error('fixture missing Article tab');

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)