import assert from 'node:assert/strict' import test from 'node:test' import { ReportPolicy } from '../src/reportPolicy' import { shouldPersist } from '../src/queue/queuePolicy' import type { BugCollectEvent } from '../src/types' test('fatal reports bypass sampling and rate limiting', () => { const policy = new ReportPolicy( 60_000, 1, () => 100, () => 1, ) policy.setSampleRate(0) assert.equal(policy.shouldReport('fatal', true), true) assert.equal(policy.shouldReport('normal', false), false) }) test('fingerprint limit expires with the configured window', () => { let now = 1_000 const policy = new ReportPolicy( 100, 2, () => now, () => 0, ) assert.equal(policy.shouldReport('same', false), true) assert.equal(policy.shouldReport('same', false), true) assert.equal(policy.shouldReport('same', false), false) now += 101 assert.equal(policy.shouldReport('same', false), true) }) test('fatal and error issues are the only events persisted for restart recovery', () => { const base = { type: 'issue', platform: 'android', fingerprint: 'f', timestamp: 1, appKey: 'app', release: '1', environment: 'test', exception: { type: 'Error', value: 'value' }, sessionId: 'session', sdk: { name: 'bugcollect.rn', version: '1.0.0' }, } as const assert.equal(shouldPersist({ ...base, level: 'fatal' } as BugCollectEvent), true) assert.equal(shouldPersist({ ...base, level: 'error' } as BugCollectEvent), true) assert.equal(shouldPersist({ ...base, level: 'warning' } as BugCollectEvent), false) })