@@ -10,7 +10,6 @@ import os from 'node:os';
1010import path from 'node:path' ;
1111import { runReplayScriptFile } from '../session-replay-runtime.ts' ;
1212import { SessionStore } from '../../session-store.ts' ;
13- import type { DaemonRequest } from '../../types.ts' ;
1413import { dispatchCommand } from '../../../core/dispatch.ts' ;
1514import {
1615 makeIosSession ,
@@ -77,59 +76,6 @@ test('a close-less replay reports sessionActive: true (real producer, session st
7776 expect ( response . data ) . toMatchObject ( { sessionActive : true , replayed : 2 } ) ;
7877} ) ;
7978
80- test ( '--keep-session suppresses a close that is terminal among executable actions' , async ( ) => {
81- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-marker-tail-' ) ) ;
82- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
83- const sessionName = 'default' ;
84- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
85- const filePath = writeReplayFile ( root , [ 'open "Demo"' , 'close' , 'replay "./nested-flow.ad"' ] ) ;
86- const commands : string [ ] = [ ] ;
87-
88- const response = await runReplayScriptFile ( {
89- req : baseReq ( { positionals : [ filePath ] , flags : { replayKeepSession : true } } ) ,
90- sessionName,
91- logPath : path . join ( root , 'daemon.log' ) ,
92- sessionStore,
93- invoke : async ( req ) => {
94- commands . push ( req . command ) ;
95- if ( req . command === 'close' ) sessionStore . delete ( sessionName ) ;
96- return { ok : true , data : { } } ;
97- } ,
98- } ) ;
99-
100- expect ( response . ok ) . toBe ( true ) ;
101- expect ( commands ) . toEqual ( [ 'open' ] ) ;
102- if ( ! response . ok ) return ;
103- expect ( response . data ) . toMatchObject ( { sessionActive : true , replayed : 1 } ) ;
104- } ) ;
105-
106- test ( '--keep-session fails explicitly when the completed replay has no live session' , async ( ) => {
107- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-postcondition-' ) ) ;
108- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
109- const sessionName = 'default' ;
110- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
111- const filePath = writeReplayFile ( root , [ 'open "Demo"' , 'click "Log out"' ] ) ;
112-
113- const response = await runReplayScriptFile ( {
114- req : baseReq ( { positionals : [ filePath ] , flags : { replayKeepSession : true } } ) ,
115- sessionName,
116- logPath : path . join ( root , 'daemon.log' ) ,
117- sessionStore,
118- invoke : async ( req ) => {
119- if ( req . command === 'click' ) sessionStore . delete ( sessionName ) ;
120- return { ok : true , data : { } } ;
121- } ,
122- } ) ;
123-
124- expect ( response ) . toMatchObject ( {
125- ok : false ,
126- error : {
127- code : 'COMMAND_FAILED' ,
128- message : expect . stringContaining ( '--keep-session could not preserve session' ) ,
129- } ,
130- } ) ;
131- } ) ;
132-
13379test ( 'a replay whose terminal close removes the session reports sessionActive: false' , async ( ) => {
13480 const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-session-closed-' ) ) ;
13581 const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
@@ -157,105 +103,6 @@ test('a replay whose terminal close removes the session reports sessionActive: f
157103 expect ( ( response . data as { sessionActive : boolean } ) . sessionActive ) . toBe ( false ) ;
158104} ) ;
159105
160- test ( '--keep-session suppresses only the authored terminal close and reports the surviving session' , async ( ) => {
161- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-session-' ) ) ;
162- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
163- const sessionName = 'default' ;
164- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
165- const filePath = writeReplayFile ( root , [ 'open "Demo"' , 'click "Save"' , 'close' ] ) ;
166- const commands : string [ ] = [ ] ;
167-
168- const response = await runReplayScriptFile ( {
169- req : baseReq ( { positionals : [ filePath ] , flags : { replayKeepSession : true } } ) ,
170- sessionName,
171- logPath : path . join ( root , 'daemon.log' ) ,
172- sessionStore,
173- invoke : async ( req ) => {
174- commands . push ( req . command ) ;
175- if ( req . command === 'close' ) sessionStore . delete ( sessionName ) ;
176- return { ok : true , data : { } } ;
177- } ,
178- } ) ;
179-
180- expect ( commands ) . toEqual ( [ 'open' , 'click' ] ) ;
181- expect ( response . ok ) . toBe ( true ) ;
182- if ( ! response . ok ) return ;
183- expect ( sessionStore . get ( sessionName ) ) . toBeDefined ( ) ;
184- expect ( response . data ) . toMatchObject ( { sessionActive : true , replayed : 2 } ) ;
185- } ) ;
186-
187- test ( '--keep-session preserves an interior close instead of broad command filtering' , async ( ) => {
188- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-interior-close-' ) ) ;
189- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
190- const sessionName = 'default' ;
191- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
192- const filePath = writeReplayFile ( root , [ 'open "Demo"' , 'close' , 'open "Next"' ] ) ;
193- const commands : string [ ] = [ ] ;
194-
195- const response = await runReplayScriptFile ( {
196- req : baseReq ( { positionals : [ filePath ] , flags : { replayKeepSession : true } } ) ,
197- sessionName,
198- logPath : path . join ( root , 'daemon.log' ) ,
199- sessionStore,
200- invoke : async ( req ) => {
201- commands . push ( req . command ) ;
202- return { ok : true , data : { } } ;
203- } ,
204- } ) ;
205-
206- expect ( response . ok ) . toBe ( true ) ;
207- expect ( commands ) . toEqual ( [ 'open' , 'close' , 'open' ] ) ;
208- } ) ;
209-
210- test ( '--keep-session is a no-op for an already close-less script' , async ( ) => {
211- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-close-less-' ) ) ;
212- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
213- const sessionName = 'default' ;
214- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
215- const filePath = writeReplayFile ( root , [ 'open "Demo"' , 'click "Save"' ] ) ;
216- const invoke = vi . fn ( async ( _req : DaemonRequest ) => ( { ok : true as const , data : { } } ) ) ;
217-
218- const response = await runReplayScriptFile ( {
219- req : baseReq ( { positionals : [ filePath ] , flags : { replayKeepSession : true } } ) ,
220- sessionName,
221- logPath : path . join ( root , 'daemon.log' ) ,
222- sessionStore,
223- invoke,
224- } ) ;
225-
226- expect ( response . ok ) . toBe ( true ) ;
227- expect ( invoke . mock . calls . map ( ( [ req ] ) => req . command ) ) . toEqual ( [ 'open' , 'click' ] ) ;
228- if ( ! response . ok ) return ;
229- expect ( ( response . data as { sessionActive : boolean } ) . sessionActive ) . toBe ( true ) ;
230- } ) ;
231-
232- test ( '--keep-session rejects Maestro YAML before engine dispatch' , async ( ) => {
233- const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-keep-maestro-' ) ) ;
234- const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
235- const sessionName = 'default' ;
236- sessionStore . set ( sessionName , makeIosSession ( sessionName ) ) ;
237- const filePath = path . join ( root , 'flow.yaml' ) ;
238- fs . writeFileSync ( filePath , [ 'appId: com.example.app' , '---' , '- launchApp' ] . join ( '\n' ) ) ;
239- const invoke = vi . fn ( async ( ) => ( { ok : true as const , data : { } } ) ) ;
240-
241- const response = await runReplayScriptFile ( {
242- req : baseReq ( {
243- positionals : [ filePath ] ,
244- flags : { replayBackend : 'maestro' , replayKeepSession : true } ,
245- } ) ,
246- sessionName,
247- logPath : path . join ( root , 'daemon.log' ) ,
248- sessionStore,
249- invoke,
250- } ) ;
251-
252- expect ( response ) . toMatchObject ( {
253- ok : false ,
254- error : { code : 'INVALID_ARGS' , message : expect . stringContaining ( '--keep-session' ) } ,
255- } ) ;
256- expect ( invoke ) . not . toHaveBeenCalled ( ) ;
257- } ) ;
258-
259106test ( 'Maestro YAML uses the typed engine while .ad remains generic' , async ( ) => {
260107 const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-typed-maestro-route-' ) ) ;
261108 const sessionStore = new SessionStore ( path . join ( root , 'sessions' ) ) ;
0 commit comments