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): show pairing steps beside an empty local view [N26,H5]

Corey Olson4d45e8929360
diff --cc src/cockpit.js
index 7304bf49,c71a008f..393d879e
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@@ -1001,19 -995,21 +1005,19 @@@ async function listedBoards()
try {
local = await jsonRequest('/api/v1/boards', undefined, localReadBase, localReadHeaders, 'no-store');
} catch (error) {
+ // A local read that fails once, as while the view restarts, is no reason to load the relay client for a
+ // person whose linked boards are all on this machine or who has none (#748).
if (!transport && hosted.relaySession && configuredTransportModule) {
- try { await loadTransport(); } catch { /* Keep the local refusal when neither source can be read. */ }
+ try { if (await linkedBoardMissing(new Set())) await loadTransport(); } catch { /* Keep the local refusal when neither source can be read. */ }
}
if (!transport) throw error;
- localNote(String(error.message || error), true);
+ localNote('local-failed', { detail: String(error.message || error) });
}
}
if (hosted.local && hasLocal && hosted.relaySession && configuredTransportModule && !transport) {
try {
- // Metadata is a same-origin cookie-authenticated read, with none of this machine's local credential.
- // Loading the decrypting client is needed only for a linked board absent from the local list.
- const linked = await jsonRequest('/api/v1/boards', undefined, '', {}, 'no-store');
- const localIds = new Set((local.boards || []).map(board => board.id));
- if (linked.boards?.some(board => typeof board.id === 'string' && /^[0-9a-f]{32}$/.test(board.id) && typeof board.repository === 'string' && !localIds.has(board.id))) await loadTransport();
+ if (await linkedBoardMissing(new Set((local.boards || []).map(board => board.id)))) await loadTransport();
- } catch (error) { localNote('Linked boards are unavailable: ' + String(error.message || error), true); }
+ } catch (error) { localNote('linked-failed', { detail: String(error.message || error) }); }
}
if (!hasLocal && transportModule && !transport) throw transportLoadError || new Error('The browser transport is still loading.');
if (transport) {
@@@ -1039,9 -1037,21 +1045,22 @@@
boardSources.set(row.id, { kind: 'relay', board: row });
boards.push(row);
}
- if (hosted.local) await hostedListed(boards, hasLocal);
++ if (hosted.local) await hostedListed(boards);
return { version: 1, boards, warnings: [...(local.warnings || []), ...(relay.warnings || [])] };
}
+ /** After a hosted board list: a list clears a state it stood in for, and a signed-in empty one says why it is empty. */
-async function hostedListed(boards, hasLocal) {
++async function hostedListed(boards) {
+ const shown = $('local-note').dataset.state || '';
+ if (boards.length) { if (['not-running', 'no-linked', 'unpaired', 'signed-out'].includes(shown)) localNote(null); return; }
- if (hasLocal || !hosted.relaySession || !['', 'not-running', 'no-linked', 'unpaired'].includes(shown)) return;
++ // An empty local view can still leave linked boards on another computer waiting for this browser to pair.
++ if (!hosted.relaySession || !['', 'not-running', 'no-linked', 'unpaired'].includes(shown)) return;
+ let linked;
+ try { linked = await jsonRequest('/api/v1/boards', undefined, '', {}, 'no-store'); } catch { return; /* the relay's banner says why */ }
+ const names = (linked.boards || []).filter((board) => typeof board.repository === 'string').map((board) => board.repository);
+ localNote(names.length ? 'unpaired' : 'no-linked', { linked: names });
+ }
+
/** Set presentation controls for the selected board; API routing still checks the target board independently. */
function syncBoardMode(root) {
if (snapshot) return;
diff --cc test/cockpit/local-origin.test.js
index b3d5a63f,05ae93f7..72769a49
--- a/test/cockpit/local-origin.test.js
+++ b/test/cockpit/local-origin.test.js
@@@ -83,11 -85,11 +85,18 @@@ async function hostedStandIn(chrome, pa
body: Buffer.from(reply.body).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,
responseHeaders: [{ name: 'Content-Type', value: 'application/json' }, { name: 'Cache-Control', value: 'no-store' }],
-- body: Buffer.from(JSON.stringify({ version: 1, boards: [], warnings: [] })).toString('base64'),
++ body: Buffer.from(JSON.stringify({ version: 1, boards: local.linked ?? [], warnings: [] })).toString('base64'),
});
}
const document = resourceType === 'Document';
@@@ -276,6 -257,6 +285,84 @@@ test('a pullboard.dev page reads the lo
}
});
++
++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: local discovery, round trip, local list, linked metadata, and empty paired transport.
++ 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');