Files
stack/packages/bus/tests/project-await.test.mjs
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

62 lines
3.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { Store } from '../src/store.mjs';
import { Broker, BusError } from '../src/broker.mjs';
function fixture(t, project, secretCheck = () => {}) {
const root = mkdtempSync(join(tmpdir(), 'project-await-'));
const store = new Store(root);
t.after(() => { store.close(); rmSync(root, { recursive: true, force: true }); });
const business = { id: 'demo', human: 'jason', arbiters: { technical: 'coder', delivery: 'coder' }, roles: {
coder: { definition: 'coder', authority: { withinRole: ['record.write'], crossRole: [] } },
} };
const broker = new Broker({ store, businesses: { demo: business }, project, secretCheck });
const cap = broker.bindLaunch({ business: 'demo', role: 'coder', run: 'run', harness: 'pi', address: 'coder' });
const call = (verb, args = {}) => broker.request(cap, { verb, args });
call('role.claim');
return { broker, cap, call, store };
}
test('D1: committed write with a failed receipt refuses outcome-unknown without action.allowed', async t => {
let f, committed = false;
f = fixture(t, { async writeRecord() {
committed = true;
f.call('role.release');
return { path: 'docs/result.md', commit: 'a'.repeat(40) };
} });
let returned;
await assert.rejects(async () => {
returned = await f.call('record.write', { project: 'stack', path: 'docs/result.md', record: '# Result' });
}, { code: 'outcome-unknown' });
assert.equal(committed, true);
assert.equal(returned, undefined);
assert.deepEqual(f.store.all("SELECT body FROM events WHERE kind='action.allowed' AND json_extract(body,'$.action')='record.write'"), []);
});
test('D2: spec.read refuses without content if its role is released during the read', async t => {
let f;
f = fixture(t, { async readSpec() {
f.call('role.release');
return { content: 'CONTENT-MUST-NOT-RETURN' };
} });
let returned;
await assert.rejects(async () => { returned = await f.call('spec.read', { project: 'stack' }); }, { code: 'not-holder' });
assert.equal(returned, undefined);
assert.ok(!JSON.stringify(f.store.all('SELECT body FROM events')).includes('CONTENT-MUST-NOT-RETURN'));
});
for (const field of ['content', 'subject']) test(`D3: spec.read secret check refuses flagged ${field} without content`, async t => {
const marker = 'FLAGGED-SPEC-VALUE';
const result = { content: field === 'content' ? marker : '# Safe', log: [{ subject: field === 'subject' ? marker : 'Safe' }] };
const f = fixture(t, { async readSpec() { return result; } }, value => {
if (JSON.stringify(value).includes(marker)) throw new BusError('secret-refused');
});
let returned;
await assert.rejects(async () => { returned = await f.call('spec.read', { project: 'stack' }); }, { code: 'secret-refused' });
assert.equal(returned, undefined);
assert.ok(!JSON.stringify(f.store.all('SELECT body FROM events')).includes(marker));
});