import assert from'node:assert/strict'; const u=(b,p)=>b.readBigUInt64LE(p),W=b=>Array.from({length:b.length/8},(_,i)=>u(b,i*8)),zero=b=>assert.ok(b.every(v=>v===0)); export const progressUnits=[Array(8).fill(0),Array(8).fill(4),Array.from({length:8},(_,i)=>i===3?4:8),Array.from({length:8},(_,i)=>i===3?8:12),Array.from({length:8},(_,i)=>i===3?12:16),Array.from({length:8},(_,i)=>i===3?12:16)]; export const progressBaselines=[0,1,1,3,4,4],progressWindows=[0,1,1,2,3,3]; const mask=(1n<<64n)-1n;function rotate(v,n){n=BigInt(n);return((v<>(64n-n)))&mask} export function progressPayload(slot,units){return Array.from({length:64},(_,i)=>(BigInt(slot+1)*0x20850101n)^rotate(BigInt(units),i)^(BigInt(i+1)*0x2085n));} export function progressDigest(slot,units){return progressPayload(slot,units).reduce((sum,v,i)=>(sum+rotate(v,i%17))&mask,0n);} export const progressBinding=cpu=>[1n,0x2045n,1n,BigInt(cpu)],progressIdentity=slot=>[2085n,1n,BigInt(slot),BigInt(slot>>1)]; export function inspectProgressModel(data,index,symbols,original,snapshots){ if(index===5)assert.deepEqual(data.OS_K2085_SAMPLES,snapshots[4].OS_K2085_SAMPLES,'retirement retains the final complete samples'); const root=u(original.OS_K2045_EVIDENCE,48),units=progressUnits[index],e=W(data.OS_K2085_EVIDENCE),primary=BigInt(symbols.OS_K2045_PRIMARY_STACK.address),pointer=e[10];assert.equal(e[11],1168n);assert.ok(pointer%8n===0n&&pointer>=primary+4096n&&pointer+1168n<=primary+69624n);assert.equal(data.progressMonitor.length,1168);assert.deepEqual(data.progressMonitor,data.OS_K2045_PRIMARY_STACK.subarray(Number(pointer-primary),Number(pointer-primary)+1168));const m=data.progressMonitor;assert.equal(u(m,0),root);assert.equal(u(m,1160),BigInt(progressWindows[index])); for(let cpu=0;cpu<4;cpu++){ assert.deepEqual(W(m.subarray(8+cpu*32,40+cpu*32)),progressBinding(cpu));const row=data.OS_K2085_SAMPLES.subarray(cpu*232,(cpu+1)*232);assert.deepEqual(W(row.subarray(0,32)),progressBinding(cpu));assert.equal(u(row,32),BigInt(units[cpu*2]+units[cpu*2+1])); for(let local=0;local<2;local++){ const slot=cpu*2+local,sample=row.subarray(40+local*96,136+local*96),words=W(sample),current=BigInt(units[slot]);assert.deepEqual(words.slice(0,4),progressBinding(cpu));assert.deepEqual(words.slice(4,8),progressIdentity(slot));assert.equal(words[8],current);assert.deepEqual(W(m.subarray(136+slot*32,168+slot*32)),progressIdentity(slot)); if(current===0n)assert.deepEqual(words.slice(9),[0n,0n,0n]);else{assert.ok(words[9]>0n&&words[10]>=words[9]);assert.equal(words[11],progressDigest(slot,units[slot]));assert.equal(words[9],u(snapshots[1].OS_K2085_SAMPLES,cpu*232+40+local*96+72));} const owned=data.OS_K2085_WORKERS.subarray(slot*112,(slot+1)*112);assert.equal(u(owned,104),index===5?0n:1n);if(index!==5){assert.equal(u(owned,0),root);assert.deepEqual(owned.subarray(8,104),sample);} const base=snapshots[progressBaselines[index]].OS_K2085_SAMPLES.subarray(cpu*232+40+local*96,cpu*232+136+local*96);assert.deepEqual(m.subarray(392+slot*96,488+slot*96),base); const payload=data.OS_K2085_PAYLOAD.subarray(slot*512,(slot+1)*512);if(!units[slot])zero(payload);else assert.deepEqual(W(payload),progressPayload(slot,units[slot])); } } zero(data.OS_K2085_CURRENT);assert.equal(u(data.OS_K2085_LOCK,0),index===2?1n:0n); const events=[{number:1,delta:Array(8).fill(4),mask:0,accepted:1},{number:2,delta:Array.from({length:8},(_,i)=>i===3?0:4),mask:8,accepted:0},{number:2,delta:Array.from({length:8},(_,i)=>i===3?4:8),mask:0,accepted:1},{number:3,delta:Array(8).fill(4),mask:0,accepted:1}]; for(let i=0;i<4;i++){const row=data.OS_K2085_WINDOWS.subarray(i*128,(i+1)*128);if(index<=i){zero(row);continue}const event=events[i];assert.deepEqual(W(row),[event.number,...Array.from({length:4},(_,cpu)=>event.delta[cpu*2]+event.delta[cpu*2+1]),...event.delta,0,event.mask,event.accepted].map(BigInt));} return{units,command:89+index,windows:progressWindows[index]}; }