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): load relay transport only for linked reads [N26,H5]

Corey Olson89e25c30ba76
diff --git a/src/cockpit.js b/src/cockpit.js
index 200dbf6e..6179f820 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -189,7 +189,8 @@ let requests = ${JSON.stringify(requestMode)};
const pageReadOnly = ${JSON.stringify(readOnly)};
const pageRequests = ${JSON.stringify(requestMode)};
const relayRequestsEnabled = requests;
-let transportModule = ${moduleOption};
+const configuredTransportModule = ${moduleOption};
+let transportModule = configuredTransportModule;
const connection = ${connection};
let transport = null;
let transportLoadError = null;
@@ -965,10 +966,22 @@ async function listedBoards() {
try {
local = await jsonRequest('/api/v1/boards', undefined, localReadBase, localReadHeaders, 'no-store');
} catch (error) {
+ if (!transport && hosted.relaySession && configuredTransportModule) {
+ try { await loadTransport(); } catch { /* Keep the local refusal when neither source can be read. */ }
+ }
if (!transport) throw error;
localNote(String(error.message || error), true);
}
}
+ 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();
+ } catch (error) { localNote('Linked boards are unavailable: ' + String(error.message || error), true); }
+ }
if (!hasLocal && transportModule && !transport) throw transportLoadError || new Error('The browser transport is still loading.');
if (transport) {
try { relay = await transport.request('/api/v1/boards'); }
@@ -3391,10 +3404,26 @@ if (hosted.local) $('local-note-retry').addEventListener('click', () => {
if (transport) { location.reload(); return; }
connectLocal().then((local) => local === 'local' ? refresh() : null).catch((error) => localNote(error.message, true));
});
-/** Load an explicitly configured transport before the first read; its updates refresh this page. */
+/** Load the configured decrypting transport once, only when relay reads or pairing need it. */
+let transportLoading = null;
+async function loadTransport() {
+ if (transport) return transport;
+ if (!transportLoading) transportLoading = (async () => {
+ const module = await import(configuredTransportModule);
+ if (typeof module.createTransport !== 'function') throw new Error('The browser transport must export createTransport({ onUpdate }).');
+ const configured = await module.createTransport({ onUpdate: () => transport ? refresh().catch((error) => { $('live').textContent = 'offline: ' + error.message; }) : Promise.resolve() });
+ if (!configured || typeof configured.request !== 'function') throw new Error('The browser transport must provide request(path, body).');
+ transportModule = configuredTransportModule;
+ transport = configured;
+ return transport;
+ })();
+ try { return await transportLoading; }
+ catch (error) { transportLoadError = error; throw error; }
+ finally { transportLoading = null; }
+}
+
+/** Read local boards first; relay-only pages and pairing still load their configured client directly. */
async function startPage() {
- // The hosted page reads this machine's view when it can. When it cannot, it is the relay page as before, for a
- // person signed in to the relay; anyone else sees why, and the ways on.
let local = 'unreachable';
if (hosted.local && !relayPairing) {
if (localProblem) localNote(localProblem, true);
@@ -3402,27 +3431,16 @@ async function startPage() {
if (local === 'away') return;
if (local === 'unreachable' && !hosted.relaySession) { hideRelayNotice(); return; }
}
- if (transportModule) {
- try {
- const module = await import(transportModule);
- if (typeof module.createTransport !== 'function') throw new Error('The browser transport must export createTransport({ onUpdate }).');
- const configured = await module.createTransport({ onUpdate: () => transport ? refresh().catch((error) => { $('live').textContent = 'offline: ' + error.message; }) : Promise.resolve() });
- if (!configured || typeof configured.request !== 'function') throw new Error('The browser transport must provide request(path, body).');
- transport = configured;
- } catch (error) {
- transportLoadError = error;
- if (hosted.local && local === 'local') localNote('Linked boards are unavailable: ' + String(error.message || error), true);
- else throw error;
- }
- }
+ if (hosted.local && local === 'local') transportModule = null;
+ else if (configuredTransportModule) await loadTransport();
await refresh();
}
startPage().catch((error) => { document.body.classList.remove('loading'); $('live').textContent = 'cannot reach the view: ' + error.message; });
// The relay transport keeps its own stream and timer. The local view reads on a timer only while it has no live
// stream, and its live line says so (#545). Each timer asks which the page uses as it fires: the hosted page starts
// out on the relay and turns to this machine's view once it reaches it (#513).
-if (!snapshot) setInterval(() => { if (!document.hidden && transportModule && transport) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, 3000);
-if (!snapshot) setInterval(() => { if (!document.hidden && !transportModule && !connected()) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, FALLBACK_MS);
+if (!snapshot) setInterval(() => { if (!document.hidden && (transport || (hosted.local && hosted.relaySession && configuredTransportModule))) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, 3000);
+if (!snapshot) setInterval(() => { if (!document.hidden && !transport && !(hosted.local && hosted.relaySession && configuredTransportModule) && !connected()) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, FALLBACK_MS);
setInterval(tickAges, 60000);
</script>
</body>
diff --git a/test/cockpit/local-origin.test.js b/test/cockpit/local-origin.test.js
index 00cf566c..17053e8a 100644
--- a/test/cockpit/local-origin.test.js
+++ b/test/cockpit/local-origin.test.js
@@ -83,6 +83,13 @@ async function hostedStandIn(chrome, pages, styles, local) {
body: Buffer.from(reply.body).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'),
+ });
+ }
const document = resourceType === 'Document';
const page = address.search === '?relay' ? pages.relay : pages.anonymous;
await chrome.send('Fetch.fulfillRequest', {
@@ -219,6 +226,19 @@ test('a pullboard.dev page reads the local board [N26,A2]', { timeout: 120_000 }
assert.equal(trips(), 2, 'the page repeated the round trip without the person');
assert.ok(!(await chrome.stable('location.href')).includes(view.key), 'the new secret is gone from the address bar too');
assert.ok(chrome.requests.every((entry) => !new URL(entry.url).search.includes(view.key) && !new URL(entry.url).search.includes(before)), 'neither secret ever rode in a query');
+ // A signed-in person with only local boards has no need for the decrypting relay client. The metadata
+ // read is on the hosted origin and must never carry this machine's local credential.
+ const modulesBefore = relayModule();
+ const metadataBefore = chrome.requests.filter((entry) => entry.url === HOSTED + '/api/v1/boards').length;
+ await chrome.send('Page.navigate', { url: HOSTED + '/?relay' });
+ await chrome.waitFor("location.search === '?relay' && document.querySelector('#chain')?.textContent.includes('A board that stays on this machine')", 20_000); // budget: hang ceiling for a tab-session read and empty linked-board metadata.
+ await chrome.waitFor("(window.__localFetches || []).some((entry) => entry.url === '/api/v1/boards')", 10_000); // budget: hang ceiling for the same-origin metadata request.
+ assert.equal(await chrome.stable('transportModule'), null, 'an empty linked list leaves the relay transport unloaded even when signed in');
+ assert.equal(relayModule(), modulesBefore, 'a local-only signed-in page does not request the relay module');
+ const metadata = chrome.requests.filter((entry) => entry.url === HOSTED + '/api/v1/boards').slice(metadataBefore);
+ assert.ok(metadata.length > 0, 'the signed-in page checked its linked-board metadata');
+ assert.ok(metadata.every((entry) => !Object.keys(entry.headers).some((name) => name.toLowerCase() === 'x-pullboard-key')), 'same-origin metadata never gets the local secret header');
+ assert.equal(await chrome.stable('readOnly'), false, 'the local board remains writable');
assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught exceptions');
} finally {
try { if (stopStandIn) await stopStandIn(); }