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(api): the roadmap watch reads the machine registry [A2,N26]

Corey Olsonb0196b6eee1a
diff --git a/src/api.js b/src/api.js
index c02c96a1..62ff812d 100644
--- a/src/api.js
+++ b/src/api.js
@@ -72,14 +72,14 @@ function localRevisionInputs(board, now) {
}
/** Capture the inexpensive inputs that can invalidate a complete board-state snapshot. */
-function boardStateRevision(root, id, isMain, projects) {
+function boardStateRevision(root, id, isMain) {
const info = repoInfo(root);
const config = loadConfig(info.root);
const files = stateFileInputs(info.root, config).map(fileRevision);
const local = withBoard(info.root, (board) => {
const inputs = localRevisionInputs(board, board.clock.now().toISOString());
const hasExternalMilestones = inputs.milestones.some((milestone) => milestone.items.some((item) => typeof item !== 'number'));
- return { ...inputs, externalMilestones: hasExternalMilestones ? milestoneRoadmap(info.root, board, projects) : null };
+ return { ...inputs, externalMilestones: hasExternalMilestones ? milestoneRoadmap(info.root, board) : null };
}, isMain);
const revision = stateRevision({
identity: [info.commonDir, id],
@@ -138,9 +138,11 @@ function headFileRevision(info) {
}
}
-/** Read default registry names without listApiProjects' pruning or metadata writes. */
-function watcherProjects(projects) {
- if (projects !== listApiProjects) return projects();
+/**
+ * Read the machine registry that milestoneRoadmap resolves against, without listApiProjects' pruning
+ * or metadata writes: a poll must not rewrite the registry it watches.
+ */
+function registeredProjects() {
try {
const value = JSON.parse(readFileSync(registryFile(), 'utf8'));
if (!Array.isArray(value.projects)) return [];
@@ -155,9 +157,9 @@ function watcherProjects(projects) {
}
/** Open only boards named by this board's external milestone references. */
-function openRoadmapInputs(root, milestones, projects, localDb) {
+function openRoadmapInputs(root, milestones, localDb) {
const references = milestones.flatMap((milestone) => milestone.items.filter((item) => typeof item !== 'number'));
- const registered = references.length ? watcherProjects(projects) : [];
+ const registered = references.length ? registeredProjects() : [];
const opened = new Map();
const pathMarkers = new Map();
const watchPath = (path) => {
@@ -220,7 +222,7 @@ function openRoadmapInputs(root, milestones, projects, localDb) {
}
/** Watch the same named state inputs as the cache without rebuilding a board-state response. */
-function watchLocalStateRevision(board, projects) {
+function watchLocalStateRevision(board) {
const info = repoInfo(board.root);
const config = loadConfig(info.root);
let files = stateFileInputs(info.root, config);
@@ -258,7 +260,7 @@ function watchLocalStateRevision(board, projects) {
const registryChanged = registryMarker !== currentRegistryMarker;
if (!external || JSON.stringify(externalReferences) !== JSON.stringify(references) || registryChanged || external.needsRefresh()) {
external?.close();
- external = openRoadmapInputs(info.root, milestoneDefinitions, projects, db);
+ external = openRoadmapInputs(info.root, milestoneDefinitions, db);
externalVersion = new Map();
externalValues = null;
externalNextExpiry = null;
@@ -550,11 +552,11 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =
const stateCache = new Map();
/** Return the current state and its cached-static JSON representation under revision checks. */
function localState(board, seen) {
- const before = boardStateRevision(board.root, board.id, codeIsMain, projects);
+ const before = boardStateRevision(board.root, board.id, codeIsMain);
const cached = stateCache.get(before.cacheId);
if (before.cacheable && cached?.revision === before.revision) {
const state = stateForRequest(cached.state, board.root, seen, cached.preparedFlow, true, codeIsMain);
- const after = boardStateRevision(board.root, board.id, codeIsMain, projects);
+ const after = boardStateRevision(board.root, board.id, codeIsMain);
if (after.cacheable && after.revision === before.revision) {
stateCache.delete(before.cacheId);
stateCache.set(before.cacheId, cached);
@@ -566,7 +568,7 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =
const state = buildLocalBoardState(board, codeIsMain, before.milestones);
const history = withBoard(board.root, (db) => store.events(db), codeIsMain);
const preparedFlow = prepareFlowHistory(history);
- const after = boardStateRevision(board.root, board.id, codeIsMain, projects);
+ const after = boardStateRevision(board.root, board.id, codeIsMain);
const stateJsonFields = prepareStateJson(state);
if (before.cacheable && after.cacheable && before.revision === after.revision) {
const entry = { revision: before.revision, state, preparedFlow, stateJsonFields };
@@ -593,7 +595,7 @@ export function createLocalApiHandler({ secret, getPort, runCommand, projects =
board: (id) => findBoard(id, projects, codeIsMain),
state: (board, who, seen) => localState(board, seen).state,
stateJson: (board, who, seen) => localState(board, seen).json,
- watchRevision: (board) => watchLocalStateRevision(board, projects),
+ watchRevision: (board) => watchLocalStateRevision(board),
shout: (board, id) => relayLinked(board.root)
? relayPresentationShout(board.root, id)
: withBoard(board.root, (db) => store.shoutDetails(db, id), codeIsMain),
diff --git a/src/roadmap.js b/src/roadmap.js
index c1d2663a..36ec3839 100644
--- a/src/roadmap.js
+++ b/src/roadmap.js
@@ -5,13 +5,13 @@ import { codeIsFromMain, repoInfo } from './git.js';
import { listApiProjects } from './projects.js';
/** Resolve a repo-qualified milestone item against this machine's registered boards. */
-export function milestoneRoadmap(root, board, projects = listApiProjects) {
- const registered = projects();
+export function milestoneRoadmap(root, board) {
+ const projects = listApiProjects();
const resolveExternal = (reference) => {
const match = /^(.+)#([1-9]\d*)$/.exec(reference);
if (!match) return { id: reference, title: reference, status: 'unavailable' };
const [, repo, number] = match;
- const candidates = registered.filter((project) => project.name === repo || basename(project.root) === repo);
+ const candidates = projects.filter((project) => project.name === repo || basename(project.root) === repo);
if (candidates.length !== 1) return { id: reference, title: `#${number} (${repo})`, status: 'unavailable' };
try {
const info = repoInfo(candidates[0].root);
diff --git a/test/api-http.test.js b/test/api-http.test.js
index aa5d901c..76dc6aa8 100644
--- a/test/api-http.test.js
+++ b/test/api-http.test.js
@@ -537,9 +537,17 @@ test('[A2] a live HTTP stream follows CLI writes and reconnects after Last-Event
test('[A2, N26] the event stream says when the board changes without a move', async (t) => {
const external = fixture(t);
+ const externalConfigPath = join(external.root, 'pullboard.json');
+ writeFileSync(externalConfigPath, JSON.stringify({ ...JSON.parse(readFileSync(externalConfigPath, 'utf8')), name: 'Roadmap fixture' }));
+ runFixtureGit(['commit', '-q', '-m', 'chore: name the roadmap fixture', '--', 'pullboard.json'], { cwd: external.root, env: external.env, stdio: 'pipe' });
const externalAdded = external.cli(external.root, 'add', 'app', 'Roadmap item', '--criterion', 'remain open', '--specs', 'G1');
const externalAgent = external.cli(external.root, 'worktree', 'app', '--model', 'fixture-agent');
const box = await httpBox(t, { additionalProjects: [{ root: external.root, name: 'Roadmap fixture' }] });
+ // The roadmap resolves other repos through this machine's registry, as an export does.
+ const priorHome = process.env.PULLBOARD_HOME;
+ process.env.PULLBOARD_HOME = box.env.PULLBOARD_HOME;
+ t.after(() => { if (priorHome === undefined) delete process.env.PULLBOARD_HOME; else process.env.PULLBOARD_HOME = priorHome; });
+ registerProject(external.root);
const boardListing = await box.call('/api/v1/boards');
const externalId = boardListing.document.boards.find((entry) => resolve(entry.root) === resolve(external.root)).id;
const configPath = join(box.root, 'pullboard.json');
@@ -613,7 +621,7 @@ test('[A2, N26] the event stream says when the board changes without a move', as
async function changedOnce(label) {
const frame = await Promise.race([
nextFrame(),
- new Promise((_, reject) => setTimeout(() => reject(new Error(`changed event did not arrive within two seconds (${label})`)), 2000)),
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`changed event did not arrive within two seconds (${label})`)), 2000)), // budget: #554's criterion bounds a changed event at two seconds.
]);
assert.equal(frame.event, 'changed');
assert.equal(frame.id, null, 'a state notification does not advance the append-only event cursor');