|
2 | 2 | DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER, |
3 | 3 | EnvironmentId, |
4 | 4 | ThreadId, |
| 5 | + PreviewCaptureFailure, |
5 | 6 | } from "@t3tools/contracts"; |
6 | 7 | import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; |
7 | 8 |
|
@@ -334,11 +335,13 @@ describe("browser recording", () => { |
334 | 335 | }); |
335 | 336 |
|
336 | 337 | await startBrowserRecording("recording-tab"); |
337 | | - FakeMediaRecorder.stopError = new Error("stop failed"); |
| 338 | + const cleanupCause = new DOMException("Could not start video source", "NotReadableError"); |
| 339 | + FakeMediaRecorder.stopError = cleanupCause; |
338 | 340 |
|
339 | 341 | await expect(stopBrowserRecording("recording-tab")).rejects.toMatchObject({ |
340 | 342 | operation: "cleanup", |
341 | 343 | tabId: "recording-tab", |
| 344 | + message: "Browser recording operation cleanup failed for tab recording-tab.", |
342 | 345 | }); |
343 | 346 | expect(stopTrack).toHaveBeenCalledOnce(); |
344 | 347 | }); |
@@ -406,6 +409,73 @@ describe("browser recording", () => { |
406 | 409 | expect(events.at(-1)).toBe("clear"); |
407 | 410 | }); |
408 | 411 |
|
| 412 | + it.each([false, true])( |
| 413 | + "explains real video-source rejection and permits retry when cleanup fails: %s", |
| 414 | + async (cleanupFails) => { |
| 415 | + const cause = new DOMException("Could not start video source", "NotReadableError"); |
| 416 | + const cleanupCause = new Error("native stop failed"); |
| 417 | + getDisplayMedia.mockRejectedValueOnce(cause); |
| 418 | + if (cleanupFails) stopScreencast.mockRejectedValueOnce(cleanupCause); |
| 419 | + |
| 420 | + const error = await startBrowserRecording("recording-tab").catch( |
| 421 | + (failure: unknown) => failure, |
| 422 | + ); |
| 423 | + expect(error).toMatchObject({ |
| 424 | + _tag: "BrowserRecordingOperationError", |
| 425 | + operation: "capture-media-stream", |
| 426 | + tabId: "recording-tab", |
| 427 | + message: |
| 428 | + "Unable to start the preview video source. Make sure the capture host is unlocked " + |
| 429 | + "and its display is on, then retry. NotReadableError: Could not start video source", |
| 430 | + cause: cleanupFails ? { cause, errors: [cause, cleanupCause] } : cause, |
| 431 | + }); |
| 432 | + expect(stopScreencast).toHaveBeenCalledWith("recording-tab"); |
| 433 | + expect(FakeMediaRecorder.instances).toHaveLength(0); |
| 434 | + expect(save).not.toHaveBeenCalled(); |
| 435 | + expect(readActiveBrowserRecordingTabIds()).toEqual(new Set()); |
| 436 | + expect(useBrowserSurfaceStore.getState().activityByTabId["recording-tab"]).toBeUndefined(); |
| 437 | + |
| 438 | + await startBrowserRecording("recording-tab"); |
| 439 | + await stopBrowserRecording("recording-tab"); |
| 440 | + expect(getDisplayMedia).toHaveBeenCalledTimes(2); |
| 441 | + }, |
| 442 | + ); |
| 443 | + |
| 444 | + it("keeps unrecognized acquisition failures generic", async () => { |
| 445 | + const cause = new Error("capture failed"); |
| 446 | + cause.name = "NotReadableError"; |
| 447 | + getDisplayMedia.mockRejectedValueOnce(cause); |
| 448 | + |
| 449 | + await expect(startBrowserRecording("recording-tab")).rejects.toMatchObject({ |
| 450 | + operation: "capture-media-stream", |
| 451 | + cause, |
| 452 | + message: "Browser recording operation capture-media-stream failed for tab recording-tab.", |
| 453 | + }); |
| 454 | + }); |
| 455 | + |
| 456 | + it("reports a native arm diagnostic immediately and frees the tab for a retry", async () => { |
| 457 | + const cause = new PreviewCaptureFailure({ |
| 458 | + reason: "renderer-unavailable", |
| 459 | + stage: "recording-start", |
| 460 | + }); |
| 461 | + startScreencast.mockRejectedValueOnce(cause); |
| 462 | + |
| 463 | + await expect(startBrowserRecording("recording-tab")).rejects.toMatchObject({ |
| 464 | + _tag: "BrowserRecordingOperationError", |
| 465 | + operation: "start-screencast", |
| 466 | + tabId: "recording-tab", |
| 467 | + cause, |
| 468 | + message: cause.message, |
| 469 | + }); |
| 470 | + expect(getDisplayMedia).not.toHaveBeenCalled(); |
| 471 | + expect(readActiveBrowserRecordingTabIds()).toEqual(new Set()); |
| 472 | + expect(useBrowserSurfaceStore.getState().activityByTabId["recording-tab"]).toBeUndefined(); |
| 473 | + |
| 474 | + await startBrowserRecording("recording-tab"); |
| 475 | + await stopBrowserRecording("recording-tab"); |
| 476 | + expect(getDisplayMedia).toHaveBeenCalledOnce(); |
| 477 | + }); |
| 478 | + |
409 | 479 | it("times out stalled stream acquisition and stops a late stream", async () => { |
410 | 480 | vi.useFakeTimers(); |
411 | 481 | let finishCapture!: (stream: MediaStream) => void; |
|
0 commit comments