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(gate): rebase submit checks onto split suite [V4,C7]
Corey Olson5063f7ac1f8a
diff --cc test/e2e-helpers.jsindex 00000000,95924f46..2a0ec8b9mode 000000,100644..100644--- a/test/e2e-helpers.js+++ b/test/e2e-helpers.js@@@ -1,0 -1,263 +1,272 @@@+ import assert from 'node:assert/strict';+ import { execFileSync, spawn, spawnSync } from 'node:child_process';+ import {+ chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync,+ rmSync, statSync, symlinkSync, writeFileSync,+ } from 'node:fs';+ import { tmpdir } from 'node:os';+ import { request } from 'node:http';+ import { connect } from 'node:net';+ import { join, resolve } from 'node:path';++import * as store from '../src/board.js';+ import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';++ /** Create isolated real-repository helpers for one parallel end-to-end test file. */+ export function createE2eHelpers() {+ const sandboxes = [];+ /** Remove this test file's fixtures after its tests finish. */+ const cleanup = () => {+ for (const dir of sandboxes) rmSync(dir, { recursive: true, force: true });+ };+ const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+ const cockpitSource = () => readFileSync(resolve(import.meta.dirname, '../src/cockpit.js'), 'utf8');+ /**+ * A scratch directory with a `pullboard` shim on the PATH, so the hooks git runs find the CLI, and+ * git isolated from the machine's own config.+ */+ function sandbox() {+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-e2e-')));+ sandboxes.push(dir);+ const shims = join(dir, 'bin');+ mkdirSync(shims);+ writeFileSync(join(shims, 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${BIN}" "$@"\n`);+ chmodSync(join(shims, 'pullboard'), 0o755);+ const env = {+ ...process.env,+ PATH: `${shims}:${process.env.PATH}`,+ GIT_CONFIG_GLOBAL: '/dev/null',+ GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'Test Agent',+ GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'Test Agent',+ GIT_COMMITTER_EMAIL: '[email protected]',+ PULLBOARD_HOME: join(dir, 'pullboard-home'),+ PULLBOARD_MACHINE_HOME: join(dir, 'machine-home'),+ };+ for (const marker of [...AGENT_SHELL_MARKERS, ...SSH_SHELL_MARKERS]) delete env[marker];+ delete env.PULLBOARD_RELAY_TOKEN;+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();+ const tryGit = (cwd, ...args) => spawnSync('git', args, { cwd, env, encoding: 'utf8' });+ const run = (cwd, ...args) => {+ const result = spawnSync(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8' });+ return { code: result.status, out: result.stdout, err: result.stderr };+ };+ return { dir, env, git, tryGit, run };+ }++ const CONFIG = {+ gate: 'test ! -f RED',+ spec: 'SPEC.md',+ verify: 'any',+ lease: '2h',+ lanes: { web: { owns: ['web/'], specs: ['G1'] }, api: { owns: ['api/'], specs: ['G2'] } },+ shared: ['docs/'],+ };++ const SPEC = `# Demo spec++ ## G · Goals+ - G1 [approved, must] The page renders. | gate: web test+ - G2 [approved, must] The API answers. | gate: api test+ `;++ /**+ * A repo set up with pullboard, two lanes and a spec, committed through its own hooks, plus a+ * worktree joined to the web lane.+ */+ function project(gate = CONFIG.gate, box = sandbox()) {+ const repo = join(box.dir, 'repo');+ mkdirSync(repo);+ box.git(repo, 'init', '-q', '-b', 'main');+ assert.equal(box.run(repo, 'init').code, 0);+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ ...CONFIG, gate }, null, 2));+ writeFileSync(join(repo, 'SPEC.md'), SPEC);+ box.git(repo, 'add', '-A');+ box.git(repo, 'commit', '-q', '-m', 'chore: set up pullboard');+ const web = join(box.dir, 'web-1');+ box.git(repo, 'worktree', 'add', '-q', web, '-b', 'web/one');+ assert.match(box.run(web, 'join', 'web').out, /joined as web-1/);+ return { ...box, repo, web };+ }++ /** Create a private gate that waits only after the test arms it. */+ function holdingGate(box) {+ const script = join(box.dir, 'holding-gate.cjs');+ const mode = join(box.dir, 'hold-gate');+ const release = join(box.dir, 'release-gate');+ const events = join(box.dir, 'gate-events.log');+ writeFileSync(script, [+ "const fs = require('node:fs');",+ 'const [armed, release, events] = process.argv.slice(2);',+ 'if (!fs.existsSync(armed)) process.exit(0);',+ "fs.appendFileSync(events, 'start\\n');",+ 'const deadline = Date.now() + 15000;',+ 'while (!fs.existsSync(release) && Date.now() < deadline) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);',+ 'if (!fs.existsSync(release)) process.exit(23);',+ "fs.appendFileSync(events, 'end\\n');",+ ].join('\n'));+ const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;+ return { command: `node ${quote(script)} ${quote(mode)} ${quote(release)} ${quote(events)}`, mode, release, events };+ }++ /** Launch a CLI or Git process while preserving its output for the gate-lock assertion. */+ function launch(box, cwd, command, args) {+ const child = spawn(command, args, { cwd, env: box.env, stdio: ['ignore', 'pipe', 'pipe'] });+ child.stdoutText = '';+ child.stderrText = '';+ child.stdout.setEncoding('utf8').on('data', (chunk) => { child.stdoutText += chunk; });+ child.stderr.setEncoding('utf8').on('data', (chunk) => { child.stderrText += chunk; });+ child.closed = new Promise((resolveClose) => child.once('close', (code, signal) => resolveClose({ code, signal })));+ return child;+ }++ /** Wait for a private fixture observation with a bounded failure time. */+ async function waitFor(predicate, description, timeoutMs = 8_000) {+ const deadline = Date.now() + timeoutMs;+ while (Date.now() < deadline) {+ const value = predicate();+ if (value) return value;+ await new Promise((resolvePromise) => setTimeout(resolvePromise, 20));+ }+ throw new Error(`timed out waiting for ${description}`);+ }++ /** Read the private gate event sequence without exposing arbitrary gate output. */+ function gateEvents(gate) {+ return existsSync(gate.events) ? readFileSync(gate.events, 'utf8').trim().split(/\r?\n/u).filter(Boolean) : [];+ }++ /**+ * Write a file in a worktree and commit it, returning git's result so a refusal can be read.+ */+ function commitFile(box, cwd, path, text, message) {+ mkdirSync(join(cwd, path, '..'), { recursive: true });+ writeFileSync(join(cwd, path), text);+ box.git(cwd, 'add', '-A');+ return box.tryGit(cwd, 'commit', '-q', '-m', message);+ }++ const LIGHT_BRIEF = 'Files:\n- web/page.js\nChange:\n- copy the header from the api\nTest:\n- the page test asserts the header\nOut of scope: anything else\n';++ async function startView(box, cwd) {+ const child = spawn(process.execPath, [BIN, 'view', '--no-open'], { cwd, env: box.env });+ const link = await new Promise((found, fail) => {+ let out = '';+ child.stdout.on('data', (chunk) => {+ out += chunk;+ const match = /Pullboard view: (http:\/\/127\.0\.0\.1:\d+\/\?k=\S+)/.exec(out);+ if (match) found(new URL(match[1]));+ });+ child.on('exit', (code) => fail(new Error(`view exited ${code}: ${out}`)));+ });+ const key = link.searchParams.get('k');+ const base = `http://127.0.0.1:${link.port}`;+ const headers = { 'x-pullboard-key': key };+ /**+ * Fetch the page through either the accepted printed-key response or the cookie exchange.+ * Keeping these paths in one fixture lets the API assertions stay independent of page auth.+ */+ const page = async () => {+ const response = await fetch(link, { redirect: 'manual' });+ if (response.status === 200) return response;+ assert.equal(response.status, 303, 'the printed link either serves the legacy page or exchanges its key');++ const rawLocation = response.headers.get('location');+ assert.ok(rawLocation, 'the cookie exchange has a redirect target');+ const location = new URL(rawLocation, base);+ assert.equal(location.origin, new URL(base).origin, 'the cookie exchange stays on this view origin');+ assert.equal(location.pathname, '/', 'the cookie exchange returns to the clean page path');+ assert.equal(location.search, '', 'the redirect does not keep credentials in the address');+ assert.equal(location.hash, '', 'the redirect has no credential-bearing fragment');++ const cookies = response.headers.getSetCookie?.() ?? [response.headers.get('set-cookie')].filter(Boolean);+ assert.equal(cookies.length, 1, 'the exchange sets one session cookie');+ const [pair, ...attributes] = cookies[0].split(';').map((part) => part.trim());+ assert.match(pair, /^[A-Za-z0-9_-]+=[A-Za-z0-9._~-]+$/u, 'the session cookie has a valid nonempty name and value');+ assert.ok(attributes.some((attribute) => /^httponly$/iu.test(attribute)), 'the session cookie is HttpOnly');+ assert.ok(attributes.some((attribute) => /^samesite=strict$/iu.test(attribute)), 'the session cookie is SameSite=Strict');+ assert.ok(attributes.some((attribute) => /^path=\/$/iu.test(attribute)), 'the session cookie is scoped to the view');++ const pageResponse = await fetch(location, { headers: { cookie: pair }, redirect: 'manual' });+ assert.equal(pageResponse.status, 200, 'the cookie jar fetches the page after the exchange');+ return pageResponse;+ };+ /** Read the public listing through the view's real authenticated API. */+ const boards = async () => {+ const response = await fetch(`${base}/api/v1/boards`, { headers });+ return { status: response.status, document: await response.json() };+ };+ /** Resolve a registered board id and read its public state. */+ const state = async (root) => {+ const listing = await boards();+ if (listing.status !== 200) return listing;+ const board = listing.document.boards.find((entry) => entry.root === root);+ if (!board) return { ...listing.document, project: null };+ const response = await fetch(`${base}/api/v1/boards/${encodeURIComponent(board.id)}/state`, { headers });+ return { ...listing.document, project: (await response.json()).state };+ };+ /** Send a public move to the registered board or a deliberately unknown id. */+ const act = async (root, body) => {+ const listing = await boards();+ const board = listing.document.boards?.find((entry) => entry.root === root);+ const id = board?.id ?? '0'.repeat(32);+ const response = await fetch(`${base}/api/v1/boards/${encodeURIComponent(id)}/moves`, {+ method: 'POST',+ headers: { ...headers, 'content-type': 'application/json' },+ body: JSON.stringify(body),+ });+ return { status: response.status, document: await response.json() };+ };+ const stop = () => new Promise((done) => {+ if (child.exitCode !== null || child.signalCode !== null) return done();+ child.once('exit', done);+ child.kill('SIGTERM');+ });+ return { link, key, base, page, state, act, stop };+ }++ function attackCommit(box, cwd) {+ box.git(cwd, 'add', '-A');+ const tree = box.git(cwd, 'write-tree');+ const commit = box.git(cwd, 'commit-tree', tree, '-p', 'HEAD', '-m', 'feat(web): adversarial fixture [G1]');+ box.git(cwd, 'update-ref', 'HEAD', commit);+ return commit;+ }+-/** Submit a fixture whose private check reads an ignored dependency folder. */++/** Seed a legacy receipt from the old full-gate-only submit rule, for independent verifier audits. */++function historicalCheckSubmission(box, commit) {++ box.git(box.web, 'update-ref', `refs/pullboard/items/1/${commit.slice(0, 12)}`, commit);++ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));++ try { store.submit(board, 1, { agentId: 'web-1', commit, tree: box.git(box.web, 'rev-parse', `${commit}^{tree}`) }); }++ finally { store.closeBoard(board); }++}++++/** Retain historical submissions whose private check needs an install, fails, or times out. */+ function privateCheckSubmission({ install = '', timeout = '5m', check }) {+ const box = project('true');+ const config = JSON.parse(readFileSync(join(box.repo, 'pullboard.json'), 'utf8'));+ config.check = { install, timeout };+ writeFileSync(join(box.repo, 'pullboard.json'), JSON.stringify(config, null, 2));+ box.git(box.repo, 'add', 'pullboard.json');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: configure private check fixture');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ assert.equal(box.run(box.repo, 'add', 'web', 'Private check', '--specs', 'G1', '--criterion', 'the installed check passes', '--check', check).code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/.gitignore'), '.deps/\n');+ writeFileSync(join(box.web, 'web/index.html'), 'fixture');+ const commit = attackCommit(box, box.web);- assert.equal(box.run(box.web, 'submit', '1').code, 0);++ historicalCheckSubmission(box, commit);+ const review = join(box.dir, 'private-check-review');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, commit);+ assert.equal(box.run(review, 'join', 'api').code, 0);+ return { ...box, review, commit };+ }+++ return {+ BIN, cockpitSource, sandboxes, cleanup, sandbox, CONFIG, SPEC, project,- holdingGate, launch, waitFor, gateEvents, commitFile, attackCommit, privateCheckSubmission,++ holdingGate, launch, waitFor, gateEvents, commitFile, attackCommit, historicalCheckSubmission, privateCheckSubmission,+ startView, LIGHT_BRIEF,+ };+ }diff --cc test/e2e-policy.test.jsindex 00000000,ef4ff29b..e83d0be8mode 000000,100644..100644--- a/test/e2e-policy.test.js+++ b/test/e2e-policy.test.js@@@ -1,0 -1,251 +1,254 @@@+ /**+ * End to end on real repos: the CLI runs as its own process, git runs the installed hooks, and+ * worktrees are real worktrees (B1–B3, B6, V3, V4, V7, L3, L4, C3, I1, I2, P2).+ */+ import assert from 'node:assert/strict';+ import { execFileSync, spawn, spawnSync } from 'node:child_process';+ import {+ chmodSync,+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ realpathSync,+ rmSync,+ statSync,+ symlinkSync,+ writeFileSync,+ } from 'node:fs';+ import { tmpdir } from 'node:os';+ import { request } from 'node:http';+ import { connect } from 'node:net';+ import { join, resolve } from 'node:path';+ import { after, test } from 'node:test';+ import { parseSpec } from '../src/spec.js';+ import { checkAtCommit } from '../src/trusted-policy.js';+ import * as store from '../src/board.js';++ import { createE2eHelpers } from './e2e-helpers.js';+ const e2e = createE2eHelpers();+ after(e2e.cleanup);+ const {+ BIN, cockpitSource, sandboxes, sandbox, CONFIG, SPEC, project, holdingGate,- launch, waitFor, gateEvents, commitFile, attackCommit, privateCheckSubmission,++ launch, waitFor, gateEvents, commitFile, attackCommit, historicalCheckSubmission, privateCheckSubmission,+ startView, LIGHT_BRIEF,+ } = e2e;++ test('the blind gate-bypass repro refuses submit and accept, and doctor audits pre-merge policy [V4,V16,L3,M3]', () => {+ const box = project('true');+ assert.equal(box.run(box.repo, 'add', 'web', 'Append notes', '--specs', 'G1', '--criterion', 'append one note', '--check', 'test ! -f web/RED_CHECK').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ const original = JSON.parse(box.run(box.web, 'show', '1', '--json').out);+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/RED_CHECK'), 'red');+ const config = JSON.parse(readFileSync(join(box.web, 'pullboard.json'), 'utf8'));+ config.gate = 'true';+ config.lanes.web.owns.push('pullboard.json');+ writeFileSync(join(box.web, 'pullboard.json'), JSON.stringify(config));+ const commit = attackCommit(box, box.web);+ const submitted = box.run(box.web, 'submit', '1', '--json');+ assert.equal(submitted.code, 1);+ assert.equal(JSON.parse(submitted.out).error.code, 'OUTSIDE_LANE');+ assert.equal(JSON.parse(submitted.out).error.message.includes('pullboard.json'), true);+ assert.equal(box.run(box.web, 'check', '1').code, 1, 'the original item check stays red');++ // Model a historical unchecked receipt using the low-level engine in this private fixture.+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));+ try { store.submit(board, 1, { agentId: 'web-1', commit, tree: box.git(box.web, 'rev-parse', 'HEAD^{tree}'), policyCommit: original.item_claim_head }); }+ finally { store.closeBoard(board); }+ box.git(box.repo, 'update-ref', 'refs/pullboard/items/1/' + commit.slice(0, 12), commit);+ const review = join(box.dir, 'review');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, commit);+ assert.equal(box.run(review, 'join', 'api').code, 0);+ const accepted = box.run(review, 'verify', '1', 'accept', '--note', 'private repro', '--json');+ assert.equal(accepted.code, 1);+ assert.equal(JSON.parse(accepted.out).error.code, 'CHECK_RED');+ assert.equal(JSON.parse(box.run(review, 'show', '1', '--json').out).item_status, 'submitted');++ const history = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));+ try { store.verify(history, 1, { agentId: 'api-1', decision: 'ACCEPT', note: 'synthetic historical unchecked verdict', head: commit, digest: original.item_frozen_digest, policy: 'any' }); }+ finally { store.closeBoard(history); }+ box.git(box.repo, 'merge', '--ff-only', '-q', 'web/one');+ assert.equal(box.run(box.repo, 'merged', '1', commit).code, 0);+ const file = join(box.repo, '.git/pullboard/board.sqlite');+ const before = readFileSync(file);+ const doctor = box.run(box.repo, 'doctor', '--json');+ assert.equal(doctor.code, 1);+ const problems = JSON.parse(doctor.out).problems;+ assert.equal(problems.some(problem => problem.code === 'OUTSIDE_LANE' && problem.message.includes('pullboard.json')), true,+ 'post-merge HEAD cannot retrospectively authorize the malicious policy edit');+ assert.equal(problems.some(problem => problem.code === 'CHECK_RED'), true);+ assert.deepEqual(readFileSync(file), before, 'doctor keeps the historical evidence unchanged');+ });++ test('a shared config edit cannot replace the gate frozen from the coordinator [V4,V16]', () => {+ const box = project('test ! -f web/RED');+ const config = JSON.parse(readFileSync(join(box.repo, 'pullboard.json'), 'utf8'));+ config.shared.push('pullboard.json');+ writeFileSync(join(box.repo, 'pullboard.json'), JSON.stringify(config));+ box.git(box.repo, 'add', 'pullboard.json');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: share fixture config');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ assert.equal(box.run(box.repo, 'add', 'web', 'Frozen gate', '--specs', 'G1', '--criterion', 'original gate passes').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/RED'), 'red');+ config.gate = 'true';+ writeFileSync(join(box.web, 'pullboard.json'), JSON.stringify(config));+ box.git(box.web, 'add', '-A');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): fixture config change [G1]');+ const refused = box.run(box.web, 'submit', '1', '--json');+ assert.equal(refused.code, 1);+ assert.equal(JSON.parse(refused.out).error.code, 'GATE_RED', 'the committed original gate executes even though the candidate says true');+ });++ test('accepted-main merges carry foreign files without granting permission to alter them [L3,V4]', () => {+ const box = project('true');+ assert.equal(box.run(box.repo, 'add', 'web', 'Main merge', '--specs', 'G1', '--criterion', 'foreign main object preserved').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ writeFileSync(join(box.repo, 'coordinator.txt'), 'accepted main fixture');+ box.git(box.repo, 'add', 'coordinator.txt');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: coordinator fixture');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/index.html'), 'app fixture');+ box.git(box.web, 'add', 'web/index.html');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): preserve main fixture [G1]');+ assert.equal(box.run(box.web, 'submit', '1').code, 0, 'unchanged accepted-main foreign objects are allowed');+ const commit = box.git(box.web, 'rev-parse', 'HEAD');+ box.git(box.repo, 'merge', '-q', '--ff-only', 'web/one');+ assert.equal(box.run(box.repo, 'verify', '1', 'accept', '--as', 'coordinator', '--note', 'private accepted-main fixture').code, 0);+ assert.equal(box.run(box.repo, 'doctor').code, 0, 'the pre-merge main proof remains available for historical audit');+ assert.equal(box.run(box.repo, 'add', 'web', 'Alter foreign file', '--specs', 'G1', '--criterion', 'ownership remains enforced').code, 0);+ assert.equal(box.run(box.web, 'claim', '2').code, 0);+ writeFileSync(join(box.web, 'coordinator.txt'), 'unauthorized replacement');+ attackCommit(box, box.web);+ const refused = box.run(box.web, 'submit', '2', '--json');+ assert.equal(refused.code, 1);+ assert.equal(JSON.parse(refused.out).error.code, 'OUTSIDE_LANE');+ });++ test('foreign changes before claiming and cross-lane renames cannot hide from submit [L3,V4]', () => {+ for (const mode of ['before-claim', 'rename', 'delete']) {+ const box = project('true');+ writeFileSync(join(box.repo, 'foreign file.txt'), 'coordinator-owned');+ box.git(box.repo, 'add', '-A');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: foreign fixture');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ assert.equal(box.run(box.repo, 'add', 'web', mode, '--specs', 'G1').code, 0);+ if (mode === 'before-claim') {+ writeFileSync(join(box.web, 'foreign file.txt'), 'unauthorized pre-claim replacement');+ attackCommit(box, box.web);+ }+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ mkdirSync(join(box.web, 'web'));+ if (mode === 'rename') box.git(box.web, 'mv', 'foreign file.txt', 'web/moved.txt');+ else if (mode === 'delete') box.git(box.web, 'rm', 'foreign file.txt');+ writeFileSync(join(box.web, 'web/index.html'), 'owned');+ attackCommit(box, box.web);+ const refused = box.run(box.web, 'submit', '1', '--json');+ assert.equal(refused.code, 1, mode);+ assert.equal(JSON.parse(refused.out).error.code, 'OUTSIDE_LANE', mode);+ assert.equal(JSON.parse(refused.out).error.message.includes('foreign file.txt'), true, mode);+ }+ });++ test('accept reruns the frozen check at the submission even when the reviewer repaired its HEAD [V4,M3]', () => {+ const box = project('true');+ assert.equal(box.run(box.repo, 'add', 'web', 'Exact check', '--specs', 'G1', '--check', 'test ! -f web/RED_CHECK').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/RED_CHECK'), 'red');+ const commit = attackCommit(box, box.web);- assert.equal(box.run(box.web, 'submit', '1').code, 0, 'the project gate passes while the separate item check is red');++ const blocked = box.run(box.web, 'submit', '1');++ assert.equal(blocked.code, 1, 'current submit refuses the red frozen check even when the project gate passes');++ assert.match(blocked.err, /GATE_RED/);++ historicalCheckSubmission(box, commit); // Legacy receipts must still be independently checked.+ const review = join(box.dir, 'exact-review');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, commit);+ assert.equal(box.run(review, 'join', 'api').code, 0);+ box.git(review, 'rm', 'web/RED_CHECK');+ attackCommit(box, review); // Model the adversarial repair without disabling its lane hook.+ assert.equal(box.run(review, 'check', '1', '--yes').code, 0, 'the reviewer HEAD alone is green');+ const refused = box.run(review, 'verify', '1', 'accept', '--note', 'reviewer repair is not submission proof', '--json');+ assert.equal(refused.code, 1);+ assert.equal(JSON.parse(refused.out).error.code, 'CHECK_RED');+ assert.equal(JSON.parse(box.run(review, 'show', '1', '--json').out).item_status, 'submitted');+ });++ test('accept independently refuses a historically unchecked foreign submission [L3,M3]', () => {+ const box = project('true');+ assert.equal(box.run(box.repo, 'add', 'web', 'Foreign receipt', '--specs', 'G1', '--check', 'true').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ writeFileSync(join(box.web, 'coordinator.txt'), 'unauthorized');+ const commit = attackCommit(box, box.web);+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));+ try { store.submit(board, 1, { agentId: 'web-1', commit, tree: box.git(box.web, 'rev-parse', 'HEAD^{tree}') }); }+ finally { store.closeBoard(board); }+ const review = join(box.dir, 'foreign-review');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, commit);+ assert.equal(box.run(review, 'join', 'api').code, 0);+ const refused = box.run(review, 'verify', '1', 'accept', '--note', 'a green check cannot authorize this path', '--json');+ assert.equal(refused.code, 1);+ assert.equal(JSON.parse(refused.out).error.code, 'OUTSIDE_LANE');+ });++ test('replacement refs cannot conceal the real submitted foreign paths [L3,V4,M3]', () => {+ const box = project('true');+ assert.equal(box.run(box.repo, 'add', 'web', 'Replacement probe', '--specs', 'G1', '--check', 'true').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ const base = box.git(box.web, 'rev-parse', 'HEAD');+ writeFileSync(join(box.web, 'coordinator.txt'), 'underlying unauthorized object');+ const commit = attackCommit(box, box.web);+ box.git(box.web, 'replace', commit, base);+ box.git(box.web, 'reset', '--hard', 'HEAD');+ assert.equal(existsSync(join(box.web, 'coordinator.txt')), false, 'Git normally shows the replacement tree');+ const submitted = box.run(box.web, 'submit', '1', '--json');+ assert.equal(submitted.code, 1);+ assert.equal(JSON.parse(submitted.out).error.code, 'OUTSIDE_LANE');+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));+ try { store.submit(board, 1, { agentId: 'web-1', commit, tree: 'synthetic unchecked tree' }); }+ finally { store.closeBoard(board); }+ const review = join(box.dir, 'replacement-review');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', review, commit);+ assert.equal(box.run(review, 'join', 'api').code, 0);+ const accepted = box.run(review, 'verify', '1', 'accept', '--note', 'the replacement is not the pinned object', '--json');+ assert.equal(accepted.code, 1);+ assert.equal(JSON.parse(accepted.out).error.code, 'OUTSIDE_LANE');+ });++ test('replacement refs cannot turn a red committed owned tree into a clean green submission [V4,V16]', () => {+ const box = project('test ! -f web/RED');+ assert.equal(box.run(box.repo, 'add', 'web', 'Exact red tree', '--specs', 'G1').code, 0);+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ const base = box.git(box.web, 'rev-parse', 'HEAD');+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web/RED'), 'committed red');+ const commit = attackCommit(box, box.web);+ box.git(box.web, 'replace', commit, base);+ box.git(box.web, 'reset', '--hard', 'HEAD');+ assert.equal(existsSync(join(box.web, 'web/RED')), false, 'ordinary Git hides the failing committed file');+ const submitted = box.run(box.web, 'submit', '1', '--json');+ assert.equal(submitted.code, 1);+ assert.equal(JSON.parse(submitted.out).error.code, 'DIRTY', 'the underlying tree differs from the files the gate would execute');+ });++ test('a detached coordinator review cannot become a new claim policy [V4,V16]', () => {+ const box = project('test ! -f web/RED');+ assert.equal(box.run(box.repo, 'add', 'web', 'Detached policy', '--specs', 'G1').code, 0);+ const config = JSON.parse(readFileSync(join(box.web, 'pullboard.json'), 'utf8'));+ config.gate = 'true';+ config.lanes.web.owns.push('pullboard.json');+ writeFileSync(join(box.web, 'pullboard.json'), JSON.stringify(config));+ const candidate = attackCommit(box, box.web);+ box.git(box.repo, 'switch', '-q', '--detach', candidate);+ const refused = box.run(box.web, 'claim', '1', '--json');+ assert.equal(refused.code, 1);+ assert.equal(JSON.parse(refused.out).error.code, 'NO_POLICY');+ assert.match(JSON.parse(refused.out).error.message, /return to its main branch/);+ box.git(box.repo, 'switch', '-q', 'main');+ assert.equal(box.run(box.web, 'claim', '1').code, 0);+ const submitted = box.run(box.web, 'submit', '1', '--json');+ assert.equal(submitted.code, 1);+ assert.equal(JSON.parse(submitted.out).error.code, 'OUTSIDE_LANE');+ });