import { createRequestId } from '@/utils/request-id' describe('request ID generation', () => { it('uses the browser native UUID when available', () => { const randomUUID = jest.fn(() => 'native-request-id') expect(createRequestId({ randomUUID })).toBe('native-request-id') expect(randomUUID).toHaveBeenCalledTimes(1) }) it('formats secure random bytes as an RFC 4122 version 4 UUID', () => { const getRandomValues = jest.fn(bytes => { bytes.fill(0xff) return bytes }) expect(createRequestId({ getRandomValues })).toBe('ffffffff-ffff-4fff-bfff-ffffffffffff') expect(getRandomValues).toHaveBeenCalledTimes(1) }) it('supports public HTTP contexts without Web Crypto', () => { jest.spyOn(Math, 'random').mockReturnValue(0) expect(createRequestId(null)).toBe('00000000-0000-4000-8000-000000000000') Math.random.mockRestore() }) })