@@ -3,6 +3,7 @@ import path from 'node:path';
33import { expect , test } from 'vitest' ;
44import type { JsonObject } from '@agent-device/contracts/client' ;
55import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime' ;
6+ import type { ScreenRecordingCompletion } from '@agent-device/contracts/screen-recording-runtime' ;
67import { createDurableResourceEnvelope } from '@agent-device/capture-kit' ;
78import type { DeviceInfo } from '@agent-device/kernel/device' ;
89import { deviceIdentity } from '@agent-device/kernel/device' ;
@@ -24,27 +25,47 @@ const SESSION_DEVICE: DeviceInfo = {
2425 kind : 'emulator' ,
2526} ;
2627
27- test ( 'a completed manifest hands its surviving export to a later stop ' , async ( ) => {
28+ test ( 'a completed manifest with no surviving video serves nothing ' , async ( ) => {
2829 const harness = makeHarness ( ) ;
29- const completion = await completeRecording ( harness , {
30- clientOutPath : '/workspace/capture.mp4' ,
31- telemetryPath : '/workspace/capture.gesture-telemetry.json' ,
32- } ) ;
30+ await completeRecording ( harness ) ;
31+ fs . rmSync ( harness . videoPath ) ;
3332
3433 expect ( resolveScreenRecordingStopRecovery ( { ...harness . params , device : SESSION_DEVICE } ) ) . toEqual (
35- { kind : 'completed' , completion } ,
34+ { kind : 'none' } ,
3635 ) ;
37- expect ( screenRecordingManifestIsTerminal ( harness . params ) ) . toBe ( true ) ;
3836} ) ;
3937
40- test ( 'a completed manifest with no surviving video serves nothing ' , async ( ) => {
38+ test ( 'a completed manifest hands back the whole stop response it stored ' , async ( ) => {
4139 const harness = makeHarness ( ) ;
42- await completeRecording ( harness ) ;
43- fs . rmSync ( harness . videoPath ) ;
40+ const completion = fullCompletion ( harness . videoPath ) ;
41+ fs . writeFileSync ( harness . videoPath , 'mp4' ) ;
42+ writeManifest ( harness , encodeScreenRecordingCompletionMetadata ( completion ) ) ;
4443
4544 expect ( resolveScreenRecordingStopRecovery ( { ...harness . params , device : SESSION_DEVICE } ) ) . toEqual (
46- { kind : 'none' } ,
45+ { kind : 'completed' , completion } ,
4746 ) ;
47+ expect ( screenRecordingManifestIsTerminal ( harness . params ) ) . toBe ( true ) ;
48+ } ) ;
49+
50+ test ( 'a completed manifest whose stored response is damaged serves nothing' , async ( ) => {
51+ const harness = makeHarness ( ) ;
52+ const stored = encodeScreenRecordingCompletionMetadata ( fullCompletion ( harness . videoPath ) ) ;
53+ fs . writeFileSync ( harness . videoPath , 'mp4' ) ;
54+
55+ const damages : JsonObject [ ] = [
56+ { outPath : 0 } ,
57+ { clientOutPath : '' } ,
58+ { completedAt : 'later' } ,
59+ { chunks : [ { index : 'first' , path : '/daemon/capture-0.mp4' } ] } ,
60+ { activeSessionApp : { bundleId : '' } } ,
61+ ] ;
62+
63+ for ( const damaged of damages ) {
64+ writeManifest ( harness , withStoredCompletion ( stored , damaged ) ) ;
65+ expect (
66+ resolveScreenRecordingStopRecovery ( { ...harness . params , device : SESSION_DEVICE } ) ,
67+ ) . toEqual ( { kind : 'none' } ) ;
68+ }
4869} ) ;
4970
5071test ( 'a completed manifest with no completion metadata serves nothing' , async ( ) => {
@@ -98,6 +119,32 @@ test('a session with no recording manifest has nothing to recover', () => {
98119 expect ( screenRecordingManifestIsTerminal ( harness . params ) ) . toBe ( false ) ;
99120} ) ;
100121
122+ function fullCompletion ( outPath : string ) : ScreenRecordingCompletion {
123+ return {
124+ backend : 'simctl' ,
125+ outPath,
126+ startedAt : 1 ,
127+ completedAt : 4 ,
128+ scope : 'app' ,
129+ showTouches : true ,
130+ recordOnlySession : false ,
131+ clientOutPath : '/workspace/capture.mp4' ,
132+ telemetryPath : '/workspace/capture.gesture-telemetry.json' ,
133+ warning : 'recording was truncated at the platform limit' ,
134+ overlayWarning : 'touch overlay burn-in is only available on macOS hosts' ,
135+ activeSessionApp : { bundleId : 'dev.example.app' , name : 'Example' } ,
136+ chunks : [
137+ { index : 0 , path : '/daemon/capture-0.mp4' , clientOutPath : '/workspace/capture-0.mp4' } ,
138+ { index : 1 , path : '/daemon/capture-1.mp4' } ,
139+ ] ,
140+ } ;
141+ }
142+
143+ function withStoredCompletion ( metadata : JsonObject , patch : JsonObject ) : JsonObject {
144+ const completion = metadata . completion as JsonObject ;
145+ return { ...metadata , completion : { ...completion , ...patch } } ;
146+ }
147+
101148function makeHarness ( ) {
102149 const sessionStore = makeSessionStore ( 'screen-recording-stop-recovery-' ) ;
103150 const outputDir = mkdtempForTestSync ( 'screen-recording-stop-recovery-output-' ) ;
0 commit comments