Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

test: sweep parsing and filing, the tier ladder, dependency merges

Corey Olson1de69eb51d29
diff --git a/test/board.test.js b/test/board.test.js
index 976fb6dc..1a72c61d 100644
--- a/test/board.test.js
+++ b/test/board.test.js
@@ -291,6 +291,7 @@ test('routes are tiers: an agent claims and verifies its tier and below, its own
assert.equal(store.nextFor(board, { agentId: 'web-4', lane: 'web' }).item.item_id, mid);
assert.equal(store.nextFor(board, { agentId: 'web-1', lane: 'web' }).item.item_id, strong);
assert.equal(store.nextFor(board, { agentId: 'web-1', lane: 'web', runnable: true }).item.item_id, mid);
+ assert.equal(store.nextFor(board, { agentId: 'web-4', lane: 'web', routes: ['light'] }).item.item_id, light);
claimAs(strong, 'web-1', 'web');
assert.throws(() => store.editItem(board, strong, { agentId: 'coordinator', route: 'mid' }), /HELD.*only while it is open/);
store.submit(board, strong, { agentId: 'web-1', commit: SHA_A, tree: 't' });
diff --git a/test/e2e.test.js b/test/e2e.test.js
index 1ca269e5..d3d7ba8a 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -401,14 +401,15 @@ test('run builds routed items unattended: the failure feeds the next attempt; re
const made = box.run(box.repo, 'worktree', 'web', '--route', 'light');
const light = made.out.match(/^made (\S+) /)[1];
assert.match(box.run(box.repo, 'run', '--agent', `sh ${agent}`).err, /MAIN_IS_COORDINATOR/);
- const ran = box.run(light, 'run', '--agent', `sh ${agent}`, '--attempts', '2', '--minutes', '2');
+ assert.match(box.run(light, 'run', '--agent-mid', `sh ${agent}`).err, /ROUTE.*joined on the light route, so it cannot take mid items/);
+ const ran = box.run(light, 'run', '--agent-light', `sh ${agent}`, '--attempts', '2', '--minutes', '2');
assert.equal(ran.code, 0, ran.err);
assert.match(ran.out, /#1 attempt 1: red[\s\S]*#1 attempt 2: green \(agent \d+s, check \d+s\)\nsubmitted #1/);
assert.match(ran.out, /nothing left to run: no open light runnable items in the web lane/);
assert.match(ran.out, /#2 attempt 2: red[\s\S]*#2 escalated light -> mid; the attempt is pinned at refs\/pullboard\/attempts\/2\//);
assert.match(ran.out, /runner done: 1 submitted, 1 escalated/);
const packs = join(box.dir, 'repo', '.git', 'worktrees', light.split('/').at(-1), 'pullboard', 'packs');
- const second = readFileSync(join(packs, '1-2.md'), 'utf8');
+ const second = readFileSync(join(packs, '1-light-2.md'), 'utf8');
assert.match(second, /reverted your changes outside the brief's files: api\/stray.js/);
assert.match(second, /### web\/page.js\n```\nexport const title = 'Hello';/);
assert.equal(existsSync(join(light, 'api', 'stray.js')), false);
@@ -423,6 +424,62 @@ test('run builds routed items unattended: the failure feeds the next attempt; re
assert.match(box.run(box.repo, 'inbox').out, /web-2 -> coordinator: #2 escalated light -> mid after 2 red attempts/);
});
+test('one runner climbs the tiers: an escalated item goes to the next command, with the earlier tries; it merges the verified work an item waits on [N16]', () => {
+ const box = project();
+ const script = (name, lines) => {
+ writeFileSync(join(box.dir, name), ['#!/bin/sh', 'mkdir -p web api', ...lines, ''].join('\n'));
+ return `sh ${join(box.dir, name)}`;
+ };
+ const good = script('web.sh', ["echo \"export const title = 'Hi';\" > web/page.js"]);
+ const weak = script('weak.sh', ['echo nope > api/server.js']);
+ const strong = script('strong.sh', ['grep -q "Earlier tries by a lighter model" "$PULLBOARD_PACK" && echo "export const served = true;" > api/server.js']);
+ const brief = (file) => LIGHT_BRIEF.replace('web/page.js', file);
+ box.run(box.repo, 'add', 'web', 'Greet', '--route', 'light', '--criterion', 'says Hi', '--check', 'grep -q Hi web/page.js', '--brief', brief('web/page.js'));
+ box.run(box.repo, 'add', 'api', 'Serve', 'the', 'page', '--after', '1', '--route', 'light', '--criterion', 'serves it', '--check', 'test -f web/page.js && grep -q served api/server.js', '--brief', brief('api/server.js'));
+ const webRunner = box.run(box.repo, 'worktree', 'web', '--route', 'light').out.match(/^made (\S+) /)[1];
+ assert.match(box.run(webRunner, 'run', '--agent-light', good, '--attempts', '1').out, /submitted #1/);
+ const commit = JSON.parse(box.run(box.repo, 'show', '1', '--json').out).item_commit;
+ box.git(box.web, 'merge', '-q', '--ff-only', commit);
+ assert.match(box.run(box.web, 'verify', '1', 'accept', '--note', 'ran the check, then emptied the file and saw it fail').out, /verified #1/);
+ const apiRunner = box.run(box.repo, 'worktree', 'api', '--route', 'mid').out.match(/^made (\S+) /)[1];
+ const ran = box.run(apiRunner, 'run', '--agent-light', weak, '--agent-mid', strong, '--attempts', '2', '--minutes', '2');
+ assert.equal(ran.code, 0, ran.err);
+ assert.match(ran.out, /#2 attempt 1\/2: running the light agent[\s\S]*#2 escalated light -> mid[\s\S]*#2 attempt 1\/2: running the mid agent\n#2 attempt 1: green[\s\S]*submitted #2/);
+ assert.match(ran.out, /runner done: 1 submitted, 1 escalated/);
+ assert.equal(box.tryGit(apiRunner, 'merge-base', '--is-ancestor', commit, 'HEAD').status, 0);
+ const packs = join(box.dir, 'repo', '.git', 'worktrees', apiRunner.split('/').at(-1), 'pullboard', 'packs');
+ assert.match(readFileSync(join(packs, '2-mid-1.md'), 'utf8'), /## Earlier tries by a lighter model\n- 2 attempts stayed red/);
+ assert.equal(existsSync(join(packs, '2-light-1.md')), true);
+});
+
+test('sweep files one light item per flagged file, in its lane; a second sweep skips what is open [N15]', () => {
+ const box = project();
+ writeFileSync(join(box.dir, 'novar.mjs'), [
+ "import fs from 'node:fs';",
+ "import path from 'node:path';",
+ 'const walk = (p) => fs.statSync(p).isDirectory() ? fs.readdirSync(p).filter((n) => !n.startsWith(".") && n !== "node_modules").flatMap((n) => walk(path.join(p, n))) : [p];',
+ 'let found = 0;',
+ 'for (const file of process.argv.slice(2).flatMap(walk).filter((f) => f.endsWith(".js"))) {',
+ ' fs.readFileSync(file, "utf8").split("\\n").forEach((line, i) => { const col = line.indexOf("var "); if (col >= 0) { found += 1; console.log(`${file}:${i + 1}:${col + 1}: no-var Unexpected var, use let or const.`); } });',
+ '}',
+ 'process.exit(found ? 1 : 0);',
+ '',
+ ].join('\n'));
+ commitFile(box, box.repo, 'web/a.js', 'var a = 1;\nvar b = 2;\n', 'chore: two vars');
+ commitFile(box, box.repo, 'api/b.js', 'var c = 3;\n', 'chore: one var');
+ const sweep = ['sweep', '--run', `node ${join(box.dir, 'novar.mjs')} .`, '--check', `node ${join(box.dir, 'novar.mjs')} {file}`];
+ assert.match(box.run(box.web, ...sweep).err, /COORDINATOR_ONLY/);
+ assert.match(box.run(box.repo, ...sweep, '--dry-run').out, /would file: fix 2 problems in web\/a.js \(web lane, light\)/);
+ const filed = box.run(box.repo, ...sweep);
+ assert.equal(filed.code, 0, filed.err);
+ assert.match(filed.out, /#1 fix 2 problems in web\/a.js \(web lane, light\)\n#2 fix 1 problem in api\/b.js \(api lane, light\)/);
+ assert.match(filed.out, /3 problems in 2 files; filed 2/);
+ const shown = box.run(box.repo, 'show', '1').out;
+ assert.match(shown, new RegExp(`check: node ${join(box.dir, 'novar.mjs')} web/a.js`));
+ assert.match(shown, /- line 2:1 no-var: Unexpected var, use let or const\./);
+ assert.match(box.run(box.repo, ...sweep).out, /already open: web\/a.js, api\/b.js\n3 problems in 2 files; filed 0/);
+});
+
test('pre-commit runs the fixers on fully staged files and restages them; partly staged files are left alone [C5]', () => {
const box = project();
const fixer = join(box.dir, 'trim.mjs');
diff --git a/test/sweep.test.js b/test/sweep.test.js
new file mode 100644
index 00000000..2c7937ad
--- /dev/null
+++ b/test/sweep.test.js
@@ -0,0 +1,67 @@
+/**
+ * The sweep (N15): reading checkers' reports and turning them into one item per file.
+ */
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+import { briefFiles, briefSections } from '../src/brief.js';
+import { parseProblems, sweepItems } from '../src/sweep.js';
+
+const ROOT = '/repo';
+
+test('reads ESLint JSON, with absolute paths made relative [N15]', () => {
+ const report = JSON.stringify([
+ { filePath: '/repo/web/a.js', messages: [{ line: 3, column: 5, ruleId: 'no-unused-vars', message: "'x' is unused." }] },
+ { filePath: '/repo/web/b.js', messages: [] },
+ ]);
+ assert.deepEqual(parseProblems(`some banner\n${report}`, ROOT), [
+ { file: 'web/a.js', line: 3, col: 5, rule: 'no-unused-vars', message: "'x' is unused." },
+ ]);
+});
+
+test('reads TypeScript and file:line:col reports [N15]', () => {
+ const text = [
+ 'src/store.ts(12,7): error TS2322: Type string is not assignable to type number.',
+ './api/server.py:4:1: F401 os imported but unused',
+ 'lib/util.py:9: error: Missing return statement [return]',
+ 'web/a.js:2:1: no-var Unexpected var, use let or const.',
+ '/repo/web/b.js:7:3: Expected === and instead saw ==. [Error/eqeqeq]',
+ 'Found 3 errors.',
+ 'warning: something without a place',
+ ].join('\n');
+ assert.deepEqual(parseProblems(text, ROOT), [
+ { file: 'src/store.ts', line: 12, col: 7, rule: 'TS2322', message: 'Type string is not assignable to type number.' },
+ { file: 'api/server.py', line: 4, col: 1, rule: 'F401', message: 'os imported but unused' },
+ { file: 'lib/util.py', line: 9, col: 0, rule: 'return', message: 'Missing return statement' },
+ { file: 'web/a.js', line: 2, col: 1, rule: 'no-var', message: 'Unexpected var, use let or const.' },
+ { file: 'web/b.js', line: 7, col: 3, rule: 'eqeqeq', message: 'Expected === and instead saw ==.' },
+ ]);
+});
+
+test('files one complete light item per file, most problems first, skipping covered files [N15, B14]', () => {
+ const problems = [
+ { file: 'web/a.js', line: 1, col: 1, rule: 'semi', message: 'Missing semicolon.' },
+ { file: 'api/b.js', line: 2, col: 1, rule: 'eqeqeq', message: 'Expected ===.' },
+ { file: 'api/b.js', line: 5, col: 3, rule: 'eqeqeq', message: 'Expected ===.' },
+ { file: 'web/c.js', line: 1, col: 1, rule: 'semi', message: 'Missing semicolon.' },
+ { file: '../outside.js', line: 1, col: 1, rule: 'semi', message: 'x' },
+ ];
+ const { items, skipped } = sweepItems(problems, {
+ laneOf: (path) => path.split('/')[0],
+ covered: new Set(['web/c.js']),
+ check: 'npx eslint {file}',
+ report: 'npx eslint -f json .',
+ route: 'light',
+ max: 5,
+ });
+ assert.deepEqual(items.map((item) => [item.title, item.lane, item.check]), [
+ ['fix 2 problems in api/b.js', 'api', 'npx eslint api/b.js'],
+ ['fix 1 problem in web/a.js', 'web', 'npx eslint web/a.js'],
+ ]);
+ assert.deepEqual(skipped, ['web/c.js']);
+ const [first] = items;
+ assert.deepEqual(briefFiles(first.brief), ['api/b.js']);
+ assert.match(first.brief, /- line 5:3 eqeqeq: Expected ===\./);
+ assert.ok(briefSections(first.brief).test.length);
+ assert.match(first.brief, /Out of scope: every other file; disabling the rule; ignore or suppression comments/);
+ assert.equal(sweepItems(problems, { laneOf: () => 'web', covered: new Set(), check: 'c {file}', report: 'r', route: 'light', max: 1 }).items.length, 1);
+});