@@ -3,22 +3,6 @@ import * as fs from 'node:fs';
33import * as os from 'node:os' ;
44import * as path from 'node:path' ;
55import { AppError } from '@agent-device/kernel/errors' ;
6- import {
7- keyboardRuntimeOperationFacts ,
8- type KeyboardDismissResult ,
9- } from '@agent-device/contracts/keyboard-runtime' ;
10- import {
11- localRuntimeOwner ,
12- narrowDeviceBinding ,
13- type DeviceBinding ,
14- type RuntimeFacts ,
15- } from '@agent-device/contracts/platform-runtime' ;
16- import type { PlatformRuntimeOperations } from '@agent-device/contracts/platform-runtime-operations' ;
17- import { deviceShape , type DeviceInfo } from '@agent-device/kernel/device' ;
18- import type {
19- BindDeviceRuntime ,
20- InspectDeviceRuntimeFacts ,
21- } from '../../request-runtime-binding.ts' ;
226import {
237 mockDispatch ,
248 mockResolveTargetDevice ,
@@ -30,43 +14,6 @@ import {
3014import type { SessionState } from '../../types.ts' ;
3115import { handleSessionCommands } from './session-command-harness.ts' ;
3216
33- const available = Object . freeze ( { available : true } as const ) ;
34-
35- /** Admits every keyboard operation so the ADR 0014 seam runs on real admission, not a rejection.
36- * `keyboardDismiss` is overridable so a test can force the invocation itself to reject, proving
37- * the frame expires before the mutating call runs rather than only after it resolves. */
38- function keyboardCapableRuntime (
39- device : DeviceInfo ,
40- overrides ?: Readonly < { keyboardDismiss ?: ( ) => Promise < KeyboardDismissResult > } > ,
41- ) {
42- const facts : RuntimeFacts < PlatformRuntimeOperations > = {
43- device : { ...deviceShape ( device ) , providerMode : 'local' } ,
44- operations : keyboardRuntimeOperationFacts ( {
45- status : available ,
46- dismiss : available ,
47- enter : available ,
48- } ) as RuntimeFacts < PlatformRuntimeOperations > [ 'operations' ] ,
49- } ;
50- const binding = {
51- device,
52- owner : localRuntimeOwner ( device . platform ) ,
53- facts,
54- operations : {
55- keyboardStatus : async ( ) => ( { visible : false } ) ,
56- keyboardDismiss :
57- overrides ?. keyboardDismiss ??
58- ( async ( ) => ( { kind : 'ime-probe' , dismissed : true , visible : false } ) ) ,
59- keyboardEnter : async ( ) => ( { } ) ,
60- } ,
61- [ Symbol . asyncDispose ] : async ( ) => { } ,
62- } satisfies DeviceBinding < PlatformRuntimeOperations > ;
63- const inspectFacts : InspectDeviceRuntimeFacts = vi . fn ( async ( ) => facts ) ;
64- const bindDevice = vi . fn ( async ( _device , use ) =>
65- narrowDeviceBinding ( binding , use ) ,
66- ) as unknown as BindDeviceRuntime ;
67- return { inspectFacts, bindDevice } ;
68- }
69-
7017test ( 'appstate on iOS requires active session on selected device' , async ( ) => {
7118 const sessionStore = makeSessionStore ( ) ;
7219 const sessionName = 'default' ;
@@ -208,101 +155,6 @@ test('appstate fails when iOS session has no tracked app', async () => {
208155 }
209156} ) ;
210157
211- test ( 'keyboard dismiss crosses the ADR 0014 seam while keyboard status preserves the frame' , async ( ) => {
212- const sessionStore = makeSessionStore ( ) ;
213- const sessionName = 'kb' ;
214- const device : SessionState [ 'device' ] = {
215- platform : 'apple' ,
216- id : 'sim-1' ,
217- name : 'iPhone 17 Pro' ,
218- kind : 'simulator' ,
219- booted : true ,
220- } ;
221- mockResolveTargetDevice . mockResolvedValue ( device ) ;
222- mockDispatch . mockResolvedValue ( { } ) ;
223- const logPath = path . join ( os . tmpdir ( ) , 'daemon.log' ) ;
224- const { inspectFacts, bindDevice } = keyboardCapableRuntime ( device ) ;
225-
226- // dismiss mutates the device → frame expires.
227- sessionStore . set ( sessionName , makeSession ( sessionName , device ) ) ;
228- await handleSessionCommands ( {
229- req : {
230- token : 't' ,
231- session : sessionName ,
232- command : 'keyboard' ,
233- positionals : [ 'dismiss' ] ,
234- flags : { } ,
235- } ,
236- sessionName,
237- logPath,
238- sessionStore,
239- invoke : noopInvoke ,
240- inspectFacts,
241- bindDevice,
242- } ) ;
243- expect ( sessionStore . get ( sessionName ) ?. refFrameState ) . toBe ( 'expired' ) ;
244-
245- // status is a read-only probe → frame preserved (undefined === active).
246- sessionStore . set ( sessionName , makeSession ( sessionName , device ) ) ;
247- await handleSessionCommands ( {
248- req : {
249- token : 't' ,
250- session : sessionName ,
251- command : 'keyboard' ,
252- positionals : [ 'status' ] ,
253- flags : { } ,
254- } ,
255- sessionName,
256- logPath,
257- sessionStore,
258- invoke : noopInvoke ,
259- inspectFacts,
260- bindDevice,
261- } ) ;
262- expect ( sessionStore . get ( sessionName ) ?. refFrameState ) . toBeUndefined ( ) ;
263- } ) ;
264-
265- // #1955 review: `runSessionOrSelectorDispatch` used to expire the frame only after a successful
266- // `execute`, so a rejecting/timed-out invocation left a stale frame active. ADR 0014 requires
267- // expiry immediately before the mutating call, with no success-only rollback — prove a rejection
268- // still lands the expiry.
269- test ( 'keyboard dismiss expires the frame even when the invocation rejects' , async ( ) => {
270- const sessionStore = makeSessionStore ( ) ;
271- const sessionName = 'kb-reject' ;
272- const device : SessionState [ 'device' ] = {
273- platform : 'apple' ,
274- id : 'sim-2' ,
275- name : 'iPhone 17 Pro' ,
276- kind : 'simulator' ,
277- booted : true ,
278- } ;
279- mockResolveTargetDevice . mockResolvedValue ( device ) ;
280- const logPath = path . join ( os . tmpdir ( ) , 'daemon.log' ) ;
281- const { inspectFacts, bindDevice } = keyboardCapableRuntime ( device , {
282- keyboardDismiss : ( ) => Promise . reject ( new AppError ( 'COMMAND_FAILED' , 'runner timed out' ) ) ,
283- } ) ;
284-
285- sessionStore . set ( sessionName , makeSession ( sessionName , device ) ) ;
286- await expect (
287- handleSessionCommands ( {
288- req : {
289- token : 't' ,
290- session : sessionName ,
291- command : 'keyboard' ,
292- positionals : [ 'dismiss' ] ,
293- flags : { } ,
294- } ,
295- sessionName,
296- logPath,
297- sessionStore,
298- invoke : noopInvoke ,
299- inspectFacts,
300- bindDevice,
301- } ) ,
302- ) . rejects . toMatchObject ( { code : 'COMMAND_FAILED' } ) ;
303- expect ( sessionStore . get ( sessionName ) ?. refFrameState ) . toBe ( 'expired' ) ;
304- } ) ;
305-
306158test ( 'appstate without session on iOS selector returns SESSION_NOT_FOUND' , async ( ) => {
307159 const sessionStore = makeSessionStore ( ) ;
308160 const selectedDevice : SessionState [ 'device' ] = {
@@ -386,57 +238,6 @@ test('clipboard requires an active session or explicit device selector', async (
386238 }
387239} ) ;
388240
389- test ( 'keyboard requires an active session or explicit device selector' , async ( ) => {
390- const sessionStore = makeSessionStore ( ) ;
391- const response = await handleSessionCommands ( {
392- req : {
393- token : 't' ,
394- session : 'default' ,
395- command : 'keyboard' ,
396- positionals : [ 'status' ] ,
397- flags : { } ,
398- } ,
399- sessionName : 'default' ,
400- logPath : path . join ( os . tmpdir ( ) , 'daemon.log' ) ,
401- sessionStore,
402- invoke : noopInvoke ,
403- } ) ;
404-
405- expect ( response ) . toBeTruthy ( ) ;
406- expect ( response ?. ok ) . toBe ( false ) ;
407- if ( response && ! response . ok ) {
408- expect ( response . error . code ) . toBe ( 'INVALID_ARGS' ) ;
409- expect ( response . error . message ) . toMatch (
410- / k e y b o a r d r e q u i r e s a n a c t i v e s e s s i o n o r a n e x p l i c i t d e v i c e s e l e c t o r / i,
411- ) ;
412- }
413- } ) ;
414-
415- test ( 'keyboard dismiss requires active iOS session for explicit selectors' , async ( ) => {
416- const sessionStore = makeSessionStore ( ) ;
417-
418- const response = await handleSessionCommands ( {
419- req : {
420- token : 't' ,
421- session : 'default' ,
422- command : 'keyboard' ,
423- positionals : [ 'dismiss' ] ,
424- flags : { platform : 'ios' , device : 'iPhone 17 Pro' } ,
425- } ,
426- sessionName : 'default' ,
427- logPath : path . join ( os . tmpdir ( ) , 'daemon.log' ) ,
428- sessionStore,
429- invoke : noopInvoke ,
430- } ) ;
431-
432- expect ( response ) . toBeTruthy ( ) ;
433- expect ( response ?. ok ) . toBe ( false ) ;
434- if ( response && ! response . ok ) {
435- expect ( response . error . code ) . toBe ( 'SESSION_NOT_FOUND' ) ;
436- expect ( response . error . message ) . toMatch ( / r e q u i r e s a n a c t i v e s e s s i o n / i) ;
437- }
438- } ) ;
439-
440241test ( 'clipboard rejects unsupported iOS physical devices' , async ( ) => {
441242 const sessionStore = makeSessionStore ( ) ;
442243 const sessionName = 'ios-device-session' ;
0 commit comments