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.

Merge branch 'main' into view/632-claude

Corey Olson604ee5671cca
diff --cc src/cockpit.js
index 41b0c048,71730c33..b980335a
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@@ -316,33 -308,14 +319,31 @@@ let detailRead = null
const addressedShouts = new Map();
const $ = (id) => document.getElementById(id);
- /** Say in one line what the page is doing about this machine's view, or why it cannot read it, with the ways on. */
- function localNote(text, ways = false) {
- $('local-note').hidden = !text;
- $('local-note-text').textContent = text || '';
- $('local-note-links').hidden = !ways;
- $('local-note-view').href = (localSession?.origin || LOCAL_VIEW) + '/local/view';
- $('local-note-sign-in').hidden = !hosted.signIn || hosted.relaySession;
- if (hosted.signIn) $('local-note-sign-in').href = hosted.signIn;
+ const hostedState = (${hostedState.toString()});
+ const hostedBrowser = (${hostedBrowser.toString()});
+ const drawHosted = (${drawHosted.toString()});
+ /** Show the hosted state the page is in (src/view/hosted.js), with its next step, or none with null. */
+ function localNote(state, facts = {}) {
+ drawHosted(document, hostedState(state, { browser: hostedBrowser(navigator), ...facts }), { view: localSession?.origin || LOCAL_VIEW, signIn: hosted.signIn, session: hosted.relaySession });
}
+/** Show one dismissable update line only after this hosted page has read a known older local release. */
+function renderHostedReleaseNote(project) {
+ const region = $('hosted-release-note');
+ region.hidden = true;
+ const source = project?.releaseNotes ? project : data?.projects?.find((entry) => entry.ok && entry.releaseNotes);
+ if (!hosted.local || !localConfirmed || !localSession || connection.base !== localSession.origin
+ || transportModule || transport || !source?.releaseNotes) return;
+ const installed = source.releaseNotes.version;
+ const distance = hostedReleaseDistance(installed, hostedRelease.version, hostedRelease.versions);
+ if (!distance) return;
+ const dismissedKey = 'pb.hosted-release-dismissed.' + hostedRelease.version;
+ if (dismissedHostedReleases.has(hostedRelease.version) || keep(dismissedKey) === '1') return;
+ $('hosted-release-text').textContent = 'Pullboard ' + installed + ' is installed; ' + hostedRelease.version + ' is current, ' + distance + ' ' + (distance === 1 ? 'release' : 'releases') + ' behind. Update with';
+ $('hosted-release-link').href = 'https://github.com/pullboard-dev/pullboard/blob/main/CHANGELOG.md';
+ region.hidden = false;
+}
+
/** Hide the relay's own banner, which speaks for the relay, on a page the relay does not serve this time. */
function hideRelayNotice() {
const banner = document.getElementById('relay-notice');
diff --cc test/cockpit/local-origin.test.js
index f9e73838,1fbda21b..cbcd5387
--- a/test/cockpit/local-origin.test.js
+++ b/test/cockpit/local-origin.test.js
@@@ -7,7 -7,7 +7,8 @@@ import { tmpdir } from 'node:os'
import { join } from 'node:path';
import { test } from 'node:test';
import { cockpitPage } from '../../src/cockpit.js';
+import { VERSION } from '../../src/help.js';
+ import { Refused } from '../../src/refused.js';
import { createRelayBrowserHandler } from '../../relay/browser-page.js';
import { BIN, machine, project, startView, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, styleOf, proofShot } from './fixture.js';
@@@ -90,9 -82,16 +91,16 @@@ async function hostedStandIn(chrome, pa
return chrome.send('Fetch.fulfillRequest', {
requestId, responseCode: reply.status,
responseHeaders: Object.entries(reply.headers).filter(([name]) => !['content-length', 'transfer-encoding', 'connection', 'keep-alive', 'date'].includes(name)).map(([name, value]) => ({ name, value: String(value) })),
- body: Buffer.from(reply.body).toString('base64'),
+ body: Buffer.from(responseBody).toString('base64'),
});
}
+ if (address.pathname === '/relay/client.js' && local.client) {
+ return chrome.send('Fetch.fulfillRequest', {
+ requestId, responseCode: 200,
+ responseHeaders: [{ name: 'Content-Type', value: 'text/javascript' }, { name: 'Cache-Control', value: 'no-store' }],
+ body: Buffer.from(local.client).toString('base64'),
+ });
+ }
if (address.pathname === '/api/v1/boards') {
return chrome.send('Fetch.fulfillRequest', {
requestId, responseCode: 200,
@@@ -287,172 -285,84 +295,249 @@@ test('a pullboard.dev page reads the lo
}
});
+test('the hosted page says how far behind this machine\'s Pullboard is [N26,A2]', { timeout: 120_000 }, async (t) => {
+ const executable = chromeExecutable();
+ assert.ok(executable, 'the hosted version notice needs real Chrome');
+ const box = machine();
+ const board = project(box, 'hosted-release');
+ box.run(board.repo, 'add', 'web', 'A board on an older Pullboard release', '--specs', 'G1');
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-release-lag-'));
+ let view, chrome, stopStandIn;
+ try {
+ view = await startView(box);
+ const local = { own: view.base, target: view.base, versionOverride: '0.8.20' };
+ chrome = await openSnapshotChrome(executable, 'about:blank', profile);
+ for (const permissions of [['loopbackNetwork', 'localNetwork', 'localNetworkAccess'], ['localNetworkAccess']]) {
+ try { await chrome.send('Browser.grantPermissions', { origin: HOSTED, permissions }); break; } catch { /* Chrome versions expose different permission names */ }
+ }
+ const changelog = readFileSync(new URL('../../CHANGELOG.md', import.meta.url), 'utf8');
+ const versionOrder = (version) => version.split('.').map(Number);
+ const compareVersions = (left, right) => {
+ const a = versionOrder(left), b = versionOrder(right);
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
+ };
+ const releaseVersions = [...new Set([...changelog.matchAll(/^## \[(\d+\.\d+\.\d+)\](?:\s|$)/gmu)].map((match) => match[1]))]
+ .filter((version) => compareVersions(version, VERSION) <= 0)
+ .sort(compareVersions);
+ /** Ask the production authenticated relay route to render its default hosted release page. */
+ const handler = createRelayBrowserHandler({ authenticate: async () => ({ kind: 'session' }) });
+ let productionPage = '';
+ let productionHeaders = {};
+ const response = { writeHead(_status, headers) { productionHeaders = headers; }, end(content) { productionPage = String(content); } };
+ assert.equal(await handler({ method: 'GET', url: '/', headers: {} }, response), true, 'the production relay route serves its authenticated page');
+ assert.match(productionHeaders['content-security-policy'], /connect-src[^;]*http:\/\/127\.0\.0\.1:4890[^;]*http:\/\/localhost:4890/u,
+ 'the production hosted page policy permits its local-view read');
+ /** Render the production hosted page for one release target, using only release entries shipped in this package. */
+ const pageFor = (version) => cockpitPage('', {
+ readOnly: true, requests: true, transportModule: '/relay/client.js', apiHeaders: {}, stylesheet: '/view.css',
+ hostedLocal: true, relaySession: true, signIn: '/auth/github/start', hostedReleaseVersion: version, hostedReleaseVersions: releaseVersions,
+ }).replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status"><p>Pairing this browser…</p></section>');
+ let activePage = pageFor('0.8.21');
+ stopStandIn = await hostedStandIn(chrome, { get anonymous() { return activePage; }, get relay() { return activePage; } }, await styleOf(view), local);
+ const bannerText = () => chrome.stable("document.querySelector('#hosted-release-text')?.textContent || ''");
+ const bannerHidden = () => chrome.stable("document.querySelector('#hosted-release-note')?.hidden ?? true");
+ let visit = 0;
+ let visitPreload;
+ let requestsAt = 0;
+ /** Every address one visit asked for, as origin plus path on the hosted page and as origin elsewhere. The page's own
+ * record of its fetch calls counts asks a page policy blocks before Chrome's network sees them. */
+ const reached = async () => {
+ const asked = [...chrome.requests.slice(requestsAt).map((request) => request.url), ...JSON.parse(await chrome.stable('JSON.stringify(window.__releaseFetches || [])'))];
+ return [...new Set(asked.map((url) => new URL(url, HOSTED + '/')).filter((address) => address.protocol.startsWith('http'))
+ .map((address) => (address.origin === HOSTED ? address.origin + address.pathname : address.origin)))].sort();
+ };
+ const open = async (version, production = false) => {
+ activePage = production ? productionPage : pageFor(version);
+ requestsAt = chrome.requests.length;
+ if (visitPreload) await chrome.send('Page.removeScriptToEvaluateOnNewDocument', { identifier: visitPreload });
+ const marker = ++visit;
+ const installed = await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `window.__releaseVisit = ${marker}; window.__releaseFetches = []; const pageFetch = window.fetch; window.fetch = function (input, init) { window.__releaseFetches.push(String(input?.url ?? input)); return pageFetch.call(this, input, init); };` });
+ visitPreload = installed.identifier;
+ await chrome.send('Page.navigate', { url: HOSTED + '/' });
+ await chrome.waitFor(`window.__releaseVisit === ${marker} && document.readyState === 'complete' && data?.project?.releaseNotes?.version === ${JSON.stringify(local.versionOverride)} && document.querySelector('#chain')?.textContent.includes('A board on an older Pullboard release')`, 25_000); // budget: hang ceiling for this navigation to finish the local state read before the next visit; no throughput claim.
+ };
+
+ // 0.8.21 is a shipped release in CHANGELOG.md, one actual release after the local 0.8.20 install.
+ await open('0.8.21');
+ assert.match(await bannerText(), /Pullboard 0\.8\.20 is installed; 0\.8\.21 is current, 1 release behind/u);
+ assert.equal(await chrome.stable("document.querySelector('#hosted-release-note code')?.textContent"), 'npm i -g pullboard@latest');
+ assert.equal(await chrome.stable("document.querySelector('#hosted-release-link')?.href"), 'https://github.com/pullboard-dev/pullboard/blob/main/CHANGELOG.md');
+ await proofShot(chrome, 'hosted-release-note', 1280);
+ await proofShot(chrome, 'hosted-release-note', 390);
+ await chrome.click("document.querySelector('#hosted-release-dismiss')");
+ assert.equal(await bannerHidden(), true, 'dismiss hides the note for its current target release');
+ await open('0.8.21');
+ assert.equal(await bannerHidden(), true, 'the same target release stays dismissed after reload');
+
+ // The next shipped version gets its own dismissal key and its release count comes from actual release entries.
+ await open(VERSION, true);
+ const releasesBehind = releaseVersions.indexOf(VERSION) - releaseVersions.indexOf('0.8.20');
+ assert.ok(releasesBehind > 0, 'the hosted package has shipped releases after the simulated older install');
+ assert.equal(await bannerText(), `Pullboard 0.8.20 is installed; ${VERSION} is current, ${releasesBehind} ${releasesBehind === 1 ? 'release' : 'releases'} behind. Update with`);
+ assert.equal(await bannerHidden(), false, 'a new target release brings the note back');
+ const behindReached = await reached();
+
+ // The production-generated page counts every numeric release heading, including 0.8.4's section with no headline.
+ local.versionOverride = '0.8.4';
+ await open(VERSION, true);
+ const legacyReleasesBehind = releaseVersions.indexOf(VERSION) - releaseVersions.indexOf('0.8.4');
+ assert.ok(legacyReleasesBehind > releasesBehind, 'the full shipped heading list includes releases without headlines');
+ assert.equal(await bannerText(), `Pullboard 0.8.4 is installed; ${VERSION} is current, ${legacyReleasesBehind} releases behind. Update with`);
+
+ local.versionOverride = VERSION;
+ await open(VERSION, true);
+ assert.equal(await bannerHidden(), true, 'matching local and hosted releases show no note');
+ assert.deepEqual(behindReached, await reached(), 'the note costs no request: a visit that shows it reaches what a matched visit reaches');
+ assert.deepEqual(behindReached.filter((address) => !address.startsWith(HOSTED + '/') && address !== LOCAL && address !== view.base), [],
+ 'the page learns both versions without asking any other address');
+
+ local.versionOverride = '0.8.22-rc.1';
+ await open(VERSION);
+ assert.equal(await bannerHidden(), true, 'an unlisted prerelease does not get a guessed release count');
+ local.versionOverride = '0.8.23';
+ await open('0.8.21');
+ assert.equal(await bannerHidden(), true, 'a local version newer than this hosted page does not get a false warning');
+ assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught page exceptions');
+ } finally {
+ try { if (stopStandIn) await stopStandIn(); }
+ finally {
+ try { if (chrome) await closeSnapshotChrome(chrome); }
+ finally {
+ try { if (view) await view.stop(); }
+ finally { rmSync(profile, { recursive: true, force: true }); }
+ }
+ }
+ }
+});
+
+test('the hosted relay never treats a remote board version as this machine\'s version [N26,A2]', { timeout: 120_000 }, async (t) => {
+ const executable = chromeExecutable();
+ assert.ok(executable, 'the relay fallback version guard needs real Chrome');
+ const box = machine();
+ const board = project(box, 'hosted-relay-release');
+ box.run(board.repo, 'add', 'web', 'A board read through the relay transport', '--specs', 'G1');
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-relay-release-'));
+ let view, chrome, stopStandIn;
+ try {
+ view = await startView(box);
+ chrome = await openSnapshotChrome(executable, 'about:blank', profile);
+ for (const permissions of [['loopbackNetwork', 'localNetwork', 'localNetworkAccess'], ['localNetworkAccess']]) {
+ try { await chrome.send('Browser.grantPermissions', { origin: HOSTED, permissions }); break; } catch { /* Chrome versions expose different permission names */ }
+ }
+ /** The relay page uses an authorized read-only transport backed by this real view's public API. */
+ const transportSource = `export async function createTransport() {
+ return { async request(path) {
+ const response = await fetch(${JSON.stringify(view.base)} + path, { headers: { 'x-pullboard-key': ${JSON.stringify(view.key)} } });
+ const document = await response.json();
+ if (!response.ok) throw new Error(document.error?.message || String(response.status));
+ return document;
+ } };
+ }`;
+ const handler = createRelayBrowserHandler({ authenticate: async () => ({ kind: 'session' }) });
+ let relayPage = '';
+ const response = { writeHead() {}, end(content) { relayPage = String(content); } };
+ assert.equal(await handler({ method: 'GET', url: '/', headers: {} }, response), true, 'the production relay handler supplies the fallback page');
+ stopStandIn = await hostedStandIn(chrome, {
+ anonymous: relayPage, relay: relayPage, assets: { '/relay/client.js': transportSource },
+ }, await styleOf(view), { own: view.base, target: null, relayTarget: view.base, versionOverride: '0.8.20' });
+ const relayVisit = '?relay-release-visit=1';
+ await chrome.send('Page.navigate', { url: HOSTED + '/' + relayVisit });
+ await chrome.waitFor(`location.search === ${JSON.stringify(relayVisit)} && document.readyState === 'complete' && data?.project?.releaseNotes?.version === '0.8.20' && document.querySelector('#chain')?.textContent.includes('A board read through the relay transport')`, 25_000); // budget: hang ceiling for this navigation to finish the relayed state read; no throughput claim.
+ assert.equal(await chrome.stable("data.project.releaseNotes.version"), '0.8.20', 'the relayed API state carries its simulated remote install version');
+ assert.equal(await chrome.stable("hosted.local && !localSession && connection.base === '' && !!transport && transportModule === '/relay/client.js' && localConfirmed === false"), true,
+ 'local discovery failed, so the board remains on the relay transport without a confirmed local session');
+ assert.equal(await chrome.stable("document.querySelector('#hosted-release-note').hidden"), true,
+ 'remote board metadata does not describe this machine’s installed version');
+ assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught relay fallback exceptions');
+ } finally {
+ try { if (stopStandIn) await stopStandIn(); }
+ finally {
+ try { if (chrome) await closeSnapshotChrome(chrome); }
+ finally {
+ try { if (view) await view.stop(); }
+ finally { rmSync(profile, { recursive: true, force: true }); }
+ }
+ }
+ }
+});
+ test('a signed-in local view with linked metadata and no paired transport says how to pair [N26,H5]', { timeout: 60_000 }, async () => { // budget: one real local-view discovery/round trip and the resulting hosted list read.
+ const executable = chromeExecutable();
+ assert.ok(executable, 'the mixed local and relay state check needs real Chrome');
+ const box = machine();
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-local-unpaired-'));
+ const linked = [{ id: 'a'.repeat(32), repository: 'acme/web', linkedAt: 0 }];
+ const client = 'export function rememberPairing() { return null; }\nexport async function createTransport() { return { async request(path) { if (path === "/api/v1/boards") { globalThis.__749transportListCalls = (globalThis.__749transportListCalls || 0) + 1; return { version: 1, boards: [], warnings: [] }; } throw new Error("no paired board"); } }; }\n';
+ let view, chrome, stopStandIn;
+ try {
+ view = await startView(box);
+ const direct = await call(view, '/api/v1/boards', { headers: { 'x-pullboard-key': view.key } });
+ assert.equal(direct.status, 200, 'the real private view answers with its valid session key');
+ assert.deepEqual(JSON.parse(direct.body).boards, [], 'the private view genuinely has no boards');
+ chrome = await openSnapshotChrome(executable, 'about:blank', profile);
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `(() => {
+ if (location.origin !== ${JSON.stringify(HOSTED)}) return;
+ const nativeFetch = window.fetch.bind(window);
+ window.__749fetches = [];
+ window.fetch = async (input, init) => {
+ const response = await nativeFetch(input, init);
+ const address = new URL(String(typeof input === 'string' ? input : input.url), location.href);
+ if (address.origin === ${JSON.stringify(HOSTED)} || ['127.0.0.1', 'localhost'].includes(address.hostname)) window.__749fetches.push({ origin: address.origin, path: address.pathname, status: response.status });
+ return response;
+ };
+ })()` });
+ const page = cockpitPage('', { readOnly: true, requests: true, transportModule: '/relay/client.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession: true, signIn: '/auth/github/start' })
+ .replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status"><p>Relay status</p></section>');
+ stopStandIn = await hostedStandIn(chrome, { anonymous: page, relay: page }, await styleOf(view), {
+ own: view.base, target: view.base, linked,
+ client,
+ });
+ for (const permissions of [['loopbackNetwork', 'localNetwork', 'localNetworkAccess'], ['localNetworkAccess']]) {
+ try { await chrome.send('Browser.grantPermissions', { origin: HOSTED, permissions }); break; } catch { /* a name this Chrome does not have */ }
+ }
+ await chrome.send('Page.navigate', { url: HOSTED + '/' });
+ // Wait for all independent authorities to finish, then make the state assertion directly. The condition does not
+ // wait for an unpaired label; loading must finish before the semantic assertion, including the final metadata read.
+ await chrome.waitFor(`location.origin === 'https://app.pullboard.dev' && sessionStorage.getItem('pullboard.local.session') && (window.__749fetches || []).some((x) => x.origin === ${JSON.stringify(view.base)} && x.path === '/api/v1/boards' && x.status === 200) && (window.__749fetches || []).some((x) => x.origin === 'https://app.pullboard.dev' && x.path === '/api/v1/boards' && x.status === 200) && window.__749transportListCalls >= 1 && !document.body.classList.contains('loading')`, 30_000); // budget: hang ceiling for local discovery, the round trip, the local list, linked metadata and the empty paired list.
+ const seen = JSON.parse(await chrome.stable(`JSON.stringify({
+ state: document.querySelector('#local-note')?.dataset.state ?? null,
+ hidden: document.querySelector('#local-note')?.hidden ?? true,
+ heading: document.querySelector('#local-note-title')?.textContent.trim() ?? null,
+ text: document.querySelector('#local-note-text')?.textContent.trim() ?? null,
+ command: document.querySelector('#local-note-code')?.textContent.trim() ?? null,
+ hasSession: Boolean(sessionStorage.getItem('pullboard.local.session')),
+ sessionOrigin: JSON.parse(sessionStorage.getItem('pullboard.local.session'))?.origin ?? null,
+ localSessionMatches: (() => { const saved = JSON.parse(sessionStorage.getItem('pullboard.local.session')); return saved?.version === 1 && saved.origin === ${JSON.stringify(view.base)} && saved.key === ${JSON.stringify(view.key)}; })(),
+ fetches: window.__749fetches,
+ transportLists: window.__749transportListCalls,
+ cards: document.querySelectorAll('#proj-list .proj').length,
+ })`));
+ assert.equal(seen.hasSession, true, 'the browser holds a tab-scoped local-view session');
+ assert.equal(seen.sessionOrigin, view.base, 'the session names this private view');
+ assert.equal(seen.localSessionMatches, true, 'the browser uses the private view session without returning its secret');
+ assert.ok(seen.transportLists >= 1, 'the relay transport confirmed its real empty paired-board list');
+ assert.ok(seen.fetches.some((x) => x.origin === view.base && x.path === '/api/v1/boards' && x.status === 200), 'the hosted page read the reachable private view');
+ assert.ok(seen.fetches.some((x) => x.origin === 'https://app.pullboard.dev' && x.path === '/api/v1/boards' && x.status === 200), 'the hosted page read the signed-in account metadata');
+ assert.equal(seen.state, 'unpaired', `linked account metadata with no paired transport must show pairing guidance, not the generic local empty state: ${JSON.stringify(seen)}`);
+ assert.equal(seen.hidden, false);
+ assert.equal(seen.heading, 'Pair this browser');
+ assert.match(seen.text, /acme\/web/);
+ assert.equal(seen.command, 'pullboard relay on --all');
+ assert.match(seen.text, /scan its QR/, 'the pairing guidance tells the person to use the QR printed by relay on --all');
+ assert.equal(seen.cards, 0, 'no local or paired board is falsely shown');
+ assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught exceptions');
+ } finally {
+ try { if (stopStandIn) await stopStandIn(); }
+ finally {
+ try { if (chrome) await closeSnapshotChrome(chrome); }
+ finally {
+ try { if (view) await view.stop(); }
+ finally { rmSync(profile, { recursive: true, force: true }); }
+ }
+ }
+ }
+ });
+
test('a foreign origin or wrong Host is refused by the local view [N26,A2]', { timeout: 60_000 }, async () => { // budget: hang ceiling for one real view and a few local requests.
const box = machine();
project(box, 'local-origin-refusals');