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
feat(view): a group follows every repo on one stream [N26,A2]
Corey Olson7e29a4c4b8c1
diff --git a/src/cockpit.js b/src/cockpit.jsindex 79d80ea1..e3909a5b 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -1043,11 +1043,12 @@ async function refresh() {$('live').textContent = snapshot ? 'read-only snapshot' : liveLine();}-// The local view follows the shown board's event stream instead of a timer (#545): it reads the board once, waits-// on the board's events after that read's latest one, and reads again only when an event or the stream's changed-// signal (#554) arrives, so a page whose board is quiet makes no requests. The relay transport keeps its own stream.+// The local view follows the shown boards' events instead of a timer (#545): it reads the board once, waits on its+// events after that read's latest one, and reads again only when an event or the stream's changed signal (#554)+// arrives, so a page whose boards are quiet makes no requests. The relay transport keeps its own stream.// A page holds at most one stream: Chrome allows six connections per host, a held stream keeps one for good, and the-// catch-up read needs the rest. Six held streams left none, and the page waited forever for its own read.+// catch-up read needs the rest. Six held streams, one per repo of a group, left none, and the page waited forever for+// its own read. So a group follows every repo it shows through one multiplexed stream (#600).let stream = null;let catching = null;let catchAgain = false;@@ -1080,22 +1081,31 @@ function unfollow() {}/**- * Follow the one board the page shows, or a shown group's first repo, starting a new stream after the state just- * read. Every catch-up reads every board, so the group's other repos and the sidebar's boards update with it, and on- * a project switch, without a stream of their own.+ * Follow every board the page shows, the board or each repo of a group, on one stream that starts each board after+ * the state just read. Every catch-up reads every board, so the sidebar's boards update with it and on a project+ * switch, without a stream of their own.*/function follow() {- const repo = data.group ? data.group.repos[0] : data.project ? { root: view.root, board: data.project } : null;- const board = repo && data.projects.find((entry) => entry.root === repo.root && entry.ok);- // The board's events after the latest one this page shows are what changed it since.- if (stream && board && stream.id === board.id) { stream.shown = Math.max(stream.shown, latestEvent(repo.board)); return; }+ const repos = data.group ? data.group.repos.map((repo) => [repo.root, repo.board]) : data.project ? [[view.root, data.project]] : [];+ const boards = repos.flatMap(([root, state]) => {+ const board = data.projects.find((entry) => entry.root === root && entry.ok);+ return board ? [{ root, id: board.id, shown: latestEvent(state) }] : [];+ });+ const key = boards.map((board) => board.id).join(',');+ // A board's events after the latest one this page shows are what changed it since.+ if (stream && boards.length && stream.key === key) {+ for (const board of boards) { const kept = stream.boards.find((entry) => entry.id === board.id); kept.shown = Math.max(kept.shown, board.shown); }+ return;+ }unfollow();- if (!board) return;- stream = { root: repo.root, id: board.id, after: latestEvent(repo.board), shown: latestEvent(repo.board), status: 'opening', offline: false, failures: 0, controller: null, retry: 0 };+ if (!boards.length) return;+ // One board's cursor is its latest event; a group's names each board's latest event, as #600 resumes them.+ const cursor = boards.length === 1 ? String(boards[0].shown) : boards.map((board) => board.id + ':' + board.shown).join(',');+ stream = { key, boards, cursor, status: 'opening', offline: false, failures: 0, controller: null, retry: 0 };void listen(stream);}-/** Read one server-sent message: its event name, its data and its numeric id. */+/** Read one server-sent message: its event name, its data and its id, as sent. */function streamMessage(block) {const message = { event: 'message', data: '', id: null };for (const line of block.split('\\n')) {@@ -1105,11 +1115,24 @@ function streamMessage(block) {const value = colon < 0 ? '' : line.slice(colon + 1).replace(/^ /, '');if (field === 'event') message.event = value;else if (field === 'data') message.data += (message.data ? '\\n' : '') + value;- else if (field === 'id' && /^\\d+$/.test(value)) message.id = Number(value);+ else if (field === 'id' && !value.includes('\\0')) message.id = value;}return message;}+/**+ * Whether a message changes what the page shows: an event after the latest one its board shows, or a signal with no+ * event, such as a warning or the board changing without a move. A group's stream names each event's board (#600).+ */+function streamMoved(entry, message) {+ let body = null;+ try { body = message.data ? JSON.parse(message.data) : null; } catch { return true; }+ const board = entry.boards.length === 1 ? entry.boards[0] : entry.boards.find((candidate) => candidate.id === body?.board);+ const id = Number(body?.event?.event_id ?? (entry.boards.length === 1 && /^\\d+$/.test(message.id ?? '') ? message.id : NaN));+ if (board && Number.isSafeInteger(id)) return id > board.shown;+ return Boolean(message.data) || message.event !== 'message';+}+/** The rule and next step a stream's refusal carries. */function streamRefusal(data) {try {@@ -1127,10 +1150,13 @@ async function listen(entry) {entry.controller = controller;try {if (!controller) throw new Error('this browser cannot read a stream');- // The stream goes where every API read goes: the serving host's base, with its credential headers.- const path = connection.base + '/api/v1/boards/' + encodeURIComponent(entry.id) + '/events';+ // The stream goes where every API read goes: the serving host's base, with its credential headers. One board has+ // its own events; a group's repos share one multiplexed stream (#600).+ const single = entry.boards.length === 1;+ const path = connection.base + (single ? '/api/v1/boards/' + encodeURIComponent(entry.boards[0].id) + '/events'+ : '/api/v1/events?boards=' + entry.boards.map((board) => encodeURIComponent(board.id)).join(','));const res = await fetch(path, {- headers: { ...connection.headers, accept: 'text/event-stream', 'last-event-id': String(entry.after) }, cache: 'no-store', signal: controller.signal,+ headers: { ...connection.headers, accept: 'text/event-stream', 'last-event-id': entry.cursor }, cache: 'no-store', signal: controller.signal,});if (!res.ok || !res.body) throw new Error('the board stream answered ' + res.status);entry.status = 'up';@@ -1148,9 +1174,8 @@ async function listen(entry) {const message = streamMessage(buffer.slice(0, end));buffer = buffer.slice(end + 2);if (message.event === 'error') throw new Error(streamRefusal(message.data));- if (message.id !== null) entry.after = message.id;- // An event after the latest one shown, or a signal with no id: a warning, or the board changed without a move.- if (message.id !== null ? message.id > entry.shown : Boolean(message.data) || message.event !== 'message') moved = true;+ if (message.id !== null) entry.cursor = message.id;+ if (streamMoved(entry, message)) moved = true;}// One read covers every event that arrived together.if (moved) catchUp();diff --git a/test/cockpit/live.test.js b/test/cockpit/live.test.jsindex feab8dde..17e650da 100644--- a/test/cockpit/live.test.js+++ b/test/cockpit/live.test.js@@ -23,6 +23,12 @@ function streamReads(chrome) {&& /text\/event-stream/.test(header(request, 'accept') ?? '')).map((request) => header(request, 'last-event-id'));}+/** The multiplexed event-stream reads the page opened (#600), each with the boards it names. */+function groupStreamReads(chrome) {+ return chrome.requests.filter((request) => /^https?:/.test(request.url) && new URL(request.url).pathname === '/api/v1/events'+ && /text\/event-stream/.test(header(request, 'accept') ?? '')).map((request) => (new URL(request.url).searchParams.get('boards') ?? '').split(',').sort());+}+/*** A loopback HTTP proxy in front of the real view, so a test can cut every connection through it and refuse new ones* until it is restored, as a lost network does. It names the view's own host, which the view's secret check requires.@@ -175,33 +181,35 @@ test('a dropped stream reconnects from its last event [N26,A2]', { timeout: 120_}});-// core-188's six-repo case (#545 review): one held stream per repo took all six of Chrome's connections to the view,-// so the catch-up read for a committed claim never left the page.-test('a group of six repos catches up on one stream [N26,A2]', { timeout: 120_000 }, async (t) => {+/**+ * A project group of `count` real repos, opened in real Chrome as the group, where a claim on `mover`'s item must+ * show within two seconds while the page follows every repo on one stream.+ */+async function groupClaim(t, name, count, mover) {const executable = chromeExecutable();assert.ok(executable, 'Chrome is required for the live view checks');const box = machine();const repos = [];- for (let index = 0; index < 6; index++) repos.push(project(box, `capacity-${index}`, SPEC, { project: 'Stream capacity', name: `Capacity ${index}` }));- box.run(repos[0].repo, 'add', 'web', 'Group catch-up', '--specs', 'G1', '--criterion', 'updates');+ for (let index = 0; index < count; index++) repos.push(project(box, `${name}-${index}`, SPEC, { project: name, name: `${name} ${index}` }));+ box.run(repos[mover].repo, 'add', 'web', 'Group catch-up', '--specs', 'G1', '--criterion', 'updates');const view = await startView(box);- const profile = mkdtempSync(join(tmpdir(), 'pullboard-live-group-chrome-'));+ const profile = mkdtempSync(join(tmpdir(), `pullboard-${name}-chrome-`));let chrome;try {chrome = await openSnapshotChrome(executable, view.link.href, profile);- const group = 'document.querySelector(\'#proj-list [data-root="group:Stream capacity"]\')';- await chrome.waitFor(`data?.projects?.length === 6 && !!${group}`);+ const group = `document.querySelector('#proj-list [data-root="group:${name}"]')`;+ await chrome.waitFor(`data?.projects?.length === ${count} && !!${group}`);await pickProject(chrome, group);- await chrome.waitFor('data?.group?.repos?.length === 6 && document.querySelector(\'#live\').textContent === \'\'');- const opened = streamReads(chrome).length;- // The group shows each repo's board; the first repo's item is the one that moves.- const shown = `data?.group?.repos?.find(repo => repo.root === ${JSON.stringify(repos[0].repo)})?.board.items.find(item => item.id === 1)?.status`;+ await chrome.waitFor(`data?.group?.repos?.length === ${count} && document.querySelector('#live').textContent === ''`);+ const ids = (await Promise.all(repos.map((repo) => boardId(view, repo.repo)))).sort();+ assert.deepEqual(groupStreamReads(chrome).at(-1), ids, 'the group follows every repo it shows on one stream');+ const shown = `data?.group?.repos?.find(repo => repo.root === ${JSON.stringify(repos[mover].repo)})?.board.items.find(item => item.id === 1)?.status`;await watchFor(chrome, '__groupClaimAt', `${shown} === 'claimed'`);- box.run(repos[0].web, 'claim', '1');- assert.equal((await boardOf(view, repos[0].repo)).items.find((item) => item.id === 1).status, 'claimed', 'the board has the claim');+ box.run(repos[mover].web, 'claim', '1');+ assert.equal((await boardOf(view, repos[mover].repo)).items.find((item) => item.id === 1).status, 'claimed', 'the board has the claim');await chrome.waitFor('window.__groupClaimAt !== null', 15_000); // budget: hang ceiling for the claim to arrive; the latency is judged below.- const latency = await chrome.stable('window.__groupClaimAt') - await eventAt(view, repos[0].repo, 'claim', 1);- t.diagnostic(`the group showed the claim ${latency} ms after the board recorded it, with ${opened} stream read(s) opened`);+ const latency = await chrome.stable('window.__groupClaimAt') - await eventAt(view, repos[mover].repo, 'claim', 1);+ t.diagnostic(`a group of ${count} showed repo ${mover + 1}'s claim ${latency} ms after the board recorded it`);assert.ok(latency <= 2_000, `the group shows the claim ${latency} ms after the board recorded it`); // budget: declared by #545's frozen criterion: a move appears within 2000 ms.assert.deepEqual(chrome.exceptions, [], 'the page raises no uncaught exception');} finally {@@ -209,4 +217,15 @@ test('a group of six repos catches up on one stream [N26,A2]', { timeout: 120_00rmSync(profile, { recursive: true, force: true });await view.stop();}+}++// core-188's six-repo case (#545 review): one held stream per repo took all six of Chrome's connections to the view,+// so the catch-up read for a committed claim never left the page.+test('a group of six repos catches up on one stream [N26,A2]', { timeout: 120_000 }, async (t) => {+ await groupClaim(t, 'capacity', 6, 0);+});++// docs-28's two-repo case (#545 review): a move made only in a group's second repo must wake the page too.+test("a move made only in a group's second repo appears as fast as one in its first [N26,A2]", { timeout: 120_000 }, async (t) => {+ await groupClaim(t, 'second', 2, 1);});