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(cli): catalog and exercise every JSON result [A1]
Corey Olson2eb3a7802cd4
diff --git a/src/cli.js b/src/cli.jsindex 973b4517..7efc7b16 100644--- a/src/cli.js+++ b/src/cli.js@@ -731,7 +731,7 @@ function worktreeFor(io, lane, route) {git(mainRoot, ['worktree', 'add', '-q', '-b', `${lane}/${n}`, pathFor(n), git(mainRoot, ['rev-parse', 'HEAD'])]);const root = git(pathFor(n), ['rev-parse', '--show-toplevel']);const id = withBoard(ctx, (board) => store.register(board, { lane, path: root, route }));- io.result?.({ agent: id, lane, route, path: root, branch: `${lane}/${n}`, prompt: `You are ${id}, in the ${lane} lane. Work only in ${shellWord(root)}, and start every command with ${cdTo(root)}\nRead ${shellWord(join(root, 'AGENTS.md'))} first. Its rules govern this work.` });+ io.result?.({ agent: id, lane, route, path: root, branch: `${lane}/${n}`, prompt: `You are ${id}, in the ${lane} lane. Work only in ${shellWord(root)}, and start every command with ${cdTo(root)}\nRead ${shellWord(join(root, 'AGENTS.md'))} first. Its rules govern this work, over any other repo's instructions you were given.` });io.say(`made ${root} on branch ${lane}/${n}, joined as ${id} in the ${lane} lane${route === 'light' ? ', on the light route' : ''}`);io.say(`Work only in that folder. A shell that starts each command in the main checkout acts as the coordinator there, so start every command with: ${cdTo(root)}`);if (existsSync(join(root, 'package.json'))) io.say(` ${cdTo(root)} npm install (its own install, so its tests run its own code)`);@@ -1522,6 +1522,7 @@ async function runCommand(argv, io) {try {parsed = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true });} catch (error) {+ io.refusal?.(new Refused('USAGE', `${error.message}; run pullboard help`));io.err(`pullboard: ${error.message}\n\n${HELP}`);return 2;}@@ -1600,3 +1601,14 @@ export async function main(argv, streams) {io.flush(code);return code;}++/** Result-producing command names, including aliases, for API contract coverage (A1). */+export function resultCommands() {+ const args = { values: {}, rest: [] };+ return [...new Set([+ ...Object.keys(setupCommands({}, args)),+ ...Object.keys(readCommands({}, args)),+ ...Object.keys(workCommands({}, args)),+ 'help', 'version', 'tour', 'lifecycle', 'view', 'forget', 'spec', 'prompt', 'hook', 'gate',+ ])].sort();+}diff --git a/src/json.js b/src/json.jsindex 1a89e325..98dfce74 100644--- a/src/json.js+++ b/src/json.js@@ -1,5 +1,68 @@/** Versioned command results and refusals for tools that drive the CLI (A1). */+/** A shape's required top-level fields; optional fields may be added within this version. */+function shape(fields) {+ return { required: { version: 'number', ...fields } };+}++/** The CLI JSON v1 catalog, shared with API documentation and contract checks (A1). */+export const JSON_SHAPES = {+ version: 1,+ commands: {+ help: shape({ help: 'string' }),+ version: shape({ release: 'string' }),+ init: shape({ root: 'string', notes: 'array' }),+ hooks: shape({ notes: 'array' }),+ join: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string' }),+ worktree: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string', branch: 'string', prompt: 'string' }),+ resume: shape({ me: 'object', all: 'array', holding: 'array', sentBack: 'array', awaiting: 'array', toVerify: 'array', toMerge: 'array', open: 'array', holds: 'array', unread: 'number', newest: 'array', root: 'string', dirty: 'number', next: 'string' }),+ whoami: shape({ id: 'string', lane: 'string', path: 'string' }),+ lanes: shape({ lanes: 'object', shared: 'array', coordinator: 'string' }),+ list: shape({ items: 'array' }),+ show: shape({ item_id: 'number', item_title: 'string', item_lane: 'string', item_status: 'string', verdicts: 'array' }),+ status: shape({ me: 'object', mine: 'array', stats: 'object', unread: 'number' }),+ inbox: shape({ shouts: 'array' }),+ decisions: shape({ decisions: 'array' }),+ ledger: shape({ items: 'array', stats: 'object' }),+ log: shape({ events: 'array' }),+ add: shape({ item: 'object' }),+ edit: shape({ item: 'object' }),+ escalate: shape({ id: 'number', from: 'string', to: 'string' }),+ run: shape({ messages: 'array' }),+ sweep: shape({ messages: 'array' }),+ next: shape({ item: 'object', review: 'boolean', held: 'boolean', shared: 'array' }),+ check: shape({ id: 'number', green: 'boolean', seconds: 'number', check: 'string', report: 'string' }),+ claim: shape({ id: 'number', renewed: 'boolean', leaseUntil: 'string', digest: 'string' }),+ hold: shape({ lane: 'string', held: 'boolean' }),+ release: shape({ id: 'number' }),+ submit: shape({ id: 'number', commit: 'string', pin: 'string', gate: 'object' }),+ done: shape({ id: 'number', commit: 'string', pin: 'string', gate: 'object' }),+ verify: shape({ id: 'number', decision: 'string', reason: 'string' }),+ merged: shape({ id: 'number', commit: 'string' }),+ withdraw: shape({ id: 'number', reason: 'string' }),+ refreeze: shape({ id: 'number', after: 'string' }),+ shout: shape({ id: 'number', decision: 'boolean' }),+ answer: shape({ id: 'number', answers: 'number' }),+ tour: shape({ messages: 'array' }),+ lifecycle: shape({ markdown: 'string' }),+ view: shape({ url: 'string', port: 'number' }),+ forget: shape({ root: 'string' }),+ prompt: shape({ role: 'string', text: 'string' }),+ gate: shape({ green: 'boolean', report: 'string' }),+ spec: shape({ rows: 'array' }),+ 'spec check': shape({ rows: 'array' }),+ 'spec view': shape({ path: 'string' }),+ 'spec show': shape({ row: 'object', standing: 'object' }),+ 'spec unmet': shape({ rows: 'array' }),+ 'spec signoff': shape({ count: 'number', by: 'string', ids: 'array', evidence: 'array' }),+ 'hook pre-commit': shape({ messages: 'array' }),+ 'hook commit-msg': shape({ messages: 'array' }),+ 'hook pre-push': shape({ messages: 'array' }),+ },+ error: shape({ error: 'object' }),+ errorFields: { code: 'string', message: 'string', next: 'string' },+};+/** Extract a concrete repair from existing refusals, retaining their original guidance. */function nextStep(message) {const match = /(?:; |\. |: )((?:run|fix|restore|commit|check out|set|give|use|the coordinator|to keep looking|never work around)\b[\s\S]*)/i.exec(message);@@ -29,9 +92,9 @@ export function commandOutput(argv, streams) {const text = refusal?.message ?? [...diagnostics, ...messages].join('\n');const match = /\[([A-Z_]+)\]\s*([\s\S]*)/.exec(text);const message = refusal ? text.replace(/^\[[A-Z_]+\] /, '') : match?.[2] ?? text;- document = { version: 1, error: { code: refusal?.code ?? match?.[1] ?? (code === 2 ? 'USAGE' : 'COMMAND_FAILED'), message, next: nextStep(message) } };+ document = { version: JSON_SHAPES.version, error: { code: refusal?.code ?? match?.[1] ?? (code === 2 ? 'USAGE' : 'COMMAND_FAILED'), message, next: nextStep(message) } };} else if (result !== undefined) {- document = { version: 1, ...result };+ document = { version: JSON_SHAPES.version, ...result };} else {// A native versioned document, such as export, already owns its public shape.let native;@@ -39,7 +102,7 @@ export function commandOutput(argv, streams) {try { native = JSON.parse(messages[0]); } catch { /* Ordinary command prose is kept as messages. */ }}document = native && !Array.isArray(native) && typeof native.version === 'number'- ? native : { version: 1, messages, ...(diagnostics.length ? { diagnostics } : {}) };+ ? native : { version: JSON_SHAPES.version, messages, ...(diagnostics.length ? { diagnostics } : {}) };}streams.stdout.write(`${JSON.stringify(document, null, 2)}\n`);};diff --git a/test/api.test.js b/test/api.test.jsnew file mode 100644index 00000000..533851cf--- /dev/null+++ b/test/api.test.js@@ -0,0 +1,358 @@+/** The public, versioned JSON surface of every pullboard command (A1). */+import assert from 'node:assert/strict';+import { execFileSync, spawn, spawnSync } from 'node:child_process';+import {+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ realpathSync,+ rmSync,+ writeFileSync,+} from 'node:fs';+import { tmpdir } from 'node:os';+import { once } from 'node:events';+import { join, dirname, resolve, basename } from 'node:path';+import { after, test } from 'node:test';+import { resultCommands } from '../src/cli.js';+import { JSON_SHAPES } from '../src/json.js';++const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+const TEMP_DIRS = [];+const covered = new Set();+const coveredRoots = new Set();++after(() => {+ for (const dir of TEMP_DIRS) rmSync(dir, { recursive: true, force: true });+});++const SPEC = `# API fixture++## G · Goals+- G1 [approved, must] The fixture keeps its board. | gate: true+`;++/** Make a disposable home and a real repo with isolated git settings. */+function sandbox() {+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-api-')));+ TEMP_DIRS.push(dir);+ const env = {+ ...process.env,+ GIT_CONFIG_GLOBAL: '/dev/null',+ GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'API Test',+ GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'API Test',+ GIT_COMMITTER_EMAIL: '[email protected]',+ PULLBOARD_HOME: join(dir, 'home'),+ };+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();+ const run = (cwd, ...args) => spawnSync(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8' });+ return { dir, env, git, run };+}++/** Initialize a real pullboard repo, replace its fixture config, and commit setup files. */+function project() {+ const box = sandbox();+ const repo = join(box.dir, 'repo');+ mkdirSync(repo);+ box.git(repo, 'init', '-q', '-b', 'main');+ const initialized = json(box, repo, 'init');+ const configFile = join(repo, 'pullboard.json');+ const config = JSON.parse(readFileSync(configFile, 'utf8'));+ writeFileSync(configFile, `${JSON.stringify({+ ...config,+ gate: 'true',+ spec: 'SPEC.md',+ practice: 'PRACTICE.md',+ lanes: {+ app: { owns: ['app/'], specs: ['G1'] },+ review: { owns: [] },+ },+ shared: [],+ }, null, 2)}\n`);+ writeFileSync(join(repo, 'SPEC.md'), SPEC);+ writeFileSync(join(repo, 'PRACTICE.md'), '');+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: set up API fixture');+ return { ...box, repo, initialized };+}++/** Resolve the catalog entry for either a root command or a documented subcommand. */+function shapeFor(command, subcommand) {+ const candidates = [+ ...(subcommand ? [`${command} ${subcommand}`, `${command}.${subcommand}`, `${command}:${subcommand}`] : []),+ command,+ ];+ const key = candidates.find((candidate) => JSON_SHAPES.commands[candidate]);+ assert.ok(key, `JSON_SHAPES.commands must document ${command}${subcommand ? ` ${subcommand}` : ''}`);+ covered.add(key);+ coveredRoots.add(command);+ return JSON_SHAPES.commands[key];+}++/** Match one catalog field to its declared JSON value type. */+function hasType(value, type) {+ if (type === 'array') return Array.isArray(value);+ if (type === 'object') return value !== null && typeof value === 'object' && !Array.isArray(value);+ if (type === 'null') return value === null;+ return typeof value === type;+}++/** Check one required-field map from JSON_SHAPES. */+function assertRequiredShape(value, required, label) {+ for (const [field, type] of Object.entries(required ?? {})) {+ assert.ok(Object.hasOwn(value, field), `${label} must include ${field}`);+ assert.ok(hasType(value[field], type), `${label}.${field} must be ${type}`);+ }+}++/** Parse a command's sole JSON document and check its public command shape. */+function json(box, cwd, command, args = [], subcommand) {+ const result = box.run(cwd, command, ...args, '--json');+ assert.equal(result.status, 0, `${command} ${args.join(' ')}: ${result.stderr}${result.stdout}`);+ assert.equal(result.stderr, '', `${command} --json must keep stderr empty`);+ const document = JSON.parse(result.stdout);+ assert.equal(document.version, 1, `${command} --json has a version 1 envelope`);+ assertRequiredShape(document, shapeFor(command, subcommand).required, command);+ return document;+}++/** Check one refusal document, including the exact public code, message and next step. */+function jsonError(box, cwd, command, args, { status, code, message, next }, subcommand) {+ const result = box.run(cwd, command, ...args, '--json');+ assert.equal(result.status, status, `${command}: ${result.stdout}${result.stderr}`);+ assert.equal(result.stderr, '', `${command} refusal must be JSON-only`);+ const document = JSON.parse(result.stdout);+ assert.equal(document.version, 1);+ assertRequiredShape(document, JSON_SHAPES.error.required, 'error envelope');+ assertRequiredShape(document.error, JSON_SHAPES.errorFields, 'error');+ if (subcommand) shapeFor(command, subcommand);+ assert.deepEqual(document.error, { code, message, next });+ return document;+}++/** Assert only that output is a single JSON value with no second document. */+function parseOneDocument(stdout) {+ const document = JSON.parse(stdout);+ assert.equal(document.version, 1);+ return document;+}++test('[A1] command results match the catalog across roots and subcommands', () => {+ const box = project();+ const { repo } = box;+ assert.equal(box.initialized.version, 1);+ assertRequiredShape(box.initialized, shapeFor('init').required, 'init');++ for (const [flag, command] of [['--help', 'help'], ['--version', 'version']]) {+ const output = box.run(repo, flag, '--json');+ assert.equal(output.status, 0, output.stderr);+ assert.equal(output.stderr, '');+ const document = parseOneDocument(output.stdout);+ assertRequiredShape(document, shapeFor(command).required, command);+ }+ json(box, repo, 'version');+ json(box, repo, 'help');+ json(box, repo, 'lifecycle');+ json(box, repo, 'prompt', ['signoff']);+ json(box, repo, 'hooks');+ json(box, repo, 'whoami');+ json(box, repo, 'lanes');+ json(box, repo, 'resume');+ json(box, repo, 'status');+ const plainStatus = box.run(repo, 'status');+ assert.equal(plainStatus.status, 0, plainStatus.stderr);+ assert.equal(plainStatus.stderr, '');+ assert.match(plainStatus.stdout, /^coordinator: /, 'ordinary text mode remains readable');+ assert.throws(() => JSON.parse(plainStatus.stdout));+ json(box, repo, 'inbox');+ json(box, repo, 'decisions');+ json(box, repo, 'ledger');+ json(box, repo, 'log');+ json(box, repo, 'list');+ json(box, repo, 'gate');++ json(box, repo, 'spec', ['--json']);+ json(box, repo, 'spec', ['check'], 'check');+ json(box, repo, 'spec', ['view', '--out', join(box.dir, 'spec.html')], 'view');+ json(box, repo, 'spec', ['show', 'G1'], 'show');+ json(box, repo, 'spec', ['unmet'], 'unmet');+ mkdirSync(join(repo, 'test'));+ writeFileSync(join(repo, 'test', 'proof.test.js'), "import { test } from 'node:test';\ntest('proof [G1]', () => {});\n");+ box.git(repo, 'add', 'test/proof.test.js');+ box.git(repo, 'commit', '-q', '-m', 'test: cite the fixture');+ json(box, repo, 'spec', ['signoff', 'G1', '--by', 'CO'], 'signoff');+ box.git(repo, 'add', '.pullboard/signoffs.jsonl');+ box.git(repo, 'commit', '-q', '-m', 'chore: record the fixture signoff');++ const messageFile = join(box.dir, 'commit-message.txt');+ writeFileSync(messageFile, 'chore: valid fixture\n');+ json(box, repo, 'hook', ['pre-commit'], 'pre-commit');+ json(box, repo, 'hook', ['commit-msg', messageFile], 'commit-msg');+ json(box, repo, 'hook', ['pre-push'], 'pre-push');++ const review = json(box, repo, 'worktree', ['review']);+ const reviewPath = review.path;+ const secondPath = join(box.dir, 'review-two');+ box.git(repo, 'worktree', 'add', '-q', secondPath, '-b', 'review/two');+ json(box, secondPath, 'join', ['review']);++ const added = json(box, repo, 'add', ['coordinator', 'API item', '--specs', 'G1', '--criterion', 'the API item is verified', '--check', 'true']);+ assert.equal(added.item.item_id, 1);+ json(box, repo, 'edit', ['1', '--criterion', 'the edited API item is verified', '--check', 'true']);+ json(box, repo, 'show', ['1']);+ json(box, repo, 'list', ['--all']);+ json(box, repo, 'next');+ json(box, repo, 'claim', ['1']);+ json(box, repo, 'check', ['1']);+ json(box, repo, 'release', ['1']);+ json(box, repo, 'claim', ['1']);+ json(box, repo, 'submit', ['1']);+ json(box, reviewPath, 'next', ['--verify']);+ json(box, reviewPath, 'verify', ['1', 'accept', '--note', 'checked the fixture result']);+ json(box, repo, 'merged', ['1', 'HEAD']);++ json(box, repo, 'add', ['coordinator', 'Done alias item', '--check', 'true']);+ json(box, repo, 'claim', ['2']);+ json(box, repo, 'done', ['2']);+ json(box, repo, 'add', ['coordinator', 'Withdraw item']);+ json(box, repo, 'withdraw', ['3', 'obsolete']);++ json(box, repo, 'add', ['coordinator', 'Refreeze item', '--specs', 'G1']);+ json(box, repo, 'claim', ['4']);+ writeFileSync(join(repo, 'SPEC.md'), SPEC.replace('The fixture keeps its board.', 'The fixture keeps its local board.'));+ json(box, repo, 'refreeze', ['4']);+ writeFileSync(join(repo, 'SPEC.md'), SPEC);++ json(box, repo, 'add', ['coordinator', 'Escalate item', '--route', 'light', '--criterion', 'the item is built', '--check', 'true', '--brief', 'Files:\n- README.md\nChange:\n- keep this fixture\nTest:\n- The item check passes']);+ json(box, repo, 'claim', ['5']);+ json(box, repo, 'escalate', ['5', '--note', 'the first route needs another pass']);+ json(box, repo, 'hold', ['app', '--reason', 'exercise JSON']);+ json(box, repo, 'hold', ['app', '--off']);++ json(box, secondPath, 'shout', ['coordinator', 'Please decide', '--decision']);+ json(box, repo, 'decisions');+ json(box, repo, 'answer', ['1', 'Yes, keep the change']);+ json(box, secondPath, 'inbox');+ json(box, repo, 'sweep', ['--run', 'true', '--check', 'true {file}']);++ json(box, reviewPath, 'run', ['--agent', 'true', '--items', '1']);+ json(box, repo, 'forget', ['.']);++ const tour = json(box, repo, 'tour');+ const location = tour.messages.find((line) => line.startsWith('Look around: cd '));+ assert.ok(location, 'tour result keeps its final repo path in messages');+ const tourRepo = /Look around: cd (.+) && pullboard log/.exec(location)?.[1];+ assert.ok(tourRepo && existsSync(tourRepo), 'the reported tour repo exists until the test cleans it up');+ assert.match(basename(dirname(tourRepo)), /^pullboard-tour-/, 'cleanup is confined to the generated tour folder');+ TEMP_DIRS.push(dirname(tourRepo));+});++test('[A1] refusals are one JSON document with exact public error fields', () => {+ const box = sandbox();+ const repo = join(box.dir, 'repo');+ mkdirSync(repo);+ box.git(repo, 'init', '-q', '-b', 'main');+ json(box, repo, 'init');+ writeFileSync(join(repo, 'pullboard.json'), `${JSON.stringify({ gate: 'true', lanes: {} }, null, 2)}\n`);+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: set up refusal fixture');++ const noRow = jsonError(box, repo, 'spec', ['show', 'G99'], {+ status: 1,+ code: 'NO_ROW',+ message: 'no row G99 in SPEC.md',+ next: 'Run pullboard help, correct the reported problem, and retry the command.',+ }, 'show');+ assert.equal(noRow.error.code, 'NO_ROW');++ const nothingFree = box.run(repo, 'next', '--json');+ assert.equal(nothingFree.status, 1);+ assert.equal(nothingFree.stderr, '');+ const nextDocument = JSON.parse(nothingFree.stdout);+ assert.equal(nextDocument.version, 1);+ assertRequiredShape(nextDocument, JSON_SHAPES.error.required, 'error envelope');+ assertRequiredShape(nextDocument.error, JSON_SHAPES.errorFields, 'error');+ shapeFor('next');+ assert.deepEqual(nextDocument.error, {+ code: 'NOTHING_FREE',+ message: "no open items in the coordinator lane; lane items are built from each lane's own worktree. To keep looking: pullboard next --wait 9 (minutes; give the command a ten-minute timeout)",+ next: 'To keep looking: pullboard next --wait 9 (minutes; give the command a ten-minute timeout)',+ });++ const unknown = box.run(repo, 'status', '--not-a-real-flag', '--json');+ assert.equal(unknown.status, 2);+ assert.equal(unknown.stderr, '');+ const unknownDocument = JSON.parse(unknown.stdout);+ assert.equal(unknownDocument.version, 1);+ assertRequiredShape(unknownDocument, JSON_SHAPES.error.required, 'error envelope');+ assertRequiredShape(unknownDocument.error, JSON_SHAPES.errorFields, 'error');+ shapeFor('status');+ assert.equal(unknownDocument.error.code, 'USAGE');+ assert.match(unknownDocument.error.message, /Unknown option '--not-a-real-flag'/);+ assert.equal(unknownDocument.error.next, 'run pullboard help');++ const valid = readFileSync(join(repo, 'SPEC.md'), 'utf8');+ writeFileSync(join(repo, 'SPEC.md'), `${valid}\n- G2 [maybe, must] Bad status.\n`);+ const textCheck = box.run(repo, 'spec', 'check');+ assert.equal(textCheck.status, 1);+ const invalid = box.run(repo, 'spec', 'check', '--json');+ assert.equal(invalid.status, 1);+ assert.equal(invalid.stderr, '');+ const invalidDocument = JSON.parse(invalid.stdout);+ assert.equal(invalidDocument.version, 1);+ assertRequiredShape(invalidDocument, JSON_SHAPES.error.required, 'error envelope');+ assertRequiredShape(invalidDocument.error, JSON_SHAPES.errorFields, 'error');+ shapeFor('spec', 'check');+ assert.equal(invalidDocument.error.code, 'COMMAND_FAILED');+ assert.equal(invalidDocument.error.message, textCheck.stdout.trim());+ assert.equal(invalidDocument.error.next, 'Run pullboard help, correct the reported problem, and retry the command.');+ rmSync(box.dir, { recursive: true, force: true });+});++test('[A1] view flushes one JSON document before shutdown', async (t) => {+ const box = project();+ t.after(() => rmSync(box.dir, { recursive: true, force: true }));+ const child = spawn(process.execPath, [BIN, 'view', '--no-open', '--port', '0', '--json'], { cwd: box.repo, env: box.env, stdio: ['ignore', 'pipe', 'pipe'] });+ let stdout = '';+ let stderr = '';+ child.stdout.setEncoding('utf8');+ child.stderr.setEncoding('utf8');+ child.stdout.on('data', (chunk) => { stdout += chunk; });+ child.stderr.on('data', (chunk) => { stderr += chunk; });+ const closed = once(child, 'close');+ t.after(() => {+ if (child.exitCode === null) child.kill('SIGTERM');+ });+ const ready = new Promise((resolveReady, rejectReady) => {+ const timeout = setTimeout(() => rejectReady(new Error('view did not flush its JSON result')), 10_000);+ child.stdout.on('data', () => {+ try {+ const document = JSON.parse(stdout);+ clearTimeout(timeout);+ resolveReady(document);+ } catch {+ // The public document is pretty-printed; wait until it is complete.+ }+ });+ child.once('error', (error) => {+ clearTimeout(timeout);+ rejectReady(error);+ });+ });+ const document = await ready;+ assert.equal(document.version, 1);+ coveredRoots.add('view');+ assertRequiredShape(document, shapeFor('view').required, 'view');+ child.kill('SIGTERM');+ await closed;+ assert.equal(stderr, '');+ assert.deepEqual(parseOneDocument(stdout), document, 'view does not flush a second document on shutdown');+});++test('[A1] every catalog command and subcommand has a real CLI exercise', () => {+ const missing = Object.keys(JSON_SHAPES.commands).filter((key) => !covered.has(key));+ assert.deepEqual(missing, [], `add real-repo invocations for undocumented coverage gaps: ${missing.join(', ')}`);+ assert.deepEqual([...coveredRoots].sort(), resultCommands(), 'every actual root/factory command has an invocation');+});