57 lines
5.4 KiB
JavaScript
57 lines
5.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { createHash } from 'node:crypto';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { DatabaseSync } from 'node:sqlite';
|
|
const destination=path.resolve('docs/live-context-a-evidence');assert.equal(fs.existsSync(destination),false);fs.mkdirSync(destination);
|
|
const hash=bytes=>createHash('sha256').update(bytes).digest('hex'),entries=new Map();
|
|
function put(relative,bytes){
|
|
const file=path.resolve(destination,relative);assert.ok(file.startsWith(destination+path.sep));
|
|
const entry={path:relative,bytes:bytes.length,sha256:hash(bytes)};
|
|
if(entries.has(relative)){assert.deepEqual(entries.get(relative),entry);return relative;}
|
|
fs.mkdirSync(path.dirname(file),{recursive:true});fs.writeFileSync(file,bytes);entries.set(relative,entry);return relative;
|
|
}
|
|
const copy=(relative,file)=>put(relative,fs.readFileSync(file)),json=(relative,value)=>put(relative,Buffer.from(JSON.stringify(value,null,2)+'\n'));
|
|
const qa='.qa/',samples=[];
|
|
const definitions=[
|
|
['failure-seed','controlled-context-3b45edc8-dbb4-4e2e-b29c-f57b3276c0ae',false],
|
|
['failure-return','controlled-context-14a9a170-4ca6-44a9-8cee-fcdc3bfc5a64',false],
|
|
['chat','controlled-context-d978fbf0-9d8a-4959-8e7d-5744cd9e66b2',true],
|
|
['responses','controlled-context-c39fb46b-07a9-4a9e-8b67-5a5955b084a0',true],
|
|
];
|
|
for(const [name,folder,passed] of definitions){
|
|
const original=path.resolve(qa,folder),base=path.join(original,'native-context'),prefix='samples/'+name+'/';
|
|
const result=copy(prefix+'result.json',path.join(base,'result.json'));copy(prefix+'run-receipt.json',path.join(original,'result.json'));
|
|
const db=new DatabaseSync(path.join(base,'original-fixture/data/workbench.sqlite'),{readOnly:true});
|
|
const records=db.prepare("SELECT kind,id,payload FROM records WHERE kind IN ('tool','artifact','engine_run') ORDER BY kind,id").all();
|
|
const owners=db.prepare('SELECT id,project_id AS projectId FROM sessions ORDER BY id').all();db.close();
|
|
const artifacts=[];
|
|
for(const row of records.filter(row=>row.kind==='artifact')){
|
|
const artifact=JSON.parse(row.payload);assert.match(artifact.relative,/^[a-f0-9]{2}\/[a-f0-9]{64}\.blob$/);
|
|
const file=path.join(base,'original-fixture/data/artifacts',artifact.relative);assert.equal(fs.lstatSync(file).isSymbolicLink(),false);
|
|
const bytes=fs.readFileSync(file);assert.equal(hash(bytes),artifact.sha256);assert.equal(bytes.length,artifact.bytes);
|
|
artifacts.push({...artifact,file:put('blobs/'+artifact.sha256+'.blob',bytes)});
|
|
}
|
|
samples.push({name,passed,result,records:json(prefix+'records.json',records),sessions:json(prefix+'owners.json',owners),artifacts,
|
|
...(name==='responses'?{attempts:copy(prefix+'original-attempts.json',path.join(base,'original-responses-attempts.json'))}:{})});
|
|
}
|
|
const receipt=JSON.parse(fs.readFileSync(path.resolve(qa,definitions[2][1],'result.json'),'utf8'));
|
|
const sourceCommit=execFileSync('git',['rev-parse','HEAD'],{encoding:'utf8',windowsHide:true}).trim();assert.equal(sourceCommit.slice(0,7),'0a58c0d');
|
|
const sourceInputs=[];
|
|
for(const input of receipt.inputs.filter(input=>!input.path.startsWith('dist-'))){
|
|
const sourcePath=input.path.replaceAll('\\','/');
|
|
const raw=fs.readFileSync(input.path);assert.equal(hash(raw),input.sha256);const blob=execFileSync('git',['show',sourceCommit+':'+sourcePath],{windowsHide:true,maxBuffer:16*1024*1024});
|
|
assert.equal(raw.toString('utf8').replace(/\r\n/g,'\n'),blob.toString('utf8').replace(/\r\n/g,'\n'));
|
|
sourceInputs.push({...input,path:sourcePath,bytes:raw.length,gitBlobSha256:hash(blob),...(hash(raw)!==hash(blob)?{snapshot:put('source-bytes/'+sourcePath,raw)}:{})});
|
|
}
|
|
for(const [name,file] of Object.entries({regression:'live-context-a-regression.tap',engine:'live-context-a-worker-final.tap',build:'live-context-a-build-v2.log',
|
|
'old-evidence':'live-context-a-historical-proof.log','native-chat':'live-context-a-native-v3.log','native-responses':'live-context-a-responses.log',
|
|
'development-native-1':'live-context-a-native.log','development-native-2':'live-context-a-native-v2.log','development-provenance':'live-context-a-provenance.tap'}))copy('receipts/'+name+(file.endsWith('.tap')?'.tap':'.txt'),qa+file);
|
|
const ui=JSON.parse(fs.readFileSync(qa+'live-context-a-ui.log','utf8').trim());copy('ui/result.json',path.join(ui.directory,'result.json'));
|
|
for(const width of [1440,390])for(const extension of ['png','html'])copy('ui/native-budget-'+width+'.'+extension,path.join(ui.directory,'native-budget-'+width+'.'+extension));
|
|
copy('instrumentation/seal-context-a.mjs',qa+'seal-context-a.mjs');
|
|
const list=[...entries.values()].sort((a,b)=>a.path.localeCompare(b.path)),manifest={schemaVersion:1,sourceCommit,createdAt:new Date().toISOString(),realModelRequests:0,
|
|
count:list.length,bytes:list.reduce((sum,entry)=>sum+entry.bytes,0),sourceInputs,samples,entries:list,scope:'Native execution with owned HTTP model fixtures; earlier failures retained. No configured keys or formal data copied. Not real-model autonomy or Purge benefit.'};
|
|
fs.writeFileSync(path.join(destination,'manifest.json'),JSON.stringify(manifest,null,2)+'\n');console.log(JSON.stringify({directory:destination,count:manifest.count,bytes:manifest.bytes,sourceInputs:sourceInputs.length,artifacts:samples.map(sample=>({name:sample.name,records:sample.artifacts.length})),manifestSha256:hash(fs.readFileSync(path.join(destination,'manifest.json')))}));
|