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

28 lines
2.5 KiB
Plaintext

// Original T owned records only. No production DB, model request or credentials.
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import {workingCandidates} from '../src/core/context/working-set.mjs';
import {historyGroups} from '../src/core/context/request-plan.mjs';
const root=path.resolve('.qa/live-delivery-t'),out=path.resolve('.qa/working-memory-u');
const read=n=>JSON.parse(fs.readFileSync(path.join(root,n),'utf8'));
const sha=b=>createHash('sha256').update(b).digest('hex');
const session=read('node/export.json').session,state=read('node/session.json');
const rows=read('analysis/owned-tool-rows.json'),artifacts=read('analysis/artifact-index.json').artifacts;
const map=new Map(artifacts.map(a=>[a.id,a]));
const store={core:{tool:new Map(rows.map(r=>{const v=JSON.parse(r.payload);return[v.id,v];})),check_job:new Map(state.execution.checks.map(r=>[r.id,r]))},
owned(kind,id,sid){assert.equal(kind,'artifact');const a=map.get(id);assert.equal(a.sessionId,sid);return a;},
artifactStore:{read(a){const b=fs.readFileSync(path.join(root,a.capturedPath));assert.equal(sha(b),a.sha256);return b.toString('utf8');}}};
const version=Number(process.argv[2]??2),groups=historyGroups(session.providerMessages).slice(0,7);
const candidates=workingCandidates(store,session,state.execution.run,groups,version);
const files=candidates.filter(c=>c.observation.path==='test/expense.test.mjs');
const source=fs.readFileSync(path.join(root,'node/source-before/test/expense.test.mjs'),'utf8');
const covered=new Set();for(const c of files){const o=c.observation;assert.equal(o.content,source.slice(o.offset,o.offset+o.content.length));for(let n=o.offset;n<o.offset+o.content.length;n++)covered.add(n);}
const result={observationVersion:version,originalToolsSha256:sha(fs.readFileSync(path.join(root,'analysis/owned-tool-rows.json'))),sourceSha256:sha(source),sourceCharacters:source.length,
candidateRanges:files.map(c=>[c.observation.offset,c.observation.offset+c.observation.content.length]),covered:covered.size,fullCoverage:covered.size===source.length,
candidates,externalModelRequests:0};
fs.writeFileSync(path.join(out,version===2?'replay-before.json':'replay-after.json'),JSON.stringify(result,null,2)+'\n',{flag:'wx'});
console.log(JSON.stringify({version,ranges:result.candidateRanges,covered:result.covered,fullCoverage:result.fullCoverage,externalModelRequests:0}));
if(version===2)assert.equal(result.fullCoverage,false);else assert.equal(result.fullCoverage,true);