Files
compras/scripts/replenishment-health-http.mjs
2026-11-03 11:51:44 +02:00

25 lines
1.6 KiB
JavaScript

import fs from 'node:fs/promises';
import assert from 'node:assert/strict';
const source = await fs.readFile('scripts/supplier-evaluation-check.mjs', 'utf8');
const common = source.slice(source.indexOf('const base ='), source.indexOf('const author ='));
await new Function('fs','assert','return (async()=>{'+common+`
const records=[];
for(const [role,expected] of [['admin',200],['warehouse',403]]) {
const viewer=client(); await viewer.enter(role);
assert.equal((await viewer.request('/contexto','POST',{area:'procurement',option:'procurement.internal'})).status,302);
const result=await viewer.request('/stock/piloto');assert.equal(result.status,expected);
if(expected===200) {
const runtime=result.page.props.report.runtime;
assert.equal(typeof runtime.schedulerRecent,'boolean');
assert.equal(runtime.schedulerBound,undefined);
assert.equal(runtime.recoveryReady,true);
assert.ok(Number(runtime.work.total)>=0);
}
records.push({role,status:result.status});
}
await fs.writeFile('docs/proofs/replenishment-health-http.json',JSON.stringify({checked_at:new Date().toISOString(),environment:base,result:'passed',records,
pilot_health_command_executed:false,business_commands:false,accounts_or_grants_changed:false,sgf_changed:false,visual_review:false,
coverage:'Existing tenant-scoped diagnostic UI and rights preserved; CLI health executed only in disposable databases.'},null,2));
console.log('Diagnóstico do piloto conferido em leitura, sem executar reposições.');
`+'})()')(fs,assert);