From bf4b57b88ad0e06cdb45b8eacc9ffcba97423f38 Mon Sep 17 00:00:00 2001 From: Pushp Date: Thu, 5 Nov 2026 02:11:51 +0530 Subject: [PATCH] test(key-recovery): make the non-OneHook QR case deterministic Random bytes failed ~2.4% of runs: base45 includes a space and open() trims the scanned text, so a random code with a leading/trailing space decoded misaligned ('corrupt'). Use fixed foreign bytes. --- src/tests/key-recovery.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tests/key-recovery.test.ts b/src/tests/key-recovery.test.ts index 416842a..984e959 100644 --- a/src/tests/key-recovery.test.ts +++ b/src/tests/key-recovery.test.ts @@ -388,9 +388,12 @@ describe('sealRecoveryBundle / openRecoveryBundle', () => { it('rejects a non-OneHook QR code and an unknown protocol version distinctly', async () => { const { seal, open } = await scenario(); - await expect( - open(base45Encode(globalThis.crypto.getRandomValues(new Uint8Array(120)))) - ).rejects.toThrow(/not a OneHook recovery code/i); + // Fixed, non-OneHook bytes. Random bytes made this flaky: base45 includes a space, and open() + // trims the scanned text, so a random code that began or ended with a space decoded misaligned + // ("corrupt") about one run in forty (2.4%). + const foreign = base45Encode(Uint8Array.from({ length: 120 }, (_, i) => (i * 37 + 11) & 0xff)); + expect(foreign).toBe(foreign.trim()); + await expect(open(foreign)).rejects.toThrow(/not a OneHook recovery code/i); const sealed = base45Decode(await seal()); sealed[3] = 0x09;