56 lines
3.1 KiB
JavaScript
56 lines
3.1 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';",
|
|
// Row 137 (#1631): land-work's checks, in RUNNER_FILES beside the broker. They import nothing.
|
|
"import { MERGE, LandingRefusal, readLanding } from './landing.mjs';",
|
|
]);
|
|
assert.doesNotMatch(source, /\bimport\s*\(/);
|
|
assert.doesNotMatch(readFileSync(new URL('../src/landing.mjs', import.meta.url), 'utf8'), /\bimport\b/);
|
|
});
|
|
|
|
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');
|
|
});
|