Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/prepare-source-with-bound-tests.mjs
T

54 lines
4.6 KiB
JavaScript

import fs from 'node:fs';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
let code=fs.readFileSync('scripts/verify-source-package.mjs','utf8').replaceAll('\r\n','\n');
const insertion = String.raw`
const inheritedRoot = path.join(workspace,'docs/embedded-browser-c-rejected-candidate-evidence');
const inheritedManifest = JSON.parse(fs.readFileSync(path.join(inheritedRoot,'manifest.json')));
const inheritedBaseline = JSON.parse(fs.readFileSync(path.join(inheritedRoot,'receipts/code-baseline.json')));
assert.equal(inheritedManifest.sourceOverallSuccess,false);
assert.deepEqual(inheritedManifest.tests,{tests:683,pass:683,fail:0,cancelled:0,skipped:0,todo:0});
const originalInputs = new Map(inheritedBaseline.inputs.map(row=>[row.path,row]));
assert.equal(inputs.length,originalInputs.size);
const changed = inputs.filter(row=>{
const old=originalInputs.get(row.path);assert.ok(old,row.path);return old.bytes!==row.bytes||old.sha256!==row.sha256;
}).map(row=>row.path).sort();
assert.deepEqual(changed,['.gitattributes','scripts/desktop-project-qa.mjs']);
for(const row of inputs.filter(row=>row.path.startsWith('tests/'))){
const text=fs.readFileSync(path.join(sourceRoot,row.path),'utf8');
assert.ok(!/desktop-project-qa|verify-controlled-projects/.test(text),'Tests must not read the changed desktop QA helper: '+row.path);
}
const inheritedRows=[];
const inheritance={success:false,sourceCommit:inheritedManifest.sourceCommit,sourceOverallSuccess:false,changedInputs:changed,tests:inheritedManifest.tests,originalManifestSha256:digest(path.join(inheritedRoot,'manifest.json')),logs:inheritedRows,
scope:'Only the complete passing C source-test stage is inherited after every source/test/dependency/compiler input and test-used script is exact. C overall remains failed at a later desktop helper. D independently installs/builds and runs runtime, desktop and all engineering gates. No test result rewritten or executed twice.'};
function inheritedTest(args,logName){
if(!/^(?:tests-\d+|upgrade-tests)\.tap$/.test(logName))return null;
const declared=inheritedManifest.files.find(row=>row.path==='source/'+logName);assert.ok(declared,logName);
const original=path.join(inheritedRoot,declared.path),bytes=fs.readFileSync(original);
assert.equal(bytes.length,declared.bytes);assert.equal(digest(original),declared.sha256);
const text=bytes.toString('utf8');
const counts=Object.fromEntries([...text.matchAll(/^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/gm)].map(row=>[row[1],Number(row[2])]));
assert.ok(counts.tests>0);assert.equal(counts.tests,counts.pass);for(const key of ['fail','cancelled','skipped','todo'])assert.equal(counts[key],0);
const oldPlan=JSON.parse(fs.readFileSync(path.join(inheritedRoot,'source/test-plan.json')));
const newPlan=JSON.parse(fs.readFileSync(path.join(directory,'test-plan.json')));assert.deepEqual(newPlan,oldPlan);
const output=path.join(directory,logName);fs.writeFileSync(output,bytes,{flag:'wx'});
const row={stage,path:output,sha256:declared.sha256,bytes:declared.bytes,inheritedFrom:original,sourceCommit:inheritedManifest.sourceCommit};logs.push(row);inheritedRows.push({...row,args,counts});
console.log('Source package: '+stage+' [exact passing C log inherited; no replay]');
if(logName==='upgrade-tests.tap'){
assert.equal(inheritedRows.length,12);assert.equal(inheritedRows.reduce((sum,row)=>sum+row.counts.tests,0),683);inheritance.success=true;
fs.writeFileSync(path.join(workspace,'.qa/embedded-browser-d-source-test-inheritance.json'),JSON.stringify(inheritance,null,2)+'
',{flag:'wx'});
}
return text.slice(-12000);
}
`;
// Keep actual newlines in the generated JS string literal escaped.
const fixedInsertion=insertion.replace("JSON.stringify(inheritance,null,2)+'\n'", "JSON.stringify(inheritance,null,2)+'\\n'");
assert.ok(code.includes('const logs = [];'));
code=code.replace('const logs = [];','const logs = [];\n'+fixedInsertion);
code=code.replace('function run(args, logName) {','function run(args, logName) {\n const inherited=inheritedTest(args,logName);if(inherited!==null)return Promise.resolve(inherited);');
code=code.replace('tests: stats, testPlan, actualEmbeddedBrowser','tests: stats, inheritedTests: inheritance, testPlan, actualEmbeddedBrowser');
const output='.qa/verify-embedded-browser-d-source.mjs';fs.writeFileSync(output,code,{flag:'wx'});
execFileSync(process.execPath,['--check',output],{stdio:'pipe',windowsHide:true});
console.log(JSON.stringify({success:true,output,scope:'Exact-input source-test inheritance only; independent install/build/runtime and repaired desktop gates remain executable.'}));