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.

fix(relay): a stale registry entry never mislabels this worktree [C6]

Corey Olsonde74d23b55c7
diff --git a/src/relay-setup.js b/src/relay-setup.js
index 1d968e5a..888735ce 100644
--- a/src/relay-setup.js
+++ b/src/relay-setup.js
@@ -85,6 +85,18 @@ async function finishApprovedLink(project, pending, source, approval, io) {
return linked;
}
+/**
+ * Read one registered board's link as a possible publisher. Another entry's refusal, such as a
+ * scratch folder that is no longer a git work tree, rules out only that entry: it never speaks
+ * for the board this command runs in.
+ */
+function publisherState(root) {
+ try { return relayMachineContext(root); } catch (error) {
+ if (!(error instanceof Refused)) throw error;
+ return null;
+ }
+}
+
/** Link a new project only after the paired phone explicitly approves its one durable proposal. */
export async function autoLinkProject(root, io) {
const machine = readRelayMachine();
@@ -102,9 +114,11 @@ export async function autoLinkProject(root, io) {
let source;
if (pending) source = relayMachineContext(pending.publisherRoot);
else {
- const candidate = listApiProjects().map(entry => ({ ...entry, state: relayMachineContext(entry.root) }))
+ const candidate = listApiProjects().map(entry => ({ ...entry, state: publisherState(entry.root) }))
.find(entry => entry.state?.token?.startsWith('pm_') && entry.state.account === machine.owner?.account && entry.state.url === machine.owner?.url);
- if (!candidate) throw new Refused('RELAY_SESSION', 'Run pullboard relay on --all to link this project and pair the phone.');
+ // With the relay off no board here can publish the request, so a move prints only its result;
+ // doctor and resume still name each unlinked board.
+ if (!candidate) return;
source = candidate.state;
const proposal = await phoneProposal(source, 'link', repository,
{ board: projectBoard(project), command: 'Link ' + name + '? (pullboard init)', link: true, root: project });
diff --git a/test/relay-setup.test.js b/test/relay-setup.test.js
index 5b4b873c..d6f319fe 100644
--- a/test/relay-setup.test.js
+++ b/test/relay-setup.test.js
@@ -1,7 +1,7 @@
/** The view uses the actual device authorization and all-board linking path without a terminal [H5,N26]. */
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
-import { existsSync, mkdirSync, readFileSync } from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { hostname, tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
@@ -9,7 +9,8 @@ import { test } from 'node:test';
import * as setup from '../src/relay-setup.js';
import { relayClientFixture } from './relay-client-fixture.js';
import { createDeviceKeys, signDeviceEnrollment } from '../src/relay-device-keys.js';
-import { runFixtureChild, startFixtureChild } from './fixture-child.js';
+import { runFixtureChild, runFixtureGit, startFixtureChild } from './fixture-child.js';
+import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
/** Run the public view adapter in a process whose complete home, registry and boards are private. */
async function viewScenario(box, mode) {
@@ -539,3 +540,62 @@ test('relay on --all says who signed in, what it linked and what it waits for [H
assert.ok(statusRequests.length > 0, 'relay status syncs with the relay before it reports');
assert.deepEqual(statusRequests, relayRequests(beforePlain), 'relay status makes the same relay requests as plain relay');
});
+
+/** Run one CLI command in plain words inside a private home, returning its exit code and both streams. */
+function relayOffCommand(cwd, env, args) {
+ const result = runFixtureChild(process.execPath, [CLI, ...args], { cwd, env, encoding: 'utf8' });
+ return { code: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
+}
+
+/** Build a set-up-once machine with the relay off, a board with an agent worktree, and optionally a stale registry entry. */
+function relayOffWorktree(t, { stale }) {
+ const scratch = mkdtempSync(join(tmpdir(), 'pullboard-relay-off-'));
+ t.after(() => rmSync(scratch, { recursive: true, force: true }));
+ const home = join(scratch, 'home');
+ mkdirSync(home, { mode: 0o700 });
+ const env = { ...process.env, HOME: home, PULLBOARD_HOME: join(home, '.pullboard'), PULLBOARD_MACHINE_HOME: join(scratch, 'machine'),
+ GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Relay Fixture', GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Relay Fixture', GIT_COMMITTER_EMAIL: '[email protected]' };
+ for (const name of ['PULLBOARD_RELAY_KEY', 'PULLBOARD_RELAY_TOKEN', ...AGENT_SHELL_MARKERS, ...SSH_SHELL_MARKERS]) delete env[name];
+ /** Make one committed repository with a GitHub origin, registered through the production CLI. */
+ const board = name => {
+ const root = join(scratch, name);
+ mkdirSync(root);
+ for (const args of [['init', '-q', '-b', 'main'], ['-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-q', '-m', 'chore: ' + name],
+ ['remote', 'add', 'origin', '[email protected]:fixture/' + name + '.git']]) runFixtureGit(args, { cwd: root, env });
+ const init = relayOffCommand(root, env, ['init', '--json']);
+ assert.equal(init.code, 0, init.stderr);
+ runFixtureGit(['add', '-A'], { cwd: root, env });
+ runFixtureGit(['-c', 'commit.gpgsign=false', 'commit', '-q', '--no-verify', '-m', 'chore: pullboard files'], { cwd: root, env });
+ return root;
+ };
+ const root = board('repo');
+ if (stale) {
+ // A registered folder that is no longer a git work tree, like a deleted scratch clone.
+ const gone = board('stale-scratch');
+ rmSync(join(gone, '.git'), { recursive: true, force: true });
+ }
+ // Set up once, then the relay is off: auto-link stays on for the owner, and no board on this machine is linked.
+ const machine = JSON.stringify(pathToFileURL(resolve(import.meta.dirname, '../src/relay-machine.js')).href);
+ const saved = runFixtureChild(process.execPath, ['--input-type=module', '-e',
+ `import { updateRelayMachine } from ${machine}; updateRelayMachine(state => { state.autoLink = true; state.owner = { account: 'fixture-account', url: 'http://127.0.0.1:9' }; });`],
+ { cwd: root, env, encoding: 'utf8' });
+ assert.equal(saved.status, 0, saved.stderr);
+ const worktree = join(scratch, 'repo-core-1');
+ runFixtureGit(['worktree', 'add', '-q', '-b', 'core/1', worktree], { cwd: root, env });
+ const joined = relayOffCommand(worktree, env, ['join', 'review', '--model', 'fixture-model']);
+ assert.equal(joined.code, 0, joined.stderr);
+ return { worktree, env };
+}
+
+test('a move from an agent worktree prints no relay-link line [C6,H5]', (t) => {
+ for (const stale of [true, false]) {
+ const { worktree, env } = relayOffWorktree(t, { stale });
+ const move = relayOffCommand(worktree, env, ['spec', 'draft', 'A fixture row', '--section', 'G']);
+ const label = stale ? 'with a stale registry entry' : 'the control with no stale entry';
+ assert.equal(move.code, 0, `the move succeeds ${label}: ${move.stderr}`);
+ assert.doesNotMatch(move.stdout + move.stderr, /not linked|NOT_A_REPO|not inside a git work tree/u, `the move prints only its result ${label}`);
+ assert.equal(move.stderr, '', `the move writes nothing to stderr ${label}`);
+ }
+});