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): the hosted page holds its mark until the list answers [N26]

Corey Olsonc38a5f6265b7
diff --git a/src/cockpit.js b/src/cockpit.js
index 827c91d3..46a7be6c 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -353,8 +353,6 @@ const drawHosted = (${drawHosted.toString()});
* page names before first paint (#757), and it hears nothing about this computer.
*/
function localNote(state, facts = {}) {
- // Until the page knows which screen applies, the neutral mark stays and no other screen shows.
- if (!['looking', 'asking'].includes(state)) document.body.classList.remove('loading');
drawHosted(document, hostedState(state, { browser: hostedBrowser(navigator), phone: document.documentElement.dataset.relayDevice === 'phone', ...facts }), { view: localSession?.origin || LOCAL_VIEW, signIn: hosted.signIn, session: hosted.relaySession });
}
@@ -3971,15 +3969,17 @@ async function startPage() {
if (hosted.local && !relayPairing) {
if (localProblem) localNote('problem', { detail: localProblem });
else local = await connectLocal();
- if (local === 'away') return;
- if (local === 'unreachable' && !hosted.relaySession) { hideRelayNotice(); return; }
+ if (local === 'away') { document.body.classList.remove('loading'); return; }
+ if (local === 'unreachable' && !hosted.relaySession) { document.body.classList.remove('loading'); hideRelayNotice(); return; }
}
if (hosted.local && local === 'local') transportModule = null;
else if (configuredTransportModule) {
// Signed out, a pairing link waits for sign-in, which its own state asks for.
- try { await loadTransport(); } catch (error) { if (!hosted.local || hosted.relaySession) throw error; localNote('signed-out'); return; }
+ try { await loadTransport(); } catch (error) { if (!hosted.local || hosted.relaySession) throw error; document.body.classList.remove('loading'); localNote('signed-out'); return; }
}
+ // The page shows its screen only once the remote list has answered or failed, so the mark holds until then (#932).
await refresh();
+ document.body.classList.remove('loading');
}
startPage().catch((error) => {
document.body.classList.remove('loading');
diff --git a/test/cockpit/local-origin.test.js b/test/cockpit/local-origin.test.js
index a7766826..01dd8f52 100644
--- a/test/cockpit/local-origin.test.js
+++ b/test/cockpit/local-origin.test.js
@@ -1133,17 +1133,18 @@ test('a hosted wait that times out names the page state and Chrome\'s network se
}
});
-test('the hosted page paints no other screen before the one it settles on [N26,H5]', { timeout: 180_000 }, async () => { // budget: hang ceiling for three hosted page loads in Chrome, each recorded from its first frame.
+test('the hosted page paints no other screen before the one it settles on [N26,H5]', { timeout: 300_000 }, async () => { // budget: hang ceiling for four hosted page loads in Chrome, one holding the relay client for 800 ms.
const executable = chromeExecutable();
assert.ok(executable, 'the hosted page check needs real Chrome');
const box = machine();
project(box, 'first-frame');
const profile = mkdtempSync(join(tmpdir(), 'pullboard-first-frame-'));
const relay = createRelayBrowserHandler({ authenticate: async () => { if (stand.signedIn) return { kind: 'session' }; throw new Refused('AUTH_REQUIRED', 'Sign in.'); } });
- // The three states: signed out; signed in with nothing shared; signed in with a board on this machine.
- const stand = { signedIn: false, linked: [], local: null };
+ // What the stand-in answers for each state: whether the person is signed in, the account's linked boards, this
+ // machine's view (closed unless named), and how long the relay client's response is held.
+ const stand = { signedIn: false, linked: [], local: null, holdClient: 0 };
const client = 'export function rememberPairing() { return null; }\nexport async function createTransport() { return { async request(path) { if (path === "/api/v1/boards") return { version: 1, boards: [], warnings: [] }; throw new Error("no paired board"); } }; }\n';
- // Recorded in the page from its first frame: which screens are shown, in order, each change once.
+ // Recorded in the page from its first frame: each screen shown, in order, with each change recorded once.
const recorder = `(() => {
if (location.origin !== ${JSON.stringify(HOSTED)}) return;
const shown = (element) => Boolean(element) && getComputedStyle(element).display !== 'none' && element.getClientRects().length > 0;
@@ -1163,7 +1164,8 @@ test('the hosted page paints no other screen before the one it settles on [N26,H
const tick = () => { sample(); requestAnimationFrame(tick); };
requestAnimationFrame(tick);
})()`;
- let view, chrome, listener, granted = false;
+ const pause = (ms) => new Promise((done) => setTimeout(done, ms));
+ let view, chrome, listener;
try {
view = await startView(box);
chrome = namedWaits(await openSnapshotChrome(executable, 'about:blank', profile), profile);
@@ -1179,7 +1181,7 @@ test('the hosted page paints no other screen before the one it settles on [N26,H
const reply = await call({ base: stand.local }, address.pathname + address.search, { method: asked.method, headers: Object.fromEntries(Object.entries(asked.headers).filter(([name]) => name.toLowerCase() !== 'host')) });
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') });
}
- if (address.pathname === '/relay/client.js') return fulfil('text/javascript', client);
+ if (address.pathname === '/relay/client.js') { if (stand.holdClient) await pause(stand.holdClient); return fulfil('text/javascript', client); }
if (address.pathname === '/api/v1/boards') return fulfil('application/json', JSON.stringify({ version: 1, boards: stand.linked, warnings: [] }));
let head = {}, body = '';
const handled = await relay({ method: 'GET', url: address.pathname, headers: {} }, { writeHead: (status, headers) => { head = headers; }, end: (content) => { body = content ?? ''; } });
@@ -1191,22 +1193,26 @@ test('the hosted page paints no other screen before the one it settles on [N26,H
chrome.socket.addEventListener('message', listener);
await chrome.send('Fetch.enable', { patterns: [{ urlPattern: HOSTED + '/*', requestStage: 'Request' }, { urlPattern: LOCAL + '/*', requestStage: 'Request' }] });
await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: recorder });
- const load = async (name, address, settle) => {
+ /** Navigate to a state, wait for the real navigation and for the page to settle, then read every screen it showed. */
+ const load = async (name, address) => {
await chrome.send('Page.navigate', { url: HOSTED + '/' + address });
- await chrome.waitFor(`location.origin === ${JSON.stringify(HOSTED)} && document.body && !document.body.classList.contains('loading') && ${settle}`, 30_000); // budget: hang ceiling for one hosted load in Chrome until its screen settles.
+ await chrome.waitFor(`location.origin === ${JSON.stringify(HOSTED)} && document.readyState === 'complete' && document.body && !document.body.classList.contains('loading')`, 60_000); // budget: hang ceiling for one hosted load, including the held relay client.
+ await pause(1500);
const screens = JSON.parse(await chrome.stable('JSON.stringify(window.__screens)'));
return { name, screens };
};
const results = [];
- stand.signedIn = false; stand.linked = []; stand.local = null;
- results.push(await load('signed out', '?out', 'true'));
- stand.signedIn = true; stand.linked = []; stand.local = null;
- results.push(await load('signed in, nothing shared', '?in', 'true'));
- stand.signedIn = false; stand.linked = []; stand.local = view.base;
+ Object.assign(stand, { signedIn: false, linked: [], local: null, holdClient: 0 });
+ results.push(await load('signed out', '?out'));
+ Object.assign(stand, { signedIn: true, linked: [], local: null, holdClient: 0 });
+ results.push(await load('signed in, nothing shared', '?in'));
+ Object.assign(stand, { signedIn: true, linked: [], local: null, holdClient: 800 });
+ results.push(await load('signed in, nothing shared, relay client held 800 ms', '?held'));
+ Object.assign(stand, { signedIn: true, linked: [], local: view.base, holdClient: 0 });
for (const permissions of [['loopbackNetwork', 'localNetwork', 'localNetworkAccess'], ['localNetworkAccess']]) {
- try { await chrome.send('Browser.grantPermissions', { origin: HOSTED, permissions }); granted = true; break; } catch { /* a name this Chrome does not have */ }
+ try { await chrome.send('Browser.grantPermissions', { origin: HOSTED, permissions }); break; } catch { /* a name this Chrome does not have */ }
}
- results.push(await load('signed in, with a board', '?board', 'true'));
+ results.push(await load('signed in, with a board', '?board'));
for (const { name, screens } of results) {
assert.equal(screens[0], 'mark', `${name}: the first frame is the neutral mark, not another screen (${JSON.stringify(screens)})`);
assert.ok(screens.slice(0, -1).every((screen) => screen === 'mark'), `${name}: every frame before the settled screen is the neutral mark (${JSON.stringify(screens)})`);
@@ -1221,5 +1227,4 @@ test('the hosted page paints no other screen before the one it settles on [N26,H
finally { rmSync(profile, { recursive: true, force: true }); }
}
}
- void granted;
});