Files
Agent-Workbench/docs/reproducible-env-release-evidence/verifiers/status.mjs
T

24 lines
2.2 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
const prefix='.qa/reproducible-env-c-';
const status={observedAt:new Date().toISOString()};
const main=fs.readFileSync(prefix+'independent-console.log','utf8');
status.pipeline=main.split(/\r?\n/).filter(line=>/^(START|PASS) /.test(line)).slice(-3);
if(fs.existsSync(prefix+'source.log')){
const source=fs.readFileSync(prefix+'source.log','utf8');status.sourceStages=source.split(/\r?\n/).filter(line=>line.startsWith('Source package:')).slice(-2);
const first=source.split(/\r?\n/).find(line=>line.startsWith('{"sourceRoot"'));
if(first){const location=JSON.parse(first);status.sourceDirectory=location.directory;
if(fs.existsSync(path.join(location.directory,'test-plan.json'))){
const plan=JSON.parse(fs.readFileSync(path.join(location.directory,'test-plan.json')));status.plannedFiles=plan.flatMap(row=>row.files).length;
status.tests=fs.readdirSync(location.directory).filter(name=>/^(tests-\d+|upgrade-tests)\.tap$/.test(name)).sort().map(name=>{
const text=fs.readFileSync(path.join(location.directory,name),'utf8'),stats=Object.fromEntries([...text.matchAll(/^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/gm)].map(match=>[match[1],Number(match[2])]));
return {log:name,...stats,...(!stats.tests?{inProgress:true,observedPassed:(text.match(/^ok /gm)||[]).length,observedFailures:(text.match(/^\s*not ok /gm)||[]).length,latestSubtest:[...text.matchAll(/^# Subtest: (.+)$/gm)].at(-1)?.[1]}:{})};
});
}
}
}
if(status.tests){status.completedBatches=status.tests.filter(row=>row.tests>0).length;status.completedTests=status.tests.reduce((sum,row)=>sum+(row.pass??0),0);status.currentBatch=status.tests.find(row=>row.inProgress)??null;delete status.tests;}
if(fs.existsSync(prefix+'promotion-console.log'))status.promotionStages=fs.readFileSync(prefix+'promotion-console.log','utf8').split(/\r?\n/).filter(line=>/^(START|PASS) /.test(line)).slice(-3);
for(const name of ['independent','promotion'])if(fs.existsSync(prefix+name+'-result.json')){const value=JSON.parse(fs.readFileSync(prefix+name+'-result.json'));status[name]={success:value.success,completed:value.completed?.map(row=>row.name),error:value.error?.slice(0,700)};}
console.log(JSON.stringify(status));