1+ import { makeCaptureSessionBinding } from '../../durable-capture/session-binding.fixtures.ts' ;
12import { expect , test , vi } from 'vitest' ;
23import { PendingTransferGuard } from '@agent-device/contracts/async-lifecycle' ;
34import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime' ;
@@ -35,6 +36,10 @@ test('screen recording persists durable truth before adopting only handle and en
3536 const sessionName = 'recording' ;
3637 const session : TestRecordingSession = { name : sessionName , device } ;
3738 sessionStore . set ( sessionName , session ) ;
39+ const binding = makeCaptureSessionBinding ( sessionStore , sessionName , {
40+ read : ( session ) => session . screenRecording ,
41+ replace : ( session , screenRecording ) => ( { ...session , screenRecording } ) ,
42+ } ) ;
3843 const owner = localRuntimeOwner ( 'android' ) ;
3944 const fence = { token : 'recording-fence' , generation : 1 } as const ;
4045 const finish = vi . fn ( async ( ) => ( {
@@ -79,9 +84,7 @@ test('screen recording persists durable truth before adopting only handle and en
7984
8085 await adoptStartedScreenRecording ( {
8186 admissionLedger : createScreenRecordingAdmissionLedger ( ) ,
82- session,
83- sessionName,
84- sessionStore,
87+ binding,
8588 device : session . device ,
8689 owner,
8790 fence,
@@ -101,9 +104,10 @@ test('screen recording persists durable truth before adopting only handle and en
101104
102105 const active = sessionStore . get ( sessionName ) ;
103106 if ( ! active ) throw new Error ( 'Expected screen-recording session' ) ;
104- await expect (
105- finishLiveScreenRecording ( { intent : 'capture' , session : active , sessionName, sessionStore } ) ,
106- ) . resolves . toMatchObject ( { backend : 'android' , outPath : '/tmp/recording.mp4' } ) ;
107+ await expect ( finishLiveScreenRecording ( { intent : 'capture' , binding } ) ) . resolves . toMatchObject ( {
108+ backend : 'android' ,
109+ outPath : '/tmp/recording.mp4' ,
110+ } ) ;
107111 expect ( finish ) . toHaveBeenCalledOnce ( ) ;
108112 expect ( sessionStore . get ( sessionName ) ?. screenRecording ) . toBeUndefined ( ) ;
109113} ) ;
@@ -115,6 +119,10 @@ test('a failed recording finish keeps the record open and never disposes the rec
115119 const sessionName = 'recording' ;
116120 const session : TestRecordingSession = { name : sessionName , device } ;
117121 sessionStore . set ( sessionName , session ) ;
122+ const binding = makeCaptureSessionBinding ( sessionStore , sessionName , {
123+ read : ( session ) => session . screenRecording ,
124+ replace : ( session , screenRecording ) => ( { ...session , screenRecording } ) ,
125+ } ) ;
118126 const owner = localRuntimeOwner ( 'android' ) ;
119127 const fence = { token : 'recording-fence' , generation : 1 } as const ;
120128 const finishError = new Error ( 'failed to retrieve playable Android recording' ) ;
@@ -150,9 +158,7 @@ test('a failed recording finish keeps the record open and never disposes the rec
150158 } ) ;
151159 await adoptStartedScreenRecording ( {
152160 admissionLedger : createScreenRecordingAdmissionLedger ( ) ,
153- session,
154- sessionName,
155- sessionStore,
161+ binding,
156162 device : session . device ,
157163 owner,
158164 fence,
@@ -163,9 +169,7 @@ test('a failed recording finish keeps the record open and never disposes the rec
163169
164170 const active = sessionStore . get ( sessionName ) ;
165171 if ( ! active ) throw new Error ( 'Expected screen-recording session' ) ;
166- await expect (
167- finishLiveScreenRecording ( { intent : 'capture' , session : active , sessionName, sessionStore } ) ,
168- ) . rejects . toBe ( finishError ) ;
172+ await expect ( finishLiveScreenRecording ( { intent : 'capture' , binding } ) ) . rejects . toBe ( finishError ) ;
169173
170174 expect ( forceCleanup ) . not . toHaveBeenCalled ( ) ;
171175 expect ( sessionStore . get ( sessionName ) ?. screenRecording ?. handle ) . toBe ( handle ) ;
@@ -182,6 +186,10 @@ test('a record stop that fails after collecting resumes through the fence withou
182186 const sessionName = 'recording' ;
183187 const session : TestRecordingSession = { name : sessionName , device } ;
184188 sessionStore . set ( sessionName , session ) ;
189+ const binding = makeCaptureSessionBinding ( sessionStore , sessionName , {
190+ read : ( session ) => session . screenRecording ,
191+ replace : ( session , screenRecording ) => ( { ...session , screenRecording } ) ,
192+ } ) ;
185193 const owner = localRuntimeOwner ( 'android' ) ;
186194 const fence = { token : 'recording-fence' , generation : 1 } as const ;
187195 const signals = vi . fn ( async ( ) => ( { observation : { recorder : 'confirmed' as const } } ) ) ;
@@ -216,9 +224,7 @@ test('a record stop that fails after collecting resumes through the fence withou
216224 ) ;
217225 await adoptStartedScreenRecording ( {
218226 admissionLedger : createScreenRecordingAdmissionLedger ( ) ,
219- session,
220- sessionName,
221- sessionStore,
227+ binding,
222228 device : session . device ,
223229 owner,
224230 fence,
@@ -239,9 +245,7 @@ test('a record stop that fails after collecting resumes through the fence withou
239245 if ( ! active ) throw new Error ( 'Expected screen-recording session' ) ;
240246 return finishLiveScreenRecording ( {
241247 intent : 'capture' ,
242- session : active ,
243- sessionName,
244- sessionStore,
248+ binding,
245249 } ) ;
246250 } ;
247251
0 commit comments