From b6be356e4053f9934d24597638a300fa27694767 Mon Sep 17 00:00:00 2001 From: Dean Wang Date: Thu, 3 Sep 2026 07:40:57 +0800 Subject: [PATCH] test(extension): cover UUID fallback during recording startup --- .../__tests__/record-frame-agent.test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/extension/src/content/__tests__/record-frame-agent.test.ts b/apps/extension/src/content/__tests__/record-frame-agent.test.ts index 0c0a651..7c55de3 100644 --- a/apps/extension/src/content/__tests__/record-frame-agent.test.ts +++ b/apps/extension/src/content/__tests__/record-frame-agent.test.ts @@ -45,10 +45,32 @@ function portHarness() { describe("RecordFrameAgent", () => { afterEach(() => { + vi.unstubAllGlobals(); document.documentElement.removeAttribute(RECORD_DOCUMENT_ATTRIBUTE); document.body.replaceChildren(); }); + it("starts when crypto.randomUUID is unavailable", async () => { + const harness = portHarness(); + const getRandomValues = vi.fn((bytes: Uint8Array) => { + bytes.fill(0x11); + return bytes; + }); + vi.stubGlobal("crypto", { getRandomValues }); + vi.stubGlobal("chrome", { + runtime: { + connect: vi.fn(() => harness.port), + sendMessage: vi.fn(), + }, + }); + const agent = new RecordFrameAgent(); + + await expect( + agent.start({ type: RECORD_FRAME_START, requestId: "rec-http", startedAtMs: 10 }), + ).resolves.toEqual({ ok: true }); + expect(getRandomValues).toHaveBeenCalled(); + }); + it("keeps a failed stop retryable and flushes the final dirty fill", async () => { const harness = portHarness(); const sendMessage = vi