Files
Agent-Workbench/tests/unrestricted-workers.test.mjs

34 lines
2.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fixture, call } from './helpers.mjs';
import { prepareWorkerFixture, ownerBytes } from './fixtures/workers-project.mjs';
test('open worker seals 33 files above two MB, records absent checks honestly and applies the parent merge without a review stop', async t => {
const f=fixture(t,{modernDefaults:true});
f.store.saveConfig({approvalMode:'full'});
const paths=Array.from({length:33},(_,index)=>'src/generated-'+index+'.mjs');
const contents=paths.map((_,index)=>index===0?'// '+ 'x'.repeat(2*1024*1024+1)+'\nexport const value=0;\n':'export const value='+index+';\n');
const {manager}=prepareWorkerFixture(f,{respond:async ({project})=>{
const session=[...f.store.sessions.values()].find(value=>value.projectId===project.id);
const calls=session.changes.length?[]:paths.map((relative,index)=>call('open-file-'+index,'propose_file',{path:relative,content:contents[index],reason:'Owned acceptance fixture'}));
return {message:{role:'assistant',content:calls.length?'':'Files written; checks have not run.',...(calls.length?{tool_calls:calls}:{})},usage:{prompt_tokens:10,completion_tokens:10,total_tokens:20}};
}});
const original=ownerBytes(f);
const group=await manager.plan(f.session,{goal:'Write all files without artificial quotas',children:[{label:'open-files',goal:'Write 33 source files',paths}]});
await (await manager.prepare(f.session,group.id,group.fingerprint)).promise;
assert.equal(group.status,'ready',group.summary);
await (await manager.start(f.session,group.id,group.fingerprint)).promise;
assert.equal(group.status,'ready_to_collect',JSON.stringify(manager.view(f.session).groups[0].workers.map(row=>row.summary)));
const child=group.children[0],worker=f.store.core.worker.get(child.id),output=await manager.output(f.store.session(child.sessionId),worker);
assert.equal(output.files.length,33);assert.equal(output.check,null);assert.equal(worker.result.checkJobId,null);
await (await manager.collect(f.session,group.id,group.fingerprint)).promise;
assert.equal(group.status,'collected',group.summary);
await (await manager.prepareMerge(f.session,group.id,group.fingerprint)).promise;
assert.equal(group.merge.status,'applied',group.summary);
assert.equal(f.store.core.change_set.get(group.merge.changeSetId).status,'completed');
for(let index=0;index<paths.length;index++)assert.equal(fs.readFileSync(path.join(f.projectRoot,paths[index]),'utf8'),contents[index]);
assert.deepEqual(ownerBytes(f),original);
});