feat(dev): correlate telemetry recovery, safety stops and passive drive evidence

This commit is contained in:
DCCONSTRUCTIONS
2026-11-21 20:58:26 +03:00
parent 43d4916331
commit d4ed96f3cd
73 changed files with 4188 additions and 349 deletions
@@ -17,7 +17,7 @@ test('invalid, failed and oversized exports never initiate a download or board r
globalThis.fetch=async(url)=>{assert.ok(url.includes('/diagnostics/local/export'));fetched=true;return {ok:false};};
try{await assert.rejects(saveOperatorCapture('/rover','invalid'),/изменилась/);assert.equal(fetched,false);
await assert.rejects(saveOperatorCapture('/rover','a'.repeat(32)),/выгрузить/);assert.equal(fetched,true);
globalThis.fetch=async()=>({ok:true,blob:async()=>new Blob([new Uint8Array(4*1024*1024+1)])});
globalThis.fetch=async()=>({ok:true,blob:async()=>new Blob([new Uint8Array(33*1024*1024+1)])});
await assert.rejects(saveOperatorCapture('/rover','a'.repeat(32)),/Размер/);
}finally{globalThis.document=priorDocument;globalThis.fetch=priorFetch;}
});
@@ -31,3 +31,32 @@ test('preview checkbox independently excludes metrics from both routes',async()=
const entries=calls.filter(x=>x.body.events.some(y=>y.event==='preview'));assert.equal(entries.length,1);assert.equal(entries[0].url,'/rover/diagnostics/local/events');
}finally{capture.close();globalThis.fetch=previous;}
});
test('passive browser capture buffers without periodic requests or close flush',async()=>{
const previousFetch=globalThis.fetch,previousTimer=globalThis.setInterval,previousClear=globalThis.clearInterval;const ticks=[],calls=[];
globalThis.setInterval=fn=>{ticks.push(fn);return 1;};globalThis.clearInterval=()=>{};
globalThis.fetch=async(url,options)=>{calls.push({url,body:JSON.parse(options.body)});return {ok:true,json:async()=>({accepted:true})};};
const capture=connectRoverEvidence('/passive');
try{
capture.set(null,'local',true,true);roverPreviewEvidence('/passive',{encoder_bps:101});
for(let i=0;i<10;i++)ticks.forEach(fn=>fn());
assert.equal(calls.length,0);
await capture.flush();assert.ok(calls.length>0);
assert.ok(calls.every(call=>call.url==='/passive/diagnostics/local/events'));
roverPreviewEvidence('/passive',{encoder_bps:102});const count=calls.length;capture.close();assert.equal(calls.length,count);
}finally{capture.close();globalThis.fetch=previousFetch;globalThis.setInterval=previousTimer;globalThis.clearInterval=previousClear;}
});
test('recovered browser evidence shares one explicit download with the Core snapshot',async()=>{
const priorDocument=globalThis.document,priorFetch=globalThis.fetch,priorURL=URL.createObjectURL;
let clicks=0,output;
globalThis.document={body:{append:()=>{}},createElement:()=>({click:()=>{clicks++;},remove:()=>{}})};
globalThis.fetch=async()=>({ok:true,blob:async()=>new Blob(['{"source":"core"}\n'])});
URL.createObjectURL=blob=>{output=blob;return 'blob:recovery';};
try{
await saveOperatorCapture('/rover','a'.repeat(32),async()=>{},async(url,id)=>{
assert.equal(url,'/rover');assert.equal(id,'a'.repeat(32));return new Blob(['{"source":"browser","browser_ms":123}\n']);
});
assert.equal(clicks,1);assert.equal(await output.text(),'{"source":"core"}\n{"source":"browser","browser_ms":123}\n');
}finally{globalThis.document=priorDocument;globalThis.fetch=priorFetch;URL.createObjectURL=priorURL;}
});