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(relay): settle signed-out pages on sign-in [N26,H5,A2]

Corey Olson188b64c00296
diff --git a/relay/browser-page.js b/relay/browser-page.js
index 1be4ddf9..27f65421 100644
--- a/relay/browser-page.js
+++ b/relay/browser-page.js
@@ -7,6 +7,9 @@ import { Refused } from '../src/refused.js';
const STYLES = readFileSync(new URL('../src/view.css', import.meta.url), 'utf8');
+/** Refuse relay startup locally while the public shell has no relay session; keep its sign-in link and never reload. */
+const SIGN_IN_TRANSPORT = '/** A signed-out shell has no relay transport to start. */\nexport function createTransport() {\n throw new Error("Sign in with GitHub to open your linked boards.");\n}\n';
+
/** Serve a fixed asset with cache and browser isolation boundaries, never a filesystem-derived URL. */
function respond(res, type, content, scriptHashes = []) {
const hashes = scriptHashes.map(hash => "'sha256-" + hash + "'").join(' ');
@@ -26,6 +29,7 @@ export function createRelayBrowserHandler({ authenticate }) {
['/relay/relay-approval.js', ['text/javascript', readFileSync(new URL('../src/relay-approval.js', import.meta.url), 'utf8').replace("'./relay-device-keys.js'", "'./device-keys.js'")]],
['/relay/browser-devices.js', ['text/javascript', readFileSync(new URL('./browser-devices.js', import.meta.url), 'utf8')]],
['/relay/client.js', ['text/javascript', readFileSync(new URL('./browser-client.js', import.meta.url), 'utf8')]],
+ ['/relay/sign-in.js', ['text/javascript', SIGN_IN_TRANSPORT]],
['/relay/browser-notice.js', ['text/javascript', readFileSync(new URL('./browser-notice.js', import.meta.url), 'utf8')]],
['/relay/browser-stream.js', ['text/javascript', readFileSync(new URL('./browser-stream.js', import.meta.url), 'utf8')]],
['/relay/model.js', ['text/javascript', readFileSync(new URL('./browser-model.js', import.meta.url), 'utf8').replace("'../src/refused.js'", "'./refused.js'")]],
@@ -54,7 +58,7 @@ export function createRelayBrowserHandler({ authenticate }) {
}
const notice = relaySession ? '<p>Pairing this browser…</p>'
: '<p>Connecting to this machine. Sign in to see your linked boards.</p><a href="/auth/github/start">Sign in with GitHub</a>';
- const page = cockpitPage('', { readOnly: true, requests: true, transportModule: '/relay/client.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' })
+ const page = cockpitPage('', { readOnly: true, requests: relaySession, transportModule: relaySession ? '/relay/client.js' : '/relay/sign-in.js', apiHeaders: {}, stylesheet: '/view.css', hostedLocal: true, relaySession, signIn: '/auth/github/start' })
.replace('<main>', '<main><section class="card-panel" id="relay-notice" role="status">' + notice + '</section>');
const scripts = [...page.matchAll(/<script>([\s\S]*?)<\/script>/g)].map(match => createHash('sha256').update(match[1]).digest('base64'));
respond(res, 'text/html', page, scripts);
diff --git a/test/relay-browser-fixture.test.js b/test/relay-browser-fixture.test.js
index 19b66d26..82287919 100644
--- a/test/relay-browser-fixture.test.js
+++ b/test/relay-browser-fixture.test.js
@@ -87,8 +87,7 @@ test('relay idle readiness waits for a real held request and then observes its c
await box.link();
const chrome = await startChrome();
t.after(() => chrome.close());
- // Measure only the held request on a static same-origin document, without cockpit startup traffic.
- await chrome.navigate(box.origin + '/view.css');
+ await chrome.navigate(box.origin);
await chrome.waitFor('document.readyState === "complete"');
const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
const release = box.holdStateReads();
diff --git a/test/relay-person-page.test.js b/test/relay-person-page.test.js
index 781c4088..7129cffb 100644
--- a/test/relay-person-page.test.js
+++ b/test/relay-person-page.test.js
@@ -36,6 +36,91 @@ test("the relay page opens without a session and may call only the local view's
assert.match(page, /Sign in with GitHub/u, 'relay mode retains its sign-in path');
});
+
+test('a signed-out relay page keeps sign-in visible without starting relay reads [N26,H5,A2]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+}, async t => {
+ const box = await relayClientFixture(t);
+ const privateTitle = 'PRIVATE_RELAY_BOARD_533_ANONYMOUS';
+ assert.equal((await box.cli('add', box.lane, privateTitle)).code, 0);
+ await box.link();
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const privateKey = readFileSync(box.keyFile, 'utf8').trim();
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Page.enable', {});
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', {
+ source: "try { sessionStorage.setItem('relayAnonymousDocumentCount', String(Number(sessionStorage.getItem('relayAnonymousDocumentCount') || 0) + 1)); } catch {}",
+ });
+ const firstCall = box.calls.length;
+ await chrome.navigate(box.origin + '/');
+ // Budget: six seconds reproduce the reviewed reload loop and span a relay refresh interval.
+ await new Promise(resolve => setTimeout(resolve, 6000));
+ const calls = box.calls.slice(firstCall);
+ assert.equal(calls.filter(call => call.method === 'GET' && call.path === '/').length, 1,
+ 'the anonymous shell does not reload');
+ await chrome.waitFor("document.readyState === 'complete' && !!document.querySelector('a[href=\"/auth/github/start\"]')");
+ const loads = await chrome.evaluate("Number(sessionStorage.getItem('relayAnonymousDocumentCount') || 0)");
+ const privateValues = [privateTitle, link.board, privateKey, link.token];
+ const retained = await chrome.evaluate(`({ html: document.documentElement.innerHTML,
+ local: JSON.stringify(localStorage), session: JSON.stringify(Object.fromEntries(
+ Array.from({ length: sessionStorage.length }, (_, index) => {
+ const key = sessionStorage.key(index); return [key, sessionStorage.getItem(key)];
+ }).filter(([key]) => key !== 'relayAnonymousDocumentCount'))) })`);
+ assert.equal(loads, 1, 'the anonymous shell does not reload');
+ assert.equal(calls.filter(call => call.method === 'GET' && call.path === '/api/v1/boards').length, 0,
+ 'the anonymous shell never starts relay board reads');
+ assert.equal(await chrome.evaluate("!!document.querySelector('a[href=\"/auth/github/start\"]')"), true,
+ 'the original sign-in link remains available');
+ assert.equal([retained.html, retained.local, retained.session].some(value => privateValues.some(secret => value.includes(secret))), false,
+ 'the anonymous page and its browser storage retain no private board or credential value');
+});
+
+test('a revoked relay session settles on sign-in without a reload loop [N26,H5,A2]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+}, async t => {
+ const box = await relayClientFixture(t);
+ const privateTitle = 'PRIVATE_RELAY_BOARD_533_REVOKED';
+ assert.equal((await box.cli('add', box.lane, privateTitle)).code, 0);
+ await box.link();
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const privateKey = readFileSync(box.keyFile, 'utf8').trim();
+ const phone = await box.phoneSession();
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Page.enable', {});
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', {
+ source: "try { sessionStorage.setItem('relayRevokedDocumentCount', String(Number(sessionStorage.getItem('relayRevokedDocumentCount') || 0) + 1)); } catch {}",
+ });
+ const cookie = await chrome.send('Network.setCookie', {
+ name: 'pb_session', value: phone.token, url: box.origin, httpOnly: true, sameSite: 'Lax',
+ });
+ assert.equal(cookie.success, true);
+ box.revokeSessionOnNextListing();
+ const firstCall = box.calls.length;
+ await chrome.navigate(box.origin + '/');
+ await chrome.waitFor("document.readyState === 'complete' && !!document.querySelector('a[href=\"/auth/github/start\"]')");
+ // Budget: six seconds after reaching sign-in span a relay refresh interval.
+ await new Promise(resolve => setTimeout(resolve, 6000));
+ const loads = await chrome.evaluate("Number(sessionStorage.getItem('relayRevokedDocumentCount') || 0)");
+ const calls = box.calls.slice(firstCall);
+ const privateValues = [privateTitle, link.board, privateKey, link.token, phone.token];
+ const retained = await chrome.evaluate(`({ html: document.documentElement.innerHTML,
+ local: JSON.stringify(localStorage), session: JSON.stringify(Object.fromEntries(
+ Array.from({ length: sessionStorage.length }, (_, index) => {
+ const key = sessionStorage.key(index); return [key, sessionStorage.getItem(key)];
+ }).filter(([key]) => key !== 'relayRevokedDocumentCount'))) })`);
+ assert.equal(loads, 2, 'one authorization loss leads to one signed-out document');
+ assert.equal(calls.filter(call => call.method === 'GET' && call.path === '/').length, 2,
+ 'the authenticated page redirects once to the signed-out entry');
+ assert.equal(calls.filter(call => call.method === 'GET' && call.path === '/api/v1/boards').length, 1,
+ 'the invalidated session produces no repeated board listings');
+ assert.equal(await chrome.evaluate("!!document.querySelector('a[href=\"/auth/github/start\"]') && !!document.querySelector('#relay-notice')"), true,
+ 'the signed-out notice and original sign-in link remain visible');
+ assert.equal([retained.html, retained.local, retained.session].some(value => privateValues.some(secret => value.includes(secret))), false,
+ 'the signed-out page and browser storage retain no private board or credential value');
+});
+
test('relay data still needs a session [N26,H5,A2]', async t => {
const box = await relayClientFixture(t);
const before = (await box.cli('export')).document.tables;