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): paint phone screens before async startup [N26,H5,H17]

Corey Olson62dcfeaf8765
diff --git a/relay/browser-client.js b/relay/browser-client.js
index 392f2f7c..a6e067ec 100644
--- a/relay/browser-client.js
+++ b/relay/browser-client.js
@@ -169,13 +169,17 @@ export async function createTransport({ onUpdate = () => {}, onOpenBoard = () =>
try { state = storedOwnedRequestState(localStorage, key, entry.state?.personRequests); } catch { /* Missing device storage can only hide this device's own notice. */ }
ownedRequestIds.set(id, state.owned);
}
- for (const text of noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, warnings, failure })) {
+ const lines = noticeLines({ available, paired, ownedRequestIds, waitingBoards, approvedBoards, warnings, failure });
+ for (const text of lines) {
const paragraph = document.createElement('p');
paragraph.textContent = text;
element.append(paragraph);
}
- // With nothing this device can open, the one-command screen shows; the page's poll fills the board in by itself.
- showRelayScreen(document.documentElement, nothingShared({ paired, waitingBoards, failure }) ? 'share' : null);
+ // A phone has no local-view screen to fall back to: keep its shell and the real reason until a board is readable.
+ const root = document.documentElement;
+ const phoneWaiting = root.dataset.relayDevice === 'phone' && paired.size === 0;
+ showRelayScreen(root, phoneWaiting || nothingShared({ paired, waitingBoards, failure }) ? 'share' : null,
+ phoneWaiting && (failure || waitingBoards.size) ? lines.join(' ') : '');
}
/** Ask once after pairing; a refusal leaves one dismissible line under the board, never above it. */
diff --git a/relay/browser-notice.js b/relay/browser-notice.js
index 161f566a..041ec20a 100644
--- a/relay/browser-notice.js
+++ b/relay/browser-notice.js
@@ -107,7 +107,7 @@ export function relayScreenMarkup(name, signIn) {
+ '<div class="relay-or">or</div>'
+ '<div class="relay-box relay-agent">' + SPEECH + '<span>' + words.agent + '<small>“' + words.ask + '”</small></span><button type="button" data-copy="' + words.ask + '">Copy</button></div>'
+ '<p class="relay-small">' + words.small + '</p>'
- + '<p class="relay-live" role="status"><i aria-hidden="true"></i>' + words.waiting + '</p>'
+ + '<p class="relay-live" role="status"><i aria-hidden="true"></i><span>' + words.waiting + '</span></p>'
+ '</div></section>';
}
@@ -119,10 +119,16 @@ export function nothingShared({ paired, waitingBoards, failure }) {
/**
* Name the first screen the page shows, or none so the board shows. The state is the root's data-relay-screen,
* which the stylesheet reads; clearing it gives back only the screen this transport set.
+ * A phone waiting for its first readable board keeps the actual failure or waiting reason here.
+ * @param {HTMLElement} root - The document's root element.
+ * @param {string|null} name - The first screen, or null when the board can show.
+ * @param {string} [message] - Existing transport guidance to display instead of the default waiting line.
*/
-export function showRelayScreen(root, name) {
+export function showRelayScreen(root, name, message = '') {
if (name) root.dataset.relayScreen = name;
else if (root.dataset.relayScreen === 'share') delete root.dataset.relayScreen;
+ const status = root.querySelector?.('#relay-screen .relay-live span');
+ if (status) status.textContent = message || RELAY_SCREEN_WORDS.share.waiting;
}
/** Copy a screen's sentence or command; a browser without the clipboard API copies from a selected field. */
diff --git a/relay/browser-page.js b/relay/browser-page.js
index 58aac1be..85d5c41c 100644
--- a/relay/browser-page.js
+++ b/relay/browser-page.js
@@ -14,11 +14,11 @@ const SIGN_IN_TRANSPORT = '/** Preserve device-only pairing before sign-in witho
/**
* Name the device before first paint: a phone or tablet (a coarse pointer and no hover) never runs Pullboard, so
- * signed out it shows the sign-in screen and nothing about this computer. A computer keeps the page's own states.
+ * it shows its signed-in or sign-in screen before any asynchronous probe. A computer keeps the page's own states.
*/
function deviceScript(relaySession) {
return "(() => { const root = document.documentElement; if (!matchMedia('(pointer: coarse)').matches || !matchMedia('(hover: none)').matches) return;"
- + " root.dataset.relayDevice = 'phone';" + (relaySession ? '' : " root.dataset.relayScreen = 'sign-in';") + ' })();';
+ + " root.dataset.relayDevice = 'phone'; root.dataset.relayScreen = '" + (relaySession ? 'share' : 'sign-in') + "'; })();";
}
/** Serve a fixed asset with cache and browser isolation boundaries, never a filesystem-derived URL. */
diff --git a/test/relay-person-page.test.js b/test/relay-person-page.test.js
index 7129cffb..780e847e 100644
--- a/test/relay-person-page.test.js
+++ b/test/relay-person-page.test.js
@@ -8,9 +8,72 @@ import { cockpitPage } from '../src/cockpit.js';
import { ENGINE_VERSION } from '../src/machine.js';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
import { relayClientFixture } from './relay-client-fixture.js';
+import { createRelayBrowserHandler } from '../relay/browser-page.js';
const chromeOptions = { skip: !findChromeExecutable() && 'Chrome is not installed' };
+test('a signed-in phone shows its first screen before a local probe can answer [N26,H5,H17]', chromeOptions, async t => {
+ const handle = createRelayBrowserHandler({ authenticate: async () => ({ kind: 'session' }) });
+ const server = createServer(async (req, res) => {
+ if (!await handle(req, res)) { res.writeHead(404); res.end(); }
+ });
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+ t.after(async () => { server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); });
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
+ await chrome.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', {
+ source: 'window.fetch = () => new Promise(() => {});',
+ });
+ const origin = 'http://127.0.0.1:' + server.address().port;
+ await chrome.navigate(origin);
+ await chrome.waitFor("document.readyState === 'complete' && document.documentElement.dataset.relayDevice === 'phone'");
+ const first = await chrome.evaluate(`({
+ screen: document.documentElement.dataset.relayScreen ?? null,
+ visible: document.querySelector('#relay-screen h1')?.getClientRects().length > 0,
+ text: document.body.innerText,
+ })`);
+ assert.equal(first.screen, 'share', 'a signed-in phone gets its screen before any asynchronous probe or board read');
+ assert.equal(first.visible, true, 'the screen heading is painted, not merely present in hidden markup');
+ assert.match(first.text, /One step on your computer/u);
+});
+
+test('a phone keeps its screen and the reason while a saved board fails or waits [N26,H5,H17]', chromeOptions, async t => {
+ let code = 'BAD_SNAPSHOT';
+ const handle = createRelayBrowserHandler({ authenticate: async () => ({ kind: 'session' }) });
+ const server = createServer(async (req, res) => {
+ if (req.url.startsWith('/api/') || req.url.startsWith('/auth/')) {
+ const body = req.url.endsWith('/state') ? { version: 1, error: { code, message: 'Fixture snapshot is unavailable.' } }
+ : { version: 1, boards: [{ id: 'a'.repeat(32), repository: 'fixture/project' }], warnings: [] };
+ res.writeHead(req.url.endsWith('/state') ? 404 : 200, { 'content-type': 'application/json' });
+ res.end(JSON.stringify(body));
+ } else if (!await handle(req, res)) { res.writeHead(404); res.end(); }
+ });
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+ t.after(async () => { server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); });
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true });
+ await chrome.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', {
+ source: `localStorage.setItem('pullboard.relay.keys.v1', JSON.stringify({ ['a'.repeat(32)]: btoa('x'.repeat(32)).replaceAll('=', '') }));
+const nativeFetch = window.fetch;
+window.fetch = (input, options) => String(input).startsWith('http://127.0.0.1:4890/')
+ ? Promise.reject(new TypeError('Fixture has no local view')) : nativeFetch(input, options);`,
+ });
+ const origin = 'http://127.0.0.1:' + server.address().port;
+ for (const [failure, expected] of [['BAD_SNAPSHOT', 'Could not open this board'], ['NO_SNAPSHOT', 'waiting for its first snapshot']]) {
+ code = failure;
+ await chrome.navigate('about:blank');
+ await chrome.navigate(origin);
+ await chrome.waitFor(`document.querySelector('#relay-notice')?.textContent.includes(${JSON.stringify(expected)})`);
+ const shown = await chrome.evaluate(`({ text: document.body.innerText, screen: document.documentElement.dataset.relayScreen ?? null })`);
+ assert.equal(shown.screen, 'share', 'an unreadable saved board cannot dismiss the phone screen');
+ assert.ok(shown.text.includes(expected), 'the person can read the actual reason, not just hidden banner markup');
+ }
+});
+
test("the relay page opens without a session and may call only the local view's default port [N26,H5,A2]", async t => {
const box = await relayClientFixture(t);
const privateTitle = 'PRIVATE_RELAY_BOARD_533';