Skip to content

Commit 8139aeb

Browse files
committed
refactor(record): store the finished stop response under one manifest key
The manifest now holds the completion as the one object record stop returned, so a replay cannot lose a field between an encoder and a decoder, and the reader lives with the stop path that needs it. Recovery still refuses a response whose served path or caller-side paths are not whole.
1 parent ce97222 commit 8139aeb

6 files changed

Lines changed: 195 additions & 298 deletions

‎src/daemon/__tests__/screen-recording-completion-metadata.test.ts‎

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎src/daemon/__tests__/screen-recording-stop-recovery.test.ts‎

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import { expect, test } from 'vitest';
44
import type { JsonObject } from '@agent-device/contracts/client';
55
import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime';
6+
import type { ScreenRecordingCompletion } from '@agent-device/contracts/screen-recording-runtime';
67
import { createDurableResourceEnvelope } from '@agent-device/capture-kit';
78
import type { DeviceInfo } from '@agent-device/kernel/device';
89
import { 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

5071
test('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+
101148
function makeHarness() {
102149
const sessionStore = makeSessionStore('screen-recording-stop-recovery-');
103150
const outputDir = mkdtempForTestSync('screen-recording-stop-recovery-output-');

‎src/daemon/handlers/__tests__/record-runtime-stop-recovery.test.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,6 @@ test('a recovered stop does not record a second session stop action', async () =
176176
expect(actions.filter((action) => action.positionals[0] === 'stop')).toHaveLength(1);
177177
});
178178

179-
test('record stop refuses a completed export owned by another session', async () => {
180-
const harness = makeRecordRuntimeHarness('record-runtime-replayed-stop-cross-session-');
181-
const outPath = writeRecording('record-runtime-replayed-stop-cross-session-output-');
182-
await harness.run(['start', outPath]);
183-
await harness.run(['stop']);
184-
const resourcePath = recordingResourcePath(harness.sessionStore, harness.sessionName);
185-
const record = screenRecordingResourceStore.read(resourcePath);
186-
if (record.status !== 'decoded') throw new Error('Expected decoded recording manifest');
187-
screenRecordingResourceStore.write(resourcePath, {
188-
...record.envelope,
189-
sessionId: 'recording-b',
190-
});
191-
192-
const recovered = await harness.run(['stop']);
193-
194-
expect(recovered).toMatchObject({
195-
ok: false,
196-
error: { code: 'COMMAND_FAILED', details: { reason: 'runtime-contract-invalid' } },
197-
});
198-
expect(harness.runtime.bindExactDeviceCalls).not.toHaveBeenCalled();
199-
});
200-
201179
test('record stop reports no active recording once a completed export is gone', async () => {
202180
const harness = makeRecordRuntimeHarness('record-runtime-deleted-stop-');
203181
const outPath = writeRecording('record-runtime-deleted-stop-output-');

‎src/daemon/screen-recording-completion-metadata.ts‎

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)