import {PlaybackBuffer} from './playback-core.js'; export function runPlaybackTests(){ const assert=(value,name)=>{if(!value)throw Error(name);};const results=[]; const q=new PlaybackBuffer(1000,e=>results.push(e.type),'low_latency');q.clear(1); q.push(1,new Float32Array(80).fill(.2),0);q.render(new Float32Array(20),20);assert(!q.started&&q.metrics.underruns===0,'startup no underrun'); q.push(1,new Float32Array(40).fill(.2),30);const out=new Float32Array(20);q.render(out,30);assert(q.started&&out[0]>.1,'100ms buffered start'); for(let t=50;t<=150;t+=20)q.render(out,t); assert(q.metrics.underruns===1&&q.rebuffer,'single underrun'); q.push(1,new Float32Array(80).fill(.3),180);q.render(out,180);assert(q.rebuffer,'wait recovery threshold'); q.push(1,new Float32Array(80).fill(.3),200);q.render(out,200);assert(!q.rebuffer&&out[0]>.2,'recovery'); q.clear(2);q.push(1,new Float32Array(100),210);q.render(out,220);assert(q.length===0&&q.metrics.underruns===0&&!q.ending,'clear immediate old turn rejected'); q.push(2,new Float32Array(10).fill(.5),230);q.end(2);q.render(out,240);assert(q.done&&out[0]>.4&&q.metrics.underruns===0,'short final drains'); q.clear(3);q.push(3,new Float32Array(2001),250);assert(results.includes('overflow')&&q.length===0,'max two seconds'); q.clear(4);q.end(4);q.render(out,260);assert(q.done&&q.metrics.underruns===0,'empty end'); function simulate(mode,gap){const p=new PlaybackBuffer(1000,()=>{},mode);p.clear(1);const block=new Float32Array(10);for(let t=0;t=gap,'explicit startup cost');assert(balanced.maxInterarrivalMs===gap,'interarrival metric');cadence.push({gap,low,balanced});} return {status:'passed',cases:['jitter/startup','underrun_recovery','clear_old_turn','short_tail_end','max_buffer','empty_end','160ms chunks 170/180/190ms cadence'],cadence,events:results}; }