// A local HTTP fixture exercises the shipped host. No production config or // credentials, no implementation supplied, no real-model delivery claim. import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import {randomUUID,createHash} from 'node:crypto'; import {execFileSync} from 'node:child_process'; import {Store} from '../src/server/store.mjs'; import {verifyPlanEvidence} from '../src/core/context/request-plan.mjs'; import {compatibleFixture,completion,call,until,assertToolPairs,launchWorkbench} from '../tests/helpers.mjs'; const root=path.resolve('.qa','working-memory-host-'+randomUUID()),data=path.join(root,'data'),projectRoot=path.join(root,'project'); const appRoot=path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT??'.'); const input=JSON.parse(fs.readFileSync(new URL('../tests/fixtures/working-memory-t.json',import.meta.url))); const sha=value=>createHash('sha256').update(value).digest('hex'),disposers=[],t={after:fn=>disposers.push(fn)}; fs.mkdirSync(projectRoot,{recursive:true}); for(const file of input.files){assert.equal(sha(file.content),file.sha256);const target=path.resolve(projectRoot,file.path);assert.ok(target.startsWith(projectRoot+path.sep));fs.mkdirSync(path.dirname(target),{recursive:true});fs.writeFileSync(target,file.content);} const git=args=>execFileSync('git',['-C',projectRoot,...args],{encoding:'utf8',windowsHide:true}); git(['init','--initial-branch=main']);git(['config','core.autocrlf','false']);git(['add','.']);git(['-c','user.name=QA','-c','user.email=qa@workbench.invalid','commit','--no-gpg-sign','-m','Original read-only T fixture']); const requests=[],facts=[],checks=[],files=input.files.filter(f=>['test/expense.test.mjs','src/amount.mjs','src/summary.mjs','src/report.mjs'].includes(f.path)); let host,sessionId,report,version,extraInspection=false; try{ const model=await compatibleFixture(t,async(_route,body)=>{ assertToolPairs(body.messages);requests.push(body);const number=requests.length;assert.ok(number<=8);assert.ok(body.messages[0].content.includes(JSON.stringify(input.goal))); if(number<=3){const message=structuredClone(input.replies[number-1]);for(const tool of message.tool_calls??[])if(tool.function.name==='run_checks'){ const current=await host.api('/sessions/'+sessionId);tool.function.arguments=JSON.stringify({plan_id:current.execution.plans.at(-1).id});} return{body:{...completion(),choices:[{message,finish_reason:'tool_calls'}]}};} const marker='当前工程执行依据(每次请求重新核对,非操作授权):\n'; const fact=JSON.parse(body.messages[0].content.split(marker)[1].split('\n')[0]);facts.push(fact); assert.equal(fact.has_applied_changes,false);assert.equal(fact.stage,'checks_need_repair');assert.equal(fact.latest_check.current_source,true); assert.equal(fact.latest_check.results[0].tests.failed,9);assert.equal(fact.latest_check.results[1].status,'passed'); const original=await host.api('/sessions/'+sessionId+'/export'),pages=original.session.providerMessages.filter(m=>m.role==='tool').map(m=>JSON.parse(m.content)).filter(v=>v.path==='test/expense.test.mjs'&&typeof v.content==='string'); const text=files.find(f=>f.path==='test/expense.test.mjs').content,covered=new Set(); for(const p of pages){assert.equal(p.content,text.slice(p.offset,p.next_offset));for(let n=p.offset;n