Files
stack/packages/bus/tests/project-runtime.test.mjs
T
jason.woltjeandClaude Opus 5.5 3190ad762b bus, project: file-backed north-star specs with spec.read and record.write (row 138, #1632)
Row 138 round 2, Rocko's candidate e3f9a400 (43 paths) on 26a0b0fab.
Dewey approved (comment 28754) after round 1 changes (comment 28752):
D1-D5 mutants killed, the 17 touched test files run singly passed
124/124. Rocko's own run: 753 tests and 59/59 mutants killed.

The bus gains the project adapter through runtime.mjs, the way it
already injects the organization, so broker.mjs takes no new imports
and refuses with project-not-configured when no adapter is set. The
project socket timeout is 120s. Roles gain record.write. The schema
moves from 3e to 3f; the live migration follows MIGRATION.md and
needs Mos's window.

Sage's landing gate ran on c842686d5 plus the candidate: 25 steps,
all rc 0 (15 packages, 10 script suites), network sage-r138_default
removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 20:49:44 -05:00

53 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { startBroker } from '../src/runtime.mjs';
import { Client } from '../src/client.mjs';
import { startTimeOf } from '../../seat/src/proc.mjs';
import { initProject } from '../../project/src/index.mjs';
import { fixture } from './spec-fixtures.mjs';
test('Broker keeps the existing sandbox client import closure: no new imports or lazy project import', () => {
const source = readFileSync(new URL('../src/broker.mjs', import.meta.url), 'utf8');
assert.deepEqual([...source.matchAll(/^import .*;$/gm)].map(m => m[0]), [
"import { randomUUID, randomBytes } from 'node:crypto';",
"import { loadRequirements } from '../../tasks/src/requirements.mjs';",
]);
assert.doesNotMatch(source, /\bimport\s*\(/);
});
test('without a trusted project adapter all three async paths refuse project-not-configured', async t => {
const f = await fixture(t, { adapter: false });
for (const [verb, args] of [
['spec.read', { project: 'stack' }],
['record.write', { project: 'stack', path: 'docs/a.md', record: '# A' }],
['decision.raise', { project: 'stack', spec_path: 'spec/north-star.md', spec_commit: f.commit }],
]) await assert.rejects(f.call(f.coder, verb, args), { code: 'project-not-configured' });
assert.equal(f.store.get('SELECT count(*) n FROM decisions').n, 0);
});
test('real startBroker injects the project adapter for socket reads and bound-author record writes', async t => {
const root = mkdtempSync(join(tmpdir(), 'project-runtime-'));
let runtime;
t.after(async () => { await runtime?.close(); rmSync(root, { recursive: true, force: true }); });
const business = { id: 'demo', human: 'jason', projects: { stack: { root: join(root, 'code') } },
arbiters: { technical: 'coder', delivery: 'coder' }, roles: { coder: {
definition: 'coder', authority: { withinRole: ['record.write'], crossRole: [] },
} } };
const initialized = await initProject({ business, project: 'stack', dataRoot: root });
runtime = await startBroker({ dataRoot: root, businesses: { demo: business }, launches: [{
business: 'demo', role: 'coder', run: 'runtime-run', harness: 'pi',
pid: process.pid, startTime: startTimeOf(process.pid),
}] });
const client = new Client({ path: runtime.path, cap: runtime.launches[0].cap });
await client.call('role.claim');
const spec = await client.call('spec.read', { project: 'stack' });
assert.equal(spec.commit, initialized.commit);
assert.equal(spec.confirmed, true);
const record = await client.call('record.write', { project: 'stack', path: 'docs/runtime.md', record: '# Runtime\n' });
assert.match(record.commit, /^[0-9a-f]{40}$/);
assert.equal(readFileSync(join(initialized.repo, record.path), 'utf8'), '# Runtime\n');
});