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
fix(person): trust a test relay only by explicit parameter [E22]
Corey Olsona14fe71ffdc0
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex 608bdd11..8cdf8341 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -1490,9 +1490,6 @@ if (process.argv[1] && resolve(process.argv[1]) === runner) {}}// After any browser wait, so a file never holds a core while it queues for a browser (#1046).- // Test-only, never published: the CLI under test may read its person authority from the loopback fixture relay (#408).- const fixtureOrigin = new URL('../test/person-authority-fixture-origin.js', import.meta.url);- if (process.env.NODE_TEST_CONTEXT === 'child-v8' && existsSync(fileURLToPath(fixtureOrigin))) process.env.NODE_OPTIONS = [process.env.NODE_OPTIONS, `--import=${fixtureOrigin.href}`].filter(Boolean).join(' ');if (process.env.NODE_TEST_CONTEXT === 'child-v8') tokenWaitMs = await takeTestFileToken();if (!landingWorker) installTestWatchdog();}diff --git a/src/person-signing-cli.js b/src/person-signing-cli.jsindex c1f62723..80e57f13 100644--- a/src/person-signing-cli.js+++ b/src/person-signing-cli.js@@ -38,13 +38,13 @@ const AUTHORITY_PATH = '/.well-known/pullboard-person-authority';const BUILT_IN_AUTHORITY_ORIGIN = new URL(DEFAULT_RELAY).origin;/**- * Whether a person authority may be read from this origin: the built-in relay over TLS, or the loopback fixture relay- * only when the test runner's own preload admits it. Never pullboard.json or a board row (#408 trust-anchor ruling).+ * Whether a person authority may be read from this origin: the built-in relay over TLS, or the one origin an+ * in-process caller hands this command as `io.trustedRelayOrigin`. That parameter exists only in a caller's own call+ * path, never in pullboard.json, a board row, an environment variable or a global, so no shell can set it (#408).*/-function authorityOrigin(origin) {+function authorityOrigin(origin, io) {if (origin === BUILT_IN_AUTHORITY_ORIGIN) return process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0';- const fixture = globalThis[Symbol.for('pullboard.personAuthorityFixtureOrigin')];- return typeof fixture === 'function' && fixture(origin) === true;+ return typeof io?.trustedRelayOrigin === 'string' && io.trustedRelayOrigin === origin;}/**@@ -62,7 +62,7 @@ export async function pinRelayAuthority(root, board, io = {}, { timeoutMs = 10_0const relay = relayStatus(root);if (!relay.linked || !relay.url) return null;const origin = new URL(relay.url).origin;- if (!authorityOrigin(origin)) {+ if (!authorityOrigin(origin, io)) {io.err?.(`pullboard: [PERSON_AUTHORITY_ORIGIN] ${origin} is not the built-in relay ${BUILT_IN_AUTHORITY_ORIGIN} over TLS, so it cannot vouch for the person; person moves wait for the built-in relay`);return null;}diff --git a/test/person-authority-fixture-origin.js b/test/person-authority-fixture-origin.jsdeleted file mode 100644index 513a10b9..00000000--- a/test/person-authority-fixture-origin.js+++ /dev/null@@ -1,6 +0,0 @@-/**- * Test-only preload (#408): lets the CLI under test read its person authority from a loopback fixture relay, which- * has no TLS. Only bin/run-tests.js adds it, to each test file's NODE_OPTIONS; it is never in the published package,- * and without it the CLI reads a first pin only from the built-in relay origin over TLS.- */-globalThis[Symbol.for('pullboard.personAuthorityFixtureOrigin')] = (origin) => /^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):\d{1,5}$/u.test(origin);diff --git a/test/person-first-pin-fixture.js b/test/person-first-pin-fixture.jsindex ecbf0ead..791716d1 100644--- a/test/person-first-pin-fixture.js+++ b/test/person-first-pin-fixture.js@@ -52,13 +52,17 @@ export function firstUnpairedAuthorityInsertion(t) {}/**- * Without the test runner's preload, the real CLI takes a first pin only from the built-in relay over TLS: a linked- * loopback relay over http, or any other origin, cannot vouch for the person, so signing stays off and nothing is pinned.+ * The shipped CLI takes a first pin only from the built-in relay over TLS: a linked loopback relay over http, or any+ * other origin, cannot vouch for the person, even with a planted preload or variable, so signing stays off and nothing+ * is pinned. Only a caller's own explicit parameter (test/person-trusted-cli.js) can name another relay.*/export async function firstPinNeedsBuiltInRelay(t) {const box = await relayClientFixture(t);assert.equal((await box.link()).code, 0);- const env = { ...box.env, NODE_OPTIONS: (box.env.NODE_OPTIONS ?? '').split(' ').filter(option => !option.includes('person-authority-fixture-origin')).join(' ') };+ // Any switch a shell can set is no authority: a preload that plants a trust hook, as an agent could, changes nothing.+ const planted = `globalThis[Symbol.for('pullboard.personAuthorityFixtureOrigin')] = () => true; globalThis.trustedRelayOrigin = ${JSON.stringify(box.origin)};`;+ const env = { ...box.env, PULLBOARD_TRUSTED_RELAY_ORIGIN: box.origin,+ NODE_OPTIONS: [box.env.NODE_OPTIONS, `--import=data:text/javascript,${encodeURIComponent(planted)}`].filter(Boolean).join(' ') };const pinned = () => {const board = store.openBoard(join(box.root, '.git', 'pullboard', 'board.sqlite'));try { return board.db.prepare("SELECT meta_value FROM board_meta WHERE meta_key='person_authority_local'").get(); }diff --git a/test/person-trusted-cli.js b/test/person-trusted-cli.jsnew file mode 100644index 00000000..96b5707d--- /dev/null+++ b/test/person-trusted-cli.js@@ -0,0 +1,15 @@+/**+ * Test-only entry (#408), never published: runs the shipped command with the loopback fixture relay handed in as+ * `trustedRelayOrigin`, an explicit parameter in the test's own call path. The shipped bin/pullboard.js has no such+ * switch, so outside a test the person authority comes only from the built-in relay over TLS.+ *+ * Usage: node test/person-trusted-cli.js <fixture relay origin> <pullboard arguments...>+ */+const [trustedRelayOrigin, ...argv] = process.argv.slice(2);+const emitWarning = process.emitWarning;+process.emitWarning = (warning, ...rest) => {+ if (String(warning).includes('SQLite is an experimental feature')) return;+ emitWarning.call(process, warning, ...rest);+};+const { main } = await import('../src/cli-main.js');+process.exitCode = await main(argv, { cwd: process.cwd(), stdout: process.stdout, stderr: process.stderr, stdin: process.stdin, trustedRelayOrigin });diff --git a/test/team.test.js b/test/team.test.jsindex 450083c7..4c607fab 100644--- a/test/team.test.js+++ b/test/team.test.js@@ -97,6 +97,8 @@ import { landingQueueCase } from './landing-queue-fixture.js';import { DatabaseSync } from 'node:sqlite';const CLI = join(import.meta.dirname, '..', 'bin', 'pullboard.js');+/** The shipped command run with an explicit trusted fixture relay; test-only, never published (#408). */+const TRUSTED_CLI = join(import.meta.dirname, 'person-trusted-cli.js');const helpers = createE2eHelpers();after(helpers.cleanup);@@ -610,10 +612,10 @@ async function phoneRequest(box, session, move) {return document.id;}-/** The phone requests this board has received, by id. */-async function receivedRequests(box) {- assert.equal((await box.cli('status')).code, 0, 'the coordinator reads the relay');- const meta = (await box.cli('export')).document.tables.board_meta.find((row) => row.meta_key === 'relay_person_requests');+/** The phone requests this board has received, by id, read through `run` (a test may pass its trusted command). */+async function receivedRequests(box, run = (...args) => box.cli(...args)) {+ assert.equal((await run('status')).code, 0, 'the coordinator reads the relay');+ const meta = (await run('export')).document.tables.board_meta.find((row) => row.meta_key === 'relay_person_requests');return Object.fromEntries((meta ? JSON.parse(meta.meta_value) : []).map((record) => [record.id, record]));}@@ -963,8 +965,11 @@ function holdsNoPersonCredential(directory) {test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(60) }, async (t) => { // budget: hang ceiling for real CLI runs and relay calls; not a speed target.const box = await relayClientFixture(t);- /** Run the real CLI in the main checkout with a chosen environment. */- const cli = (env, ...args) => relayFixtureChild(box.root, env, [CLI, ...args, '--json']);+ // The shipped command, handed the loopback fixture relay as an explicit trusted parameter in this test's own call path:+ // no environment variable or global can make the real CLI trust it (#408 rulings 38756cb3 and 28611).+ const trusted = [TRUSTED_CLI, box.origin];+ /** Run the command in the main checkout with a chosen environment, trusting only this fixture relay. */+ const cli = (env, ...args) => relayFixtureChild(box.root, env, [...trusted, ...args, '--json']);// S10a: an agent that cleared AI_AGENT and CLAUDECODE has exactly the person's shell markers.const cleared = { ...box.env };const marked = { ...box.env, AI_AGENT: '1', CLAUDECODE: '1' };@@ -1021,7 +1026,7 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(renameSync(`${box.linkFile}.unpaired`, box.linkFile);assert.ok(holdsNoPersonCredential(box.root) && holdsNoPersonCredential(box.env.HOME), 'no file holds a person session or grant');const terminal = helpers.launch({ ...box, env: { ...cleared, SSH_CONNECTION: '127.0.0.1 40000 127.0.0.1 22' } },- box.root, process.execPath, [CLI, 'answer', String(ask), 'Signed on the passkey', '--as', 'person', '--json']);+ box.root, process.execPath, [...trusted, 'answer', String(ask), 'Signed on the passkey', '--as', 'person', '--json']);t.after(async () => { if (terminal.exitCode === null && terminal.signalCode === null) terminal.kill('SIGTERM'); await terminal.closed; });/** Observe fixture SQLite directly; no second command may execute the waiting action. */const nativeRows = (sql, ...args) => {@@ -1115,7 +1120,7 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(} finally { raw.close(); }assert.equal((await box.cli('status')).document.person.signed, true, 'the hand-written off turns nothing off');const waitingAgain = helpers.launch({ ...box, env: cleared }, box.root, process.execPath,- [CLI, 'answer', String(ask), 'still signed', '--as', 'person', '--json']);+ [...trusted, 'answer', String(ask), 'still signed', '--as', 'person', '--json']);try {await helpers.waitFor(() => { assert.equal(waitingAgain.exitCode, null, waitingAgain.stderrText); return waitingAgain.stderrText.includes('this terminal is waiting'); },'a cleared-marker terminal still waits for a new confirmation', relayWorkBudgetMs(5));@@ -1135,13 +1140,13 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(const rowGrant = await grantFor(request);assert.equal((await passkeyRequest(box, phone, request, { grant: rowGrant, ...passkey.get(grantChallenge(rowGrant)) })).status, 200);}- received = await receivedRequests(box);+ received = await receivedRequests(box, (...args) => cli(box.env, ...args));assert.equal(received[blind.id].error?.code, 'STALE_ROW_DECISION', 'a decision that does not name the rows shown is refused');assert.notEqual(received[seen.id].status, 'refused', JSON.stringify(received[seen.id]));const decided = (await box.cli('export')).document.tables.event.filter((row) => row.event_kind === 'row_decision');assert.deepEqual(decided.map((row) => [row.event_by, JSON.parse(row.event_detail).record.id]), [['person', 'G1']], 'the passkey decided exactly the row it showed');// The real CLI applies that decision, checked against the authority its relay vouches for, never a stored key (#408).- const applied = await box.cli('spec', 'apply');+ const applied = await cli(box.env, 'spec', 'apply');assert.equal(applied.code, 0, JSON.stringify(applied.document));assert.match(readFileSync(join(box.root, 'SPEC.md'), 'utf8'), /- G1 \[approved, must\] A row the person decides on the passkey\./u, 'the native CLI applies the passkey approval');assert.throws(() => refuseNamedSigners([{ id: 'G2', signers: ['[email protected]'] }], ['G2']), { code: 'PERSON_SIGNER_REQUIRED', message: /G2 names its SSH signers alice@example\.com/u });@@ -1150,7 +1155,7 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(async function confirmTerminal(argv, expectedVerb) {const beforeIds = new Set(JSON.parse(nativeRows('SELECT meta_value FROM board_meta WHERE meta_key=?', 'person_proposals')[0]?.meta_value ?? '[]').map(entry => entry.id));const child = helpers.launch({ ...box, env: { ...cleared, SSH_CONNECTION: '127.0.0.1 40000 127.0.0.1 22' } },- box.root, process.execPath, [CLI, ...argv, '--json']);+ box.root, process.execPath, [...trusted, ...argv, '--json']);try {const proposal = await helpers.waitFor(() => {assert.equal(child.exitCode, null, child.stderrText);@@ -1225,7 +1230,7 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(// Only the passkey turns signing off; unlinking offline keeps it on.const switchedOff = await confirmTerminal(['settings', 'person.signed', 'off'], 'signing');assert.equal(switchedOff.person.signed, false);- assert.equal((await box.cli('status')).document.person.signed, false, 'the passkey turned signing off');+ assert.equal((await cli(box.env, 'status')).document.person.signed, false, 'the passkey turned signing off');assert.equal((await cli(marked, 'settings', 'person.signed', 'on')).code, 0);await box.stopRelay();await cli(cleared, 'relay', 'off');