Files
Agent-Workbench/docs/working-memory-u-evidence/drivers/working-memory-u-seal.mjs.txt
T
2026-11-04 08:39:17 +08:00

68 lines
6.1 KiB
Plaintext

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import {DatabaseSync} from 'node:sqlite';
const sha=b=>createHash('sha256').update(b).digest('hex');
const read=p=>JSON.parse(fs.readFileSync(p,'utf8').replace(/^\uFEFF/,''));
const root='.qa/working-memory-u',base=path.resolve('docs/working-memory-u-evidence');
assert.equal(fs.existsSync(base),false);fs.mkdirSync(base);
const freeze=read(root+'/release/product-freeze.json'),release=read(root+'/release/candidate.json');
assert.equal(read(root+'/formal-release/final.json').success,true);
assert.equal(read(root+'/native/result.json').success,true);
assert.deepEqual(read('releases/latest.json'),release);
const entries=[];
function put(bytes,relative,source){
const target=path.resolve(base,relative);assert.ok(target.startsWith(base+path.sep));
fs.mkdirSync(path.dirname(target),{recursive:true});fs.writeFileSync(target,bytes,{flag:'wx'});
entries.push({path:relative.replaceAll('\\','/'),bytes:bytes.length,sha256:sha(bytes),source});
}
function copy(file,relative){assert.equal(fs.lstatSync(file).isSymbolicLink(),false);put(fs.readFileSync(file),relative,path.resolve(file));}
function walk(directory,destination){for(const e of fs.readdirSync(directory,{withFileTypes:true})){
const p=path.join(directory,e.name),r=path.posix.join(destination,e.name);assert.equal(fs.lstatSync(p).isSymbolicLink(),false,'No junctions');
if(e.isDirectory())walk(p,r);else copy(p,r);
}}
function top(directory,destination){for(const e of fs.readdirSync(directory,{withFileTypes:true}))if(e.isFile()&&/\.(?:json|log|txt|png|jpg)$/.test(e.name))copy(path.join(directory,e.name),destination+'/'+e.name);}
walk(root,'receipts');
for(const name of fs.readdirSync('.qa').filter(n=>/^working-memory-u.*\.mjs$/.test(n)))copy('.qa/'+name,'drivers/'+name+'.txt');
copy('.qa/desktop-f-state.mjs','drivers/desktop-f-state.mjs.txt');
copy('scripts/verify-working-memory.mjs','drivers/verify-working-memory.mjs.txt');
copy('tests/fixtures/working-memory-t.json','original-t-fixture.json');
for(const item of freeze.compiled){const p=path.join(release.portableRoot,item.path);assert.equal(sha(fs.readFileSync(p)),item.sha256);copy(p,'compiled/'+item.path);}
for(const item of freeze.files.filter(v=>/^src\//.test(v.path)||/working-memory|working-set|task-delivery-progress|task-context|tool-feedback/.test(v.path))){
assert.equal(sha(fs.readFileSync(item.path)),item.sha256,item.path);copy(item.path,'source-bytes/'+item.path);
}
function memory(directory,name){
const report=read(path.join(directory,'result.json'));assert.equal(report.success,true);assert.equal(report.requests,7);
top(directory,'validation/'+name);walk(path.join(directory,'data/artifacts'),'validation/'+name+'/artifacts');
const db=new DatabaseSync(path.join(directory,'data/workbench.sqlite'),{readOnly:true});
try{const rows=db.prepare("SELECT kind,payload FROM records WHERE kind IN ('artifact','tool','run','task','context_plan') ORDER BY rowid").all();
put(Buffer.from(JSON.stringify(rows,null,2)+'\n'),'validation/'+name+'/owned-records.json',path.resolve(directory,'data/workbench.sqlite')+' (read-only selected fixture rows)');
}finally{db.close();}
}
memory('.qa/working-memory-host-cd805518-be14-44fe-a4d5-1eb4cf422768','source-memory');
const pm=read(root+'/release/memory.json');memory(path.dirname(pm.resultPath),'portable-memory');
const build=read(root+'/release/rebuild.json').result;top(build.root,'validation/rebuild');
const install=read(root+'/release/install.json').result;top(install.root,'validation/install');
for(const p of install.installedUI.proofs){
const lines=fs.readFileSync(p.log,'utf8').trim().split(/\r?\n/),summary=JSON.parse(lines.findLast(l=>l.startsWith('{"success":')));
const directory=summary.directory??summary.root;
if(p.script==='verify-working-memory.mjs')memory(directory,'installed-memory');
else top(directory,p.script==='verify-file-results-ui.mjs'?'validation/installed-results':'validation/installed-files');
}
copy('.qa/archives-validation.json','validation/archives.json');copy('.qa/release-validation.json','validation/portable.json');
copy('releases/latest.json','release-latest.json');
copy(path.join(release.portableRoot,'MANIFEST.json'),'portable-manifest.json');copy(path.join(release.sourceRoot,'MANIFEST.json'),'source-manifest.json');
const oldManifest='docs/live-delivery-t-evidence/manifest.json';
const reference={path:oldManifest,sha256:sha(fs.readFileSync(oldManifest)),scope:'Immutable original T bytes remain in their committed manifest; no old task is resumed or historical artifact rewritten.'};
put(Buffer.from(JSON.stringify(reference,null,2)+'\n'),'original-t-reference.json','immutable committed T evidence');
const identity={version:'1.24.8',sourceCommit:freeze.sourceCommit,candidate:path.basename(release.portableRoot),
portableManifestSha256:sha(fs.readFileSync(path.join(release.portableRoot,'MANIFEST.json'))),sourceManifestSha256:sha(fs.readFileSync(path.join(release.sourceRoot,'MANIFEST.json'))),
installer:release.installer,archives:Object.fromEntries(['portable','source','evidence'].map(kind=>[kind,release[kind]])),realModelRequests:0};
fs.writeFileSync('docs/working-memory-u-release-identity.json',JSON.stringify(identity,null,2)+'\n',{flag:'wx'});copy('docs/working-memory-u-release-identity.json','release-identity.json');
const manifest={schemaVersion:1,version:'1.24.8',sourceCommit:freeze.sourceCommit,createdAt:new Date().toISOString(),realModelRequests:0,
scope:'U actual read-page retention and current check facts; original failures, frozen source/portable/installed bytes and requests, exact original production state. Only public real config and hashes, no real credential values. Drivers are inert evidence, never replay instructions.',
count:entries.length,bytes:entries.reduce((n,e)=>n+e.bytes,0),entries:entries.sort((a,b)=>a.path.localeCompare(b.path))};
fs.writeFileSync(path.join(base,'manifest.json'),JSON.stringify(manifest,null,2)+'\n',{flag:'wx'});
console.log(JSON.stringify({success:true,count:manifest.count,bytes:manifest.bytes,manifestSha256:sha(fs.readFileSync(path.join(base,'manifest.json')))}));