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(view): the star line counts linked boards read locally [N26]

Corey Olsonf894b2f77713
diff --git a/src/cockpit.js b/src/cockpit.js
index c921b875..dd22a4f9 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -321,10 +321,23 @@ function localNote(state, facts = {}) {
drawHosted(document, hostedState(state, { browser: hostedBrowser(navigator), ...facts }), { view: localSession?.origin || LOCAL_VIEW, signIn: hosted.signIn, session: hosted.relaySession });
}
-/** Show the hosted page's star line (src/view/star.js) to a signed-in person with a linked board, until dismissed here; pass a board list through. */
+let starLinked = { at: 0, linked: false, reading: false };
+/**
+ * Show the hosted page's star line (src/view/star.js) to a signed-in person whose account lists a linked board, until
+ * dismissed here; pass a board list through. Why the account's list: it is the linked-board metadata the relay serves
+ * this page, whichever source then draws a board, so a linked board this machine reads locally still counts, and no
+ * relay client loads to decide it. It is read until it lists one, at most every few seconds.
+ */
function starLine(list) {
- const linked = Boolean(list?.boards?.some((board) => board.source === 'relay'));
- if ($('star-line')) $('star-line').hidden = !(hosted.relaySession && linked && keep(${JSON.stringify(STAR_KEY)}) !== 'dismissed');
+ const line = $('star-line');
+ if (!line) return list;
+ const show = () => { line.hidden = !(hosted.relaySession && starLinked.linked && keep(${JSON.stringify(STAR_KEY)}) !== 'dismissed'); };
+ if (hosted.relaySession && !starLinked.linked && !starLinked.reading && Date.now() - starLinked.at > 2500) {
+ starLinked = { at: Date.now(), linked: false, reading: true };
+ jsonRequest('/api/v1/boards', undefined, '', {}, 'no-store').then((reply) => reply?.boards?.some((board) => typeof board?.id === 'string'), () => false)
+ .then((linked) => { starLinked = { at: Date.now(), linked, reading: false }; line.dataset.linked = linked ? 'yes' : 'no'; show(); });
+ }
+ show();
return list;
}
$('star-dismiss')?.addEventListener('click', () => { keep(${JSON.stringify(STAR_KEY)}, 'dismissed'); starLine(null); });
diff --git a/test/cockpit/relay.test.js b/test/cockpit/relay.test.js
index fb574dda..07919e13 100644
--- a/test/cockpit/relay.test.js
+++ b/test/cockpit/relay.test.js
@@ -15,7 +15,7 @@ import { relayClientFixture } from '../relay-client-fixture.js';
import { runFixtureChildAsync } from '../fixture-child.js';
import { findChromeExecutable, relayWorkBudgetMs, startChrome } from '../relay-browser-fixture.js';
import { BIN, scratch, SPEC, machine, project, fetchLive, startView, target, chromeExecutable, browserPause, startSnapshotChrome, openSnapshotChrome, stopOwnedChrome, closeSnapshotChrome, pickProject, proofShot } from './fixture.js';
-import { STAR_TEXT, starRepository } from '../../src/view/star.js';
+import { STAR_SHOWN, STAR_TEXT, starLineFixture, starRepository, starSteps } from './star-line.js';
test('a paired relay reference explains that committed source is available only in the local project view [B33]', {
// Its relay work is the fixture's setup moves, the browser's pairing and the reference's request: three budgets,
@@ -2045,47 +2045,46 @@ test('the hosted page lists linked and local boards together [N26,H5]', {
}
});
-test('the star line shows once to a signed-in person and stays dismissed [N26]', { timeout: 90_000 }, async (t) => { // budget: hang-only ceiling for real Chrome startup and five page loads.
+test('the star line shows once to a signed-in person and stays dismissed [N26]', { timeout: 120_000 }, async (t) => { // budget: hang-only ceiling for real Chrome startup and nine page loads.
const executable = chromeExecutable();
if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for the star line proof.');
- const box = machine();
- project(box, 'star-line');
- const live = await startView(box);
- let linked = false, chrome;
- const page = (relaySession) => cockpitPage('', { readOnly: true, requests: relaySession, transportModule: '/star-transport.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' });
- const server = createServer(async (request, response) => {
- const url = new URL(request.url, 'http://127.0.0.1');
- const send = (type, body, status = 200) => response.writeHead(status, { 'content-type': type, 'cache-control': 'no-store' }).end(body);
- if (url.pathname === '/in' || url.pathname === '/out') return send('text/html; charset=utf-8', page(url.pathname === '/in'));
- if (url.pathname === '/star-transport.js') return send('text/javascript', "export async function createTransport() { return { async request(path) { return (await fetch('/relay' + path)).json(); } }; }");
- if (url.pathname === '/view.css') return send('text/css', readFileSync(new URL('../../src/view.css', import.meta.url), 'utf8'));
- if (!url.pathname.startsWith('/relay/') || (!linked && url.pathname === '/relay/api/v1/boards')) return send('application/json', JSON.stringify({ version: 1, boards: [] }));
- const reply = await fetchLive(live.base + url.pathname.slice('/relay'.length) + url.search, { headers: { 'x-pullboard-key': live.key } }).catch(() => null);
- return send('application/json', reply ? await reply.text() : '{}', reply?.status ?? 502);
- });
- const origin = await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(`http://127.0.0.1:${server.address().port}`)));
+ const star = await starLineFixture();
+ const linkedBoard = { id: star.board.id, name: 'person/star-line', repository: 'person/star-line' };
const profile = mkdtempSync(join(tmpdir(), 'pullboard-star-line-chrome-'));
- const line = "(() => { const p = document.querySelector('#star-line'); return p && !p.hidden && getComputedStyle(p).display !== 'none' ? { text: p.textContent, href: p.querySelector('a').href, lines: p.querySelector('a').getClientRects().length, parts: p.children.length, count: document.querySelectorAll('.star-line').length } : null; })()";
+ const expected = { text: STAR_TEXT + '×', href: starRepository(), lines: 1, parts: 2, count: 1 };
+ let chrome;
try {
chrome = await openSnapshotChrome(executable, 'about:blank', profile);
- await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: "{ const f = window.fetch; window.fetch = (input, init) => String(input?.url ?? input).startsWith('http://127.0.0.1:4890') ? Promise.reject(new TypeError('no local view in this proof')) : f(input, init); }" }); // Never this machine's real view.
- await chrome.send('Page.navigate', { url: origin + '/out' }).then(() => chrome.waitFor("location.pathname === '/out' && !document.querySelector('#local-note').hidden"));
- assert.equal(await chrome.stable(line), null, 'a signed-out page shows no star line');
- await chrome.send('Page.navigate', { url: live.link.href }).then(() => chrome.waitFor('!!data?.project'));
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: star.script });
+ const page = starSteps(chrome, star);
+ star.state.account = [linkedBoard]; // Even a linked list that answered a signed-out page would show nothing there.
+ await chrome.send('Page.navigate', { url: star.origin + '/out' }).then(() => chrome.waitFor("location.pathname === '/out' && !document.querySelector('#local-note').hidden"));
+ assert.equal(await page.shown(), null, 'a signed-out page shows no star line');
+ assert.equal(star.requests.get('/api/v1/boards'), undefined, 'a signed-out page never asks for the linked list');
+ await chrome.send('Page.navigate', { url: star.live.link.href }).then(() => chrome.waitFor('!!data?.project'));
assert.equal(await chrome.stable("document.querySelector('#star-line') === null && !document.body.textContent.includes('GitHub star')"), true, 'the local view never carries the star line');
for (const file of ['src/cli.js', 'src/mcp.js', 'src/help.js']) assert.ok(!readFileSync(new URL('../../' + file, import.meta.url), 'utf8').includes('GitHub star'), file + ' never prints the star line');
- await chrome.send('Page.navigate', { url: origin + '/in' }).then(() => chrome.waitFor("location.pathname === '/in' && data !== null && !document.body.classList.contains('loading')"));
- assert.equal(await chrome.stable(line), null, 'a signed-in person with no linked board sees no star line');
- linked = true; // The person links a board: the page's next read of the relay lists it.
- await chrome.waitFor(`${line} !== null`);
- assert.deepEqual(await chrome.stable(line), { text: STAR_TEXT + '×', href: starRepository(), lines: 1, parts: 2, count: 1 }, 'one line, one plain sentence, linking to the repository');
+ await page.open('/in-local', 'no', []);
+ assert.equal(await page.shown(), null, 'a signed-in person with an unlinked local-only board sees no star line');
+ await page.open('/in', 'no');
+ assert.equal(await page.shown(), null, 'a signed-in person with an empty linked list sees no star line');
+ await page.open('/in-local', 'yes', [linkedBoard]); // The person links this machine's board: the page reads it locally.
+ assert.deepEqual(await page.shown(), expected, 'a linked board read locally shows one line, one plain sentence, linking to the repository');
+ assert.equal(star.requests.get('/star-transport.js'), undefined, 'no relay client loads while every linked board is local');
for (const width of [1280, 390]) await proofShot(chrome, 'star-line', width);
- await press(chrome, "document.querySelector('#star-dismiss')");
- await chrome.waitFor(`${line} === null && localStorage.getItem('pb.star') === 'dismissed'`);
- await chrome.send('Page.reload', {}).then(() => chrome.waitFor("!!data?.project && document.querySelector('#star-line') !== null"));
- assert.equal(await chrome.stable(line), null, 'a dismissed star line stays dismissed across a reload, with the linked board listed');
+ await page.dismiss();
+ await page.reload('yes');
+ assert.equal(await page.shown(), null, 'a dismissed star line stays dismissed across a reload, with the linked board listed');
+ await chrome.stable("localStorage.removeItem('pb.star')");
+ await page.open('/in', 'no', []);
+ Object.assign(star.state, { account: [linkedBoard], relay: true }); // A board linked from another machine arrives through the relay.
+ await chrome.waitFor(`${STAR_SHOWN} !== null`);
+ assert.deepEqual(await page.shown(), expected, 'a relay-drawn linked board shows the same one line');
+ await page.dismiss();
+ await page.reload('yes');
+ assert.equal(await page.shown(), null, 'dismissed there too, it stays dismissed across a reload');
} finally {
if (chrome) await closeSnapshotChrome(chrome);
- await Promise.all([live.stop(), new Promise((resolve) => server.close(resolve))]).finally(() => rmSync(profile, { recursive: true, force: true }));
+ await star.close().finally(() => rmSync(profile, { recursive: true, force: true }));
}
});
diff --git a/test/cockpit/star-line.js b/test/cockpit/star-line.js
new file mode 100644
index 00000000..b1786653
--- /dev/null
+++ b/test/cockpit/star-line.js
@@ -0,0 +1,101 @@
+/** @pullboard-test-input source-tree */
+/**
+ * The star line's hosted fixture (#727) [N26]: a stand-in for pullboard.dev that serves the real hosted page signed
+ * out (/out), signed in (/in), and signed in on the machine whose view it reads (/in-local), with the account's
+ * linked list, a relay transport and this machine's view all owned by the test. In the page, its fixed local address,
+ * 127.0.0.1:4890, is this fixture on /in-local and answers nothing elsewhere, so the proof never reaches a real view.
+ */
+import { readFileSync } from 'node:fs';
+import { createServer, request as httpRequest } from 'node:http';
+import { cockpitPage } from '../../src/cockpit.js';
+import { fetchLive, machine, project, startView } from './fixture.js';
+import { press } from './stable.js';
+export { STAR_TEXT, starRepository } from '../../src/view/star.js';
+
+/**
+ * Start the fixture. `state.account` is the account's linked list as the relay serves it; `state.relay` says whether
+ * the relay transport lists the board; `requests` counts each path asked for.
+ *
+ * @returns {Promise<{origin: string, live: object, board: object, state: {account: object[], relay: boolean}, requests: Map<string, number>, script: string, close: () => Promise<void>}>}
+ */
+export async function starLineFixture() {
+ const box = machine();
+ project(box, 'star-line');
+ const live = await startView(box);
+ const board = (await (await fetchLive(live.base + '/api/v1/boards', { headers: { 'x-pullboard-key': live.key } })).json()).boards[0];
+ const state = { account: [], relay: false };
+ const requests = new Map();
+ /** The hosted page as the relay serves it, signed in or not. */
+ const page = (relaySession) => cockpitPage('', { readOnly: true, requests: relaySession, transportModule: '/star-transport.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' });
+ let origin = '';
+ const server = createServer(async (request, response) => {
+ const url = new URL(request.url, 'http://127.0.0.1');
+ requests.set(url.pathname, (requests.get(url.pathname) || 0) + 1);
+ /** Answer with a body of a type. */
+ const send = (type, body, status = 200) => response.writeHead(status, { 'content-type': type, 'cache-control': 'no-store' }).end(body);
+ if (['/in', '/in-local', '/out'].includes(url.pathname)) return send('text/html; charset=utf-8', page(url.pathname !== '/out'));
+ if (url.pathname === '/star-transport.js') return send('text/javascript', "export async function createTransport() { return { async request(path) { return (await fetch('/relay' + path)).json(); } }; }");
+ if (url.pathname === '/view.css') return send('text/css', readFileSync(new URL('../../src/view.css', import.meta.url), 'utf8'));
+ // The account's linked list: metadata only, read by the page on its own origin.
+ if (url.pathname === '/api/v1/boards') return send('application/json', JSON.stringify({ version: 1, boards: state.account }));
+ if (url.pathname === '/lv/local/protocol') return send('application/json', JSON.stringify({ version: 1, apiVersion: 1, hostedOrigin: origin }));
+ // This machine's view answers reads and streams through the fixture, with its key.
+ if (url.pathname.startsWith('/lv/')) return proxy(live.base + url.pathname.slice(3) + url.search, request, response);
+ if (url.pathname.startsWith('/relay/') && (state.relay || url.pathname !== '/relay/api/v1/boards')) return proxy(live.base + url.pathname.slice(6) + url.search, request, response);
+ if (url.pathname === '/relay/api/v1/boards') return send('application/json', JSON.stringify({ version: 1, boards: [] }));
+ return send('application/json', JSON.stringify({ error: 'not in this fixture' }), 404);
+ });
+ /** Read the owned view with its key and pass the answer on as it comes, an event stream included. */
+ function proxy(address, request, response) {
+ const headers = { 'x-pullboard-key': live.key, accept: request.headers.accept || '*/*', ...(request.headers['last-event-id'] ? { 'last-event-id': request.headers['last-event-id'] } : {}) };
+ const upstream = httpRequest(address, { headers, agent: false }, (reply) => {
+ response.writeHead(reply.statusCode || 502, { 'content-type': reply.headers['content-type'] || 'application/json', 'cache-control': 'no-store' });
+ reply.pipe(response);
+ });
+ response.once('close', () => upstream.destroy());
+ upstream.once('error', () => { if (!response.headersSent) response.writeHead(502); response.end(); });
+ upstream.end();
+ }
+ origin = await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(`http://127.0.0.1:${server.address().port}`)));
+ // Run before each page: on /in-local, 127.0.0.1:4890 is this fixture and the tab starts with its local session;
+ // anywhere else nothing answers there, so the page never starts its round trip to a real view.
+ const script = `{ const f = window.fetch, local = 'http://127.0.0.1:4890', here = location.pathname === '/in-local';
+ window.fetch = (input, init) => { const url = String(input?.url ?? input); return !url.startsWith(local) ? f(input, init) : here ? f(${JSON.stringify(origin)} + '/lv' + url.slice(local.length), init) : Promise.reject(new TypeError('no local view here')); };
+ if (here) sessionStorage.setItem('pullboard.local.session', JSON.stringify({ version: 1, origin: local, key: ${JSON.stringify(live.key)} })); }`;
+ return { origin, live, board, state, requests, script, close: () => Promise.all([live.stop(), new Promise((resolve) => server.close(resolve))]) };
+}
+
+/** The star line as the page shows it: its words, link, line boxes and parts, or null while it is not on screen. */
+export const STAR_SHOWN = "(() => { const p = document.querySelector('#star-line'); return p && !p.hidden && getComputedStyle(p).display !== 'none' ? { text: p.textContent, href: p.querySelector('a').href, lines: p.querySelector('a').getClientRects().length, parts: p.children.length, count: document.querySelectorAll('.star-line').length } : null; })()";
+
+/**
+ * Steps on the fixture's pages in one Chrome: open or reload a page and wait until it has drawn its boards and read
+ * the account's linked list (linked: 'yes' or 'no'), optionally with a new list and with the request counts
+ * started afresh, read the line, and dismiss it.
+ *
+ * @param {object} chrome - A shared-wait Chrome client.
+ * @param {{origin: string, state: {account: object[]}, requests: Map<string, number>}} star - The fixture.
+ */
+export function starSteps(chrome, star) {
+ /** Wait for a fresh page at a path to have read its boards and the account's list. */
+ const ready = (path, linked) => chrome.waitFor(`!window.__stale && location.pathname === ${JSON.stringify(path)} && data !== null && !document.body.classList.contains('loading') && document.querySelector('#star-line')?.dataset.linked === ${JSON.stringify(linked)}`);
+ return {
+ shown: () => chrome.stable(STAR_SHOWN),
+ async open(path, linked, account = star.state.account) {
+ star.state.account = account;
+ star.requests.clear();
+ await chrome.stable('window.__stale = true');
+ await chrome.send('Page.navigate', { url: star.origin + path });
+ await ready(path, linked);
+ },
+ async reload(linked) {
+ const path = await chrome.stable('(window.__stale = true, location.pathname)');
+ await chrome.send('Page.reload', {});
+ await ready(path, linked);
+ },
+ async dismiss() {
+ await press(chrome, "document.querySelector('#star-dismiss')");
+ await chrome.waitFor(`${STAR_SHOWN} === null && localStorage.getItem('pb.star') === 'dismissed'`);
+ },
+ };
+}