|
1 | 1 | import { expect, test, vi } from 'vitest'; |
2 | 2 | import { localRuntimeOwner } from '@agent-device/contracts/platform-runtime'; |
| 3 | +import { recordingFileStore } from '@agent-device/capture-kit/recording-artifact-fixtures'; |
| 4 | +import { nativeRecordingPath } from '@agent-device/capture-kit/recording-stop-sequence'; |
3 | 5 | import { createAppleScreenRecordingOperations } from './runtime.ts'; |
4 | 6 | import { |
5 | 7 | appleRecordingHost, |
6 | 8 | coreDevice, |
7 | 9 | processIdentity, |
8 | 10 | recordingInput, |
| 11 | + recordingOutputPath, |
9 | 12 | simulator, |
| 13 | + simulatorRecorderStart, |
10 | 14 | } from './runtime.fixtures.ts'; |
11 | 15 |
|
12 | 16 | test('daemon-loss cleanup distinguishes live, dead, replaced, and corrupt simulator identity', async () => { |
@@ -68,6 +72,125 @@ test('daemon-loss cleanup distinguishes live, dead, replaced, and corrupt simula |
68 | 72 | expect(inspectProcess).not.toHaveBeenCalled(); |
69 | 73 | }); |
70 | 74 |
|
| 75 | +type SimulatorHostOptions = Parameters<typeof appleRecordingHost>[0]; |
| 76 | + |
| 77 | +function simulatorHost( |
| 78 | + files: ReturnType<typeof recordingFileStore>, |
| 79 | + extra: SimulatorHostOptions = {}, |
| 80 | +) { |
| 81 | + return appleRecordingHost({ |
| 82 | + ...extra, |
| 83 | + files, |
| 84 | + apple: { |
| 85 | + ...simulatorRecorderStart(), |
| 86 | + inspectProcess: async () => 'missing' as const, |
| 87 | + ...extra.apple, |
| 88 | + }, |
| 89 | + }); |
| 90 | +} |
| 91 | + |
| 92 | +function recoveryOperations(host: ReturnType<typeof appleRecordingHost>) { |
| 93 | + return createAppleScreenRecordingOperations({ |
| 94 | + host, |
| 95 | + device: simulator, |
| 96 | + owner: localRuntimeOwner('apple'), |
| 97 | + signal: new AbortController().signal, |
| 98 | + }); |
| 99 | +} |
| 100 | + |
| 101 | +async function startSimulatorRecording( |
| 102 | + files: ReturnType<typeof recordingFileStore>, |
| 103 | + overrides: Parameters<typeof recordingInput>[0] = {}, |
| 104 | +) { |
| 105 | + return await recoveryOperations(simulatorHost(files)).screenRecordingStart( |
| 106 | + recordingInput(overrides), |
| 107 | + ); |
| 108 | +} |
| 109 | + |
| 110 | +test('a simulator recording whose recorder died with its daemon exports through the retried stop', async () => { |
| 111 | + const files = recordingFileStore(); |
| 112 | + const started = await startSimulatorRecording(files); |
| 113 | + const nativePath = nativeRecordingPath(recordingOutputPath()); |
| 114 | + |
| 115 | + const reattached = await recoveryOperations(simulatorHost(files)).screenRecordingReattach({ |
| 116 | + envelope: started.envelope, |
| 117 | + }); |
| 118 | + expect(reattached).toMatchObject({ status: 'active' }); |
| 119 | + if (reattached.status !== 'active') throw new Error('expected an exportable recording'); |
| 120 | + |
| 121 | + await expect(reattached.handle.finish()).resolves.toMatchObject({ |
| 122 | + status: 'completed', |
| 123 | + result: { |
| 124 | + backend: 'simctl recordVideo', |
| 125 | + outPath: recordingOutputPath(), |
| 126 | + scope: 'device', |
| 127 | + stopObservation: { recorder: 'confirmed' }, |
| 128 | + nativePathDisposition: 'retired', |
| 129 | + }, |
| 130 | + }); |
| 131 | + expect(files.exists(recordingOutputPath())).toBe(true); |
| 132 | + expect(files.exists(nativePath)).toBe(false); |
| 133 | +}); |
| 134 | + |
| 135 | +test('a recovered export discloses the touch overlay whose events died with the daemon', async () => { |
| 136 | + const files = recordingFileStore(); |
| 137 | + const started = await startSimulatorRecording(files, { showTouches: true }); |
| 138 | + |
| 139 | + const reattached = await recoveryOperations(simulatorHost(files)).screenRecordingReattach({ |
| 140 | + envelope: started.envelope, |
| 141 | + }); |
| 142 | + if (reattached.status !== 'active') throw new Error('expected an exportable recording'); |
| 143 | + const finished = await reattached.handle.finish(); |
| 144 | + if (finished.status !== 'completed') throw new Error('expected a completed export'); |
| 145 | + expect(finished.result.overlayWarning).toContain('overlay unavailable'); |
| 146 | +}); |
| 147 | + |
| 148 | +test('a simulator recording left by a manifest without export coordinates is still a loss', async () => { |
| 149 | + const files = recordingFileStore(); |
| 150 | + const started = await startSimulatorRecording(files); |
| 151 | + const { recording: _dropped, ...bodyWithoutCoordinates } = started.envelope.descriptor.body; |
| 152 | + |
| 153 | + await expect( |
| 154 | + recoveryOperations(simulatorHost(files)).screenRecordingReattach({ |
| 155 | + envelope: { |
| 156 | + ...started.envelope, |
| 157 | + descriptor: { ...started.envelope.descriptor, body: bodyWithoutCoordinates }, |
| 158 | + }, |
| 159 | + }), |
| 160 | + ).resolves.toEqual({ status: 'missing' }); |
| 161 | +}); |
| 162 | + |
| 163 | +test('a gone recorder with no readable video left behind is answered as a loss', async () => { |
| 164 | + const started = await startSimulatorRecording(recordingFileStore()); |
| 165 | + |
| 166 | + await expect( |
| 167 | + recoveryOperations(simulatorHost(recordingFileStore())).screenRecordingReattach({ |
| 168 | + envelope: started.envelope, |
| 169 | + }), |
| 170 | + ).resolves.toEqual({ status: 'missing' }); |
| 171 | +}); |
| 172 | + |
| 173 | +test('unreadable export coordinates refuse reattach before the recorder is probed', async () => { |
| 174 | + const files = recordingFileStore(); |
| 175 | + const started = await startSimulatorRecording(files); |
| 176 | + const inspectProcess = vi.fn(async () => 'missing' as const); |
| 177 | + |
| 178 | + await expect( |
| 179 | + recoveryOperations(simulatorHost(files, { apple: { inspectProcess } })).screenRecordingReattach( |
| 180 | + { |
| 181 | + envelope: { |
| 182 | + ...started.envelope, |
| 183 | + descriptor: { |
| 184 | + ...started.envelope.descriptor, |
| 185 | + body: { ...started.envelope.descriptor.body, recording: { outPath: 42 } }, |
| 186 | + }, |
| 187 | + }, |
| 188 | + }, |
| 189 | + ), |
| 190 | + ).resolves.toMatchObject({ status: 'unreattachable', reason: 'descriptor-invalid' }); |
| 191 | + expect(inspectProcess).not.toHaveBeenCalled(); |
| 192 | +}); |
| 193 | + |
71 | 194 | test('runner recovery never stops a replacement session owner', async () => { |
72 | 195 | const operations = createAppleScreenRecordingOperations({ |
73 | 196 | host: appleRecordingHost(), |
|
0 commit comments