Files
stack/packages/cli/tests/project.test.mjs
T
jason.woltjeandClaude Opus 5.5 686fc1cb6d project: records layout, init, check and writer (row 147, #1641)
Round 2 candidate 7a585aa9606863a0d44a26094b585160914e3d8fd5f13436b56470cd69e6d867
(Rocko, packet fafee2f22), approved by Filbert in comment 28707.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 19:10:52 -05:00

43 lines
2.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
import { main, run } from '../src/cli.mjs';
import { fixture, humanEnv, io, tmp } from './helpers.mjs';
import { writeJson } from '../../business/tests/helpers.mjs';
test('project init/check use declared business repo and never contact the bus', async t => {
const root = tmp(t), f = fixture(root);
f.doc.projects.stack.repo = join(root, 'records');
writeJson(join(root, 'config/businesses/acme.json'), f.doc);
const x = io(humanEnv(f.env));
const deps = { transport: () => assert.fail('local project command contacted bus') };
await main(['project', 'init', 'acme', 'stack'], x, deps);
assert.ok(existsSync(join(root, 'records/spec/north-star.md')));
const checked = io(humanEnv(f.env));
assert.equal(await run(['project', 'check', 'acme', 'stack'], checked, deps), 0);
assert.match(checked.out.text, /valid|checked/);
writeFileSync(join(root, 'records/unknown'), 'bad');
const bad = io(humanEnv(f.env));
assert.equal(await run(['project', 'check', 'acme', 'stack'], bad, deps), 2);
assert.match(bad.err.text, /unknown/);
});
test('project commands validate args and refuse undeclared projects and agent init', async t => {
const root = tmp(t), f = fixture(root);
await assert.rejects(main(['project', 'init', 'acme', 'missing'], io(humanEnv(f.env)), {}), /declare/);
await assert.rejects(main(['project', 'init', 'acme', 'stack'], io({ ...f.env, CODEX_THREAD_ID: 'fixture-agent' }), {}), /agent/i);
for (const args of [[], ['other', 'acme', 'stack'], ['init', 'acme'], ['check', 'acme', 'stack', '--write']])
assert.equal(await run(['project', ...args], io(humanEnv(f.env)), {}), 4);
});
test('project dispatcher reaches the human CLI', async t => {
const root = tmp(t), f = fixture(root);
const result = spawnSync(new URL('../../../scripts/mosaic', import.meta.url).pathname, ['project'], {
encoding: 'utf8', env: humanEnv(f.env),
});
assert.equal(result.status, 4);
assert.match(result.stderr, /mosaic project/);
});