From d7840a811c733577270073015413b98c22e11894 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 15 May 2026 17:24:18 +0200 Subject: [PATCH] test(01-02): add RED codec-check tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two RED tests pin D-20 (codec strict-mode, no silent fallback): - 'throws on unsupported vp9 and emits RECORDING_ERROR' - 'does not throw when vp9 IS supported' vi.resetModules() between tests is critical: module-load side-effects (handshake + port connect) happen once per import, so isolation across the four test files depends on it. chrome.runtime is stubbed locally (no vitest-chrome dependency added, per threat T-1-NEW-02-01 — minimize supply chain for four test files). No 'as any' / no '@ts-ignore'; the cast is 'as unknown as T'. Plan 03 must export assertCodecSupported() from src/offscreen/recorder.ts. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/offscreen/codec-check.test.ts | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/offscreen/codec-check.test.ts diff --git a/tests/offscreen/codec-check.test.ts b/tests/offscreen/codec-check.test.ts new file mode 100644 index 0000000..ea52caa --- /dev/null +++ b/tests/offscreen/codec-check.test.ts @@ -0,0 +1,43 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; + +interface ChromeStub { + runtime: { sendMessage: ReturnType }; +} + +interface GlobalWithChrome { + chrome?: ChromeStub; + MediaRecorder?: { isTypeSupported: (mime: string) => boolean }; +} + +describe('codec strict mode', () => { + beforeEach(() => { + vi.resetModules(); + (globalThis as unknown as GlobalWithChrome).chrome = { + runtime: { sendMessage: vi.fn() }, + }; + }); + + it('throws on unsupported vp9 and emits RECORDING_ERROR', async () => { + (globalThis as unknown as GlobalWithChrome).MediaRecorder = { + isTypeSupported: vi.fn().mockReturnValue(false), + }; + const mod = await import('../../src/offscreen/recorder'); + expect(() => mod.assertCodecSupported()).toThrow(/vp9 unsupported/); + const stub = (globalThis as unknown as GlobalWithChrome).chrome!; + expect(stub.runtime.sendMessage).toHaveBeenCalledWith( + expect.objectContaining({ type: 'RECORDING_ERROR' }) + ); + }); + + it('does not throw when vp9 IS supported', async () => { + (globalThis as unknown as GlobalWithChrome).MediaRecorder = { + isTypeSupported: vi.fn().mockReturnValue(true), + }; + const mod = await import('../../src/offscreen/recorder'); + expect(() => mod.assertCodecSupported()).not.toThrow(); + const stub = (globalThis as unknown as GlobalWithChrome).chrome!; + expect(stub.runtime.sendMessage).not.toHaveBeenCalledWith( + expect.objectContaining({ type: 'RECORDING_ERROR' }) + ); + }); +});