import{test,expect}from'bun:test';import{readyIncidentObserved,drained}from'../scripts/lib/incident-readback'; const fact={id:'own',status:'ready',accepted_at:'2026-11-16T04:14:31Z',first_ready_at:'2026-11-16T04:15:22Z',ready_seconds:51},stop='2026-11-16T04:14:30Z',start='2026-11-16T04:15:16Z'; const sample=(at:string,phase='worker_recovery')=>({at,phase,rules:[{name:'MessengerReadyErrorBudgetBurn',state:'Alerting'}]}); test('recognizes firing while the same accepted backlog is recovering after process start',()=>{expect(readyIncidentObserved([sample('2026-11-16T04:15:19Z')],[fact],['own'],stop,start)).toBe(true)}); test('accepts firing during worker stop and requires the complete owned late-job cohort',()=>{expect(readyIncidentObserved([sample('2026-11-16T04:15:10Z','worker_stopped')],[fact],['own'],stop,start)).toBe(true);expect(readyIncidentObserved([sample('2026-11-16T04:15:10Z','worker_stopped')],[],['own'],stop,start)).toBe(false)}); test('rejects an unrelated later alert or timely successful workload',()=>{expect(readyIncidentObserved([sample('2026-11-16T04:17:19Z')],[fact],['own'],stop,start)).toBe(false);expect(readyIncidentObserved([sample('2026-11-16T04:15:19Z')],[{...fact,ready_seconds:2}],['own'],stop,start)).toBe(false)}); test('queue drain needs actual finite samples rather than empty NoData',()=>{expect(drained([])).toBe(false);expect(drained([0])).toBe(true);expect(drained([0,1])).toBe(false);expect(drained([NaN])).toBe(false)});