Skip to content

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.

5.1 KB
Raw Blame
/** Real local-only initialization, relay opt-in and landing proof [I1,B3,R3,H5]. */
import assert from 'node:assert/strict';
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { runFixtureChild } from './fixture-child.js';

/** Preserve every independent observable failure so the prefeature control proves both paths. */
export function assertNoRemoteLanding(sandbox, commitFile) {
  const box = sandbox();
  const repo = join(box.dir, 'local-repo');
  mkdirSync(repo);
  box.git(repo, 'init', '-q', '-b', 'main');
  const initialized = box.run(repo, 'init');
  assert.equal(initialized.code, 0, initialized.err);
  const configFile = join(repo, 'pullboard.json');
  const original = JSON.parse(readFileSync(configFile, 'utf8'));
  const failures = [];
  /** Collect assertions only; setup or execution exceptions remain fatal. */
  const observe = (check) => { try { check(); } catch (error) { if (error.code !== 'ERR_ASSERTION') throw error; failures.push(error.message); } };
  observe(() => assert.equal(original.landing?.publish, 'separate', 'init chooses local-first landing without any remote'));
  writeFileSync(configFile, JSON.stringify({ ...original, gate: 'true', verify: 'any', lanes: { web: { owns: ['web/'], specs: ['G1'] } } }, null, 2));
  writeFileSync(join(repo, 'SPEC.md'), '# Local fixture\n\n## Goals\n- G1 [approved, must] The local result exists. | gate: true\n');
  box.git(repo, 'add', '-A');
  box.git(repo, 'commit', '-q', '-m', 'chore: configure local landing');
  const added = box.run(repo, 'add', 'web', 'Local result', '--specs', 'G1', '--criterion', 'The result exists.', '--check', 'test -f web/result.txt', '--wait', '--json');
  assert.equal(added.code, 0, added.err);
  const item = JSON.parse(added.out).item.item_id;
  const made = box.run(repo, 'worktree', 'web', '--model', 'local-builder', '--json');
  assert.equal(made.code, 0, made.err);
  const builder = JSON.parse(made.out).path;
  assert.equal(box.run(builder, 'claim', String(item)).code, 0);
  const committed = commitFile(box, builder, 'web/result.txt', 'local result\n', 'feat(web): local result [G1]');
  assert.equal(committed.status, 0, committed.stderr);
  const submitted = box.run(builder, 'submit', String(item), '--json');
  assert.equal(submitted.code, 0, submitted.err);
  const head = JSON.parse(submitted.out).commit;
  box.git(repo, 'switch', '-q', '--detach', head);
  try { assert.equal(box.run(repo, 'verify', String(item), 'accept', '--as', 'coordinator', '--note', 'The actual local result exists.').code, 0); }
  finally { box.git(repo, 'switch', '-q', 'main'); }

  const machine = new URL('../src/relay-machine.js', import.meta.url).href;
  const enabled = runFixtureChild(process.execPath, ['--input-type=module', '-e', `import { updateRelayMachine } from ${JSON.stringify(machine)}; updateRelayMachine(state => { state.autoLink = true; });`], { cwd: repo, env: box.env, encoding: 'utf8' });
  assert.equal(enabled.status, 0, enabled.stderr);
  const status = box.run(repo, 'status');
  observe(() => assert.equal(status.code, 0, status.err));
  observe(() => assert.doesNotMatch(status.err + status.out, /not linked:|\[RELAY_(?:ORIGIN|SESSION)\]/u, 'an inherited link-all never turns local status into a relay refusal'));
  observe(() => assert.match(status.out, /optional:.*relay on/u, 'status offers linking as an optional next step'));
  const explicit = box.run(repo, 'relay', 'on', '--json');
  observe(() => assert.equal(explicit.code, 1, 'an explicit link still requires a GitHub origin'));
  observe(() => assert.match(explicit.out + explicit.err, /RELAY_ORIGIN/u));
  const landed = box.run(repo, 'land', '--json');
  observe(() => assert.equal(landed.code, 0, landed.err));
  if (landed.code === 0) {
    const receipt = JSON.parse(landed.out);
    observe(() => assert.deepEqual(receipt.landed, [item]));
    observe(() => assert.equal(receipt.batch.state, 'landed'));
    observe(() => assert.equal(box.git(repo, 'rev-parse', 'main'), receipt.batch.tip));
    const recorded = JSON.parse(box.run(repo, 'show', String(item), '--json').out);
    observe(() => assert.equal(recorded.item_merged_commit, receipt.batch.tip, 'normal land records the merge; no manual merged command'));
    observe(() => assert.equal(readFileSync(join(repo, 'web/result.txt'), 'utf8'), 'local result\n'));
  }
  assert.equal(box.git(repo, 'remote'), '', 'the whole workflow retains no remote');
  for (const origin of ['https://github.com/example/local-proof.git', join(box.dir, 'private-origin.git')]) {
    const remoteRepo = join(box.dir, origin.startsWith('https:') ? 'github-repo' : 'bare-repo');
    mkdirSync(remoteRepo);
    box.git(remoteRepo, 'init', '-q', '-b', 'main');
    box.git(remoteRepo, 'remote', 'add', 'origin', origin);
    assert.equal(box.run(remoteRepo, 'init').code, 0);
    const withRemote = JSON.parse(readFileSync(join(remoteRepo, 'pullboard.json'), 'utf8'));
    observe(() => assert.equal(withRemote.landing, undefined, 'a configured remote keeps the existing push-and-land default'));
    observe(() => assert.equal(box.git(remoteRepo, 'remote', 'get-url', 'origin'), origin));
  }
  assert.deepEqual(failures, [], failures.join('\n'));
}