1- import { test , expect , vi , beforeEach } from 'vitest' ;
1+ import { test , expect , beforeEach } from 'vitest' ;
22import { attachRefs } from '@agent-device/kernel/snapshot' ;
3- import { makeSessionStore } from '@agent-device/daemon/testing/__tests__/support/store-factory' ;
4- import { activateCompleteRefFrame , refFrameState } from '@agent-device/daemon/testing/ref-frame' ;
3+ import { makeSessionStore } from '../../../__tests__/support/store-factory.ts' ;
4+ import { activateCompleteRefFrame , refFrameState } from '../../../core/ref-frame.ts' ;
5+ import { setSessionSnapshot , STALE_SNAPSHOT_REFS_WARNING } from '../../session-snapshot.ts' ;
56import {
6- setSessionSnapshot ,
7- STALE_SNAPSHOT_REFS_WARNING ,
8- } from '@agent-device/daemon/testing/session-snapshot' ;
9- import { handleInteractionCommands } from '@agent-device/daemon/testing/interaction/index' ;
7+ installInteractorSnapshotResolution ,
8+ mockInteractorSnapshot ,
9+ } from '../../../__tests__/support/interactor-resolution-fixture.ts' ;
10+ import { touchCreateCommandSurface } from '../../../__tests__/support/touch-command-surface-fake.ts' ;
11+ import { runInteraction } from '../../../__tests__/support/touch-interaction-runner.ts' ;
1012import {
1113 getRuntimeBindings ,
1214 mockTapPoint ,
1315 resetGetRuntimeFixture ,
14- } from '@agent-device/daemon/testing/ __tests__/interaction-get-runtime-fixture' ;
16+ } from '../../ __tests__/interaction-get-runtime-fixture.ts ' ;
1517import {
1618 contextFromFlags ,
17- findResolvedTarget ,
18- makeFindPreresolvedTree ,
1919 makeSession ,
2020 makeStaleRefSession ,
2121 makeTwoButtonNodes ,
22- readPressPoint ,
23- } from '@agent-device/daemon/testing/interaction/internal/__tests__/interaction-touch-fixtures' ;
24- import { runFindInternalClick , runInteraction } from './interaction-touch-runner.ts' ;
25- import { testCreateCommandSurface } from '../command-surface-fixture.ts' ;
22+ } from './__tests__/interaction-touch-fixtures.ts' ;
23+ import { handleInteractionCommands } from '../index.ts' ;
2624
2725// Whether a targeted touch may act, and on what: click-option and positional
28- // validation, and the ADR 0014 @ref rules (staleness, pins, frame expiry,
29- // locator provenance) that admit or reject before any device op.
30-
31- const { mockRunAppleRunnerCommand } = vi . hoisted ( ( ) => ( {
32- mockRunAppleRunnerCommand : vi . fn ( ) ,
33- } ) ) ;
34-
35- vi . mock ( '@agent-device/platform-android/mechanics' , async ( importOriginal ) => {
36- const actual = await importOriginal < typeof import ( '@agent-device/platform-android/mechanics' ) > ( ) ;
37- return {
38- ...actual ,
39- getAndroidScreenSize : vi . fn ( async ( ) => ( { width : 1344 , height : 2992 } ) ) ,
40- getAndroidAppState : vi . fn ( async ( ) => ( { } ) ) ,
41- getAndroidBlockingDialogObservation : vi . fn ( async ( ) => ( { status : 'clear' } ) as const ) ,
42- } ;
43- } ) ;
44-
45- vi . mock ( '@agent-device/daemon/testing/snapshot-interactor-capture' , ( ) => ( {
46- captureSnapshotWithInteractor : vi . fn ( ) ,
47- } ) ) ;
48-
49- vi . mock ( '@agent-device/platform-apple/runner/operations' , async ( importOriginal ) => {
50- const actual =
51- await importOriginal < typeof import ( '@agent-device/platform-apple/runner/operations' ) > ( ) ;
52- return { ...actual , runAppleRunnerCommand : mockRunAppleRunnerCommand } ;
53- } ) ;
54-
55- import {
56- getAndroidAppState ,
57- getAndroidBlockingDialogObservation ,
58- getAndroidScreenSize ,
59- } from '@agent-device/platform-android/mechanics' ;
60- import { captureSnapshotWithInteractor } from '@agent-device/daemon/testing/snapshot-interactor-capture' ;
61- const mockGetAndroidAppState = vi . mocked ( getAndroidAppState ) ;
62- const mockGetAndroidBlockingDialogObservation = vi . mocked ( getAndroidBlockingDialogObservation ) ;
63- const mockGetAndroidScreenSize = vi . mocked ( getAndroidScreenSize ) ;
64- const mockCaptureSnapshotForSession = vi . mocked ( captureSnapshotWithInteractor ) ;
26+ // validation, and the ADR 0014 @ref rules (staleness, pins, frame expiry) that
27+ // admit or reject before any device op.
6528
6629beforeEach ( ( ) => {
6730 resetGetRuntimeFixture ( ) ;
68- mockGetAndroidAppState . mockReset ( ) ;
69- mockGetAndroidAppState . mockResolvedValue ( { } ) ;
70- mockGetAndroidBlockingDialogObservation . mockReset ( ) ;
71- mockGetAndroidBlockingDialogObservation . mockResolvedValue ( { status : 'clear' } ) ;
72- mockGetAndroidScreenSize . mockReset ( ) ;
73- mockGetAndroidScreenSize . mockResolvedValue ( { width : 1344 , height : 2992 } ) ;
74- mockCaptureSnapshotForSession . mockReset ( ) ;
75- mockRunAppleRunnerCommand . mockReset ( ) ;
76- mockRunAppleRunnerCommand . mockResolvedValue ( { } ) ;
31+ installInteractorSnapshotResolution ( ) ;
32+ mockInteractorSnapshot . mockReset ( ) ;
7733} ) ;
7834
7935test ( 'click --button middle on macOS fails with an explicit unsupported-operation error' , async ( ) => {
@@ -95,7 +51,7 @@ test('click --button middle on macOS fails with an explicit unsupported-operatio
9551 ) ;
9652
9753 const response = await handleInteractionCommands ( {
98- createCommandSurface : testCreateCommandSurface ,
54+ createCommandSurface : touchCreateCommandSurface ,
9955 req : {
10056 token : 't' ,
10157 session : sessionName ,
@@ -123,7 +79,7 @@ test('press coordinates does not treat extra trailing args as selector', async (
12379 sessionStore . publish ( sessionName , makeSession ( sessionName ) ) ;
12480
12581 const response = await handleInteractionCommands ( {
126- createCommandSurface : testCreateCommandSurface ,
82+ createCommandSurface : touchCreateCommandSurface ,
12783 req : {
12884 token : 't' ,
12985 session : sessionName ,
@@ -143,30 +99,12 @@ test('press coordinates does not treat extra trailing args as selector', async (
14399 expect ( sessionStore . get ( sessionName ) ?. actions . length ) . toBe ( 1 ) ;
144100} ) ;
145101
146- test ( '#1654: the resolved-target payload fails closed when its ref provenance disagrees' , async ( ) => {
147- const sessionStore = makeSessionStore ( ) ;
148- const sessionName = 'find-preresolved-mismatched-ref' ;
149- sessionStore . publish ( sessionName , makeStaleRefSession ( sessionName ) ) ;
150- const preresolved = makeFindPreresolvedTree ( ) ;
151-
152- const response = await runFindInternalClick ( sessionStore , sessionName , {
153- findResolvedTarget : findResolvedTarget ( preresolved , '@e9' ) ,
154- } ) ;
155-
156- expect ( response ?. ok ) . toBe ( false ) ;
157- if ( response && ! response . ok ) {
158- expect ( response . error . code ) . toBe ( 'COMMAND_FAILED' ) ;
159- expect ( response . error . message ) . toContain ( 'provenance does not match' ) ;
160- }
161- expect ( readPressPoint ( mockTapPoint ) ) . toBeUndefined ( ) ;
162- } ) ;
163-
164102test ( 'press selector then press @ref rejects refs that outlived the stored snapshot before dispatch' , async ( ) => {
165103 const sessionStore = makeSessionStore ( ) ;
166104 const sessionName = 'stale-ref-warns' ;
167105 const session = makeStaleRefSession ( sessionName ) ;
168106 sessionStore . publish ( sessionName , session ) ;
169- mockCaptureSnapshotForSession . mockResolvedValue ( {
107+ mockInteractorSnapshot . mockResolvedValue ( {
170108 nodes : makeTwoButtonNodes ( ) ,
171109 backend : 'xctest' ,
172110 producer : 'apple-runner' ,
@@ -202,7 +140,7 @@ test('a ref press crosses the ADR 0014 side-effect seam and expires the ref fram
202140 const sessionName = 'seam-expiry' ;
203141 const session = makeStaleRefSession ( sessionName ) ;
204142 sessionStore . publish ( sessionName , session ) ;
205- mockCaptureSnapshotForSession . mockResolvedValue ( {
143+ mockInteractorSnapshot . mockResolvedValue ( {
206144 nodes : makeTwoButtonNodes ( ) ,
207145 backend : 'xctest' ,
208146 producer : 'apple-runner' ,
@@ -225,7 +163,7 @@ test('ADR 0014 evidence #1: a second ref mutation rejects (bare and pinned) unti
225163 // A complete snapshot issued the frame at generation 500.
226164 activateCompleteRefFrame ( session ) ;
227165 sessionStore . publish ( sessionName , session ) ;
228- mockCaptureSnapshotForSession . mockResolvedValue ( {
166+ mockInteractorSnapshot . mockResolvedValue ( {
229167 nodes : makeTwoButtonNodes ( ) ,
230168 backend : 'xctest' ,
231169 producer : 'apple-runner' ,
@@ -270,7 +208,7 @@ test('re-issuing a complete frame lets press @ref succeed again without warning'
270208 const sessionName = 'reissued-refs-no-warning' ;
271209 const session = makeStaleRefSession ( sessionName ) ;
272210 sessionStore . publish ( sessionName , session ) ;
273- mockCaptureSnapshotForSession . mockResolvedValue ( {
211+ mockInteractorSnapshot . mockResolvedValue ( {
274212 nodes : makeTwoButtonNodes ( ) ,
275213 backend : 'xctest' ,
276214 producer : 'apple-runner' ,
0 commit comments