Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/final-audit.mjs
T

34 lines
4.4 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {execFileSync} from 'node:child_process';
import {publicSnapshot,compareOriginalState,hash} from './embedded-browser-d-state.mjs';
const read=file=>JSON.parse(fs.readFileSync(file,'utf8'));
const git=args=>execFileSync('git',args,{encoding:'utf8',windowsHide:true,maxBuffer:8*1024*1024});
assert.equal(git(['status','--porcelain']).trim(),'','Final local checkout must be clean');git(['diff','--check']);
const identityFile='docs/embedded-browser-release-identity.json',identity=read(identityFile);
assert.equal(identity.version,'1.22.0');git(['merge-base','--is-ancestor',identity.sourceCommit,'HEAD']);
assert.equal(git(['diff',identity.sourceCommit,'HEAD','--','src','scripts','tests','package.json','package-lock.json','vite.config.ts','tsconfig.json','index.html','mobile.html']).trim(),'','Frozen execution inputs unchanged');
let evidenceFiles=0,evidenceBytes=0;const committed=[identityFile];
for(const manifestFile of [identity.evidence.manifest,'docs/embedded-browser-development-evidence/manifest.json','docs/embedded-browser-rejected-candidate-evidence/manifest.json','docs/embedded-browser-b-rejected-candidate-evidence/manifest.json','docs/embedded-browser-c-rejected-candidate-evidence/manifest.json']){
const manifest=read(manifestFile),root=path.dirname(manifestFile);committed.push(manifestFile);
if(manifestFile===identity.evidence.manifest){assert.equal(hash(fs.readFileSync(manifestFile)),identity.evidence.sha256);assert.equal(manifest.files.length,identity.evidence.files);}
for(const row of manifest.files){const file=path.posix.join(root,row.path),bytes=fs.readFileSync(file);assert.equal(bytes.length,row.bytes,file);assert.equal(hash(bytes),row.sha256,file);committed.push(file);evidenceFiles++;evidenceBytes+=bytes.length;}
}
for(let index=0;index<committed.length;index+=16){
const batch=committed.slice(index,index+16),output=execFileSync('git',['cat-file','--batch'],{input:batch.map(file=>'HEAD:'+file).join('\n')+'\n',windowsHide:true,maxBuffer:64*1024*1024});
let position=0;for(const file of batch){const end=output.indexOf(10,position),header=output.subarray(position,end).toString('utf8');assert.match(header,/^[a-f0-9]+ blob \d+$/,'Missing committed evidence '+file);const length=Number(header.split(' ').at(-1)),bytes=output.subarray(end+1,end+1+length);position=end+2+length;assert.deepEqual(bytes,fs.readFileSync(file),'Exact committed evidence '+file);}assert.equal(position,output.length);
}
let links=0;
for(const file of ['AGENTS.md','README.md','docs/QA-1.22.md','docs/RETROSPECTIVE-1.22.md','docs/PLAN-1.22.md','docs/PLAN-1.23.md','docs/EMBEDDED-BROWSER.md','docs/NEXT-STEPS.md','docs/CAPABILITIES.md']){
for(const match of fs.readFileSync(file,'utf8').matchAll(/\]\(([^)]+)\)/g)){if(/^(https?:|#)/.test(match[1]))continue;assert.ok(fs.existsSync(path.resolve(path.dirname(file),match[1].split('#')[0])),'Broken local link '+file+': '+match[1]);links++;}
}
const before=read('.qa/embedded-browser-d-formal-after-verify.json'),after=await publicSnapshot('http://127.0.0.1:4318',identity.formal.pointer.dataRoot);
assert.equal(after.version,'1.22.0');assert.equal(after.pid,identity.formal.pid);assert.equal(after.runtimeRoot,identity.formal.runtimeRoot);assert.deepEqual(after.active,[]);
const retained=compareOriginalState(before,after),pointer=read('C:/Users/wangy/AppData/Local/Programs/AgentWorkbench/current.json');assert.deepEqual(pointer,identity.formal.pointer);
const finalCommit=git(['rev-parse','HEAD']).trim(),result={schemaVersion:1,success:true,version:'1.22.0',verifiedAt:new Date().toISOString(),sourceCommit:identity.sourceCommit,finalCommit,
identity:identityFile,identitySha256:hash(fs.readFileSync(identityFile)),evidenceFiles,evidenceBytes,exactCommittedBlobs:committed.length,localLinks:links,
formal:{pid:after.pid,runtimeRoot:after.runtimeRoot,retained,counts:identity.formal.counts},gitClean:true,localOnly:true,realModelRequestsInitiated:0,
scope:'Frozen implementation ancestry, exact bytes of all development/final evidence in checkout and Git, local links, installed pointer and every original row/export/config/artifact byte after final UI/native observations.'};
const output=path.join('releases',identity.installer.candidateDirectory+'-ACCEPTANCE-FINAL.json');fs.writeFileSync(output,JSON.stringify(result,null,2)+'\n',{flag:'wx'});console.log(JSON.stringify({success:true,output,finalCommit,evidenceFiles,retained,counts:identity.formal.counts}));