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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
test(check): wait for background baseline before cleanup [C7]
Corey Olson866602a706e9
diff --git a/test/check.test.js b/test/check.test.jsindex f556eb28..99b41bc6 100644--- a/test/check.test.js+++ b/test/check.test.js@@ -6,19 +6,40 @@ import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { DatabaseSync } from 'node:sqlite';import { after, test } from 'node:test';+import { addItem, closeBoard, openBoard } from '../src/board.js';+import { prepareCheckBaseline } from '../src/check-baseline.js';import { removeFixtureDirectory } from './cleanup-diagnostics.js';const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+const BASELINE_WORKER = resolve(import.meta.dirname, '../bin/check-baseline.js');const TEMP_DIRS = [];+const BACKGROUND_WRITERS = [];const SPEC = `# Check ownership fixture## G · Goals- G1 [approved, must] The fixture keeps its board. | gate: true`;-after(() => {+/** Wait for every owned baseline worker before removing its fixture repository. */+async function cleanupFixtures() {+ const failures = [];+ for (const writer of BACKGROUND_WRITERS) writeFileSync(writer.releaseFile, 'release');+ for (const writer of BACKGROUND_WRITERS) {+ try {+ await writer.closed;+ assert.notEqual(writer.child.exitCode, null, `background writer ${writer.name} did not exit before cleanup`);+ assert.equal(writer.child.signalCode, null, `background writer ${writer.name} was signaled before cleanup`);+ assert.equal(writer.child.exitCode, 0, `background writer ${writer.name} exited unsuccessfully before cleanup`);+ assert.equal(readFileSync(writer.completedFile, 'utf8'), writer.completedValue,+ `background writer ${writer.name} wrote its late marker before cleanup`);+ } catch (error) { failures.push(error); }+ }+ for (const writer of BACKGROUND_WRITERS) if (writer.child.exitCode === null) await writer.closed;for (const dir of TEMP_DIRS) removeFixtureDirectory(dir);-});+ if (failures.length) throw failures[0];+}++after(cleanupFixtures);/** Quote a literal executable path for the fixture hook's POSIX shim. */function shellWord(value) {@@ -99,7 +120,7 @@ function markerCheck(filename) {/** Add a check-bearing item as the coordinator and return its persisted id. */function addCheckedItem(box, title, command) {- const result = box.run(box.repo, ['add', 'coordinator', title, '--check', command, '--json']);+ const result = box.run(box.repo, ['add', 'coordinator', title, '--check', command, '--wait', '--json']);assert.equal(result.status, 0, result.stderr);return JSON.parse(result.stdout).item.item_id;}@@ -194,7 +215,7 @@ test('[V2,N23] only the coordinator sets checks and agents confirm them before econst interactiveCommand = markerCheck('check-ran-interactive.txt');const interactiveId = ordinaryId;- const authored = box.run(box.repo, ['edit', String(interactiveId), '--check', interactiveCommand, '--json']);+ const authored = box.run(box.repo, ['edit', String(interactiveId), '--check', interactiveCommand, '--wait', '--json']);assert.equal(authored.status, 0, authored.stdout + authored.stderr);assert.equal(queryBoard(box, 'SELECT item_created_by FROM item WHERE item_id = ?', interactiveId).item_created_by, 'web-1','the check setter is derived from the edit, independently of the item creator');@@ -231,3 +252,54 @@ test('[V2,N23] only the coordinator sets checks and agents confirm them before eassert.equal(JSON.parse(yesResult.stdout).check, yesCommand);assert.equal(readFileSync(join(box.web, 'check-ran-yes.txt'), 'utf8'), 'ran');});++/** Wait for a real baseline worker to start its held check before the test body ends. */+async function waitForFile(filename, child, description) {+ const deadline = Date.now() + 10_000;+ while (!existsSync(filename) && child.exitCode === null && child.signalCode === null && Date.now() < deadline) {+ await new Promise(resolvePromise => setTimeout(resolvePromise, 10));+ }+ assert.ok(existsSync(filename), `${description}${child.fixtureFailure ? `: ${child.fixtureFailure}` : ''}`);+}++test('check cleanup waits for every background writer [C7]', async () => {+ const box = project();+ const startedFile = join(box.dir, 'baseline-started');+ const releaseFile = join(box.dir, 'baseline-release');+ const completedFile = join(box.dir, 'baseline-completed');+ const completedValue = 'late baseline write completed';+ const source = [+ `const fs = require('node:fs');`,+ `fs.writeFileSync(${JSON.stringify(startedFile)}, 'started');`,+ `while (!fs.existsSync(${JSON.stringify(releaseFile)})) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);`,+ `fs.writeFileSync(${JSON.stringify(completedFile)}, ${JSON.stringify(completedValue)});`,+ ].join('');+ const command = `${shellWord(process.execPath)} -e ${shellWord(source)}`;+ const baseline = prepareCheckBaseline(box.repo, command);+ assert.equal(baseline.result, 'pending', 'the real fixture check starts with an authorized pending baseline');+ const board = openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));+ let itemId;+ try {+ itemId = addItem(board, {+ by: 'coordinator', lane: 'web', title: 'Held baseline writer',+ criterion: 'cleanup waits until the baseline worker exits', check: command, checkBaseline: baseline,+ });+ } finally { closeBoard(board); }++ const child = spawn(process.execPath, [BASELINE_WORKER, box.repo, String(itemId), baseline.request], {+ cwd: box.repo, env: box.env, stdio: 'ignore',+ });+ const closed = new Promise(resolveClose => {+ child.once('close', (code, signal) => resolveClose({ code, signal }));+ });+ BACKGROUND_WRITERS.push({+ name: `baseline request ${baseline.request}`,+ child,+ releaseFile,+ completedFile,+ completedValue,+ closed,+ });+ await waitForFile(startedFile, child, `background writer ${baseline.request} started its check`);+ assert.equal(existsSync(completedFile), false, 'the baseline is still writing after the test body reaches cleanup');+});