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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(view): isolate configured transport startup [N26,N27]
Corey Olson858cf48e57f8
diff --git a/src/cockpit.js b/src/cockpit.jsindex 6b8eaca5..3514cc24 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -149,6 +149,7 @@ const readOnly = ${JSON.stringify(readOnly)};const transportModule = ${moduleOption};const connection = ${connection};let transport = null;+let transportLoadError = null;const snapshotReplay = { final: null, events: [], index: 0, playing: false, timer: null };const keep = (name, value) => { name = snapshot ? 'snapshot.' + name : name; try { if (value === undefined) return localStorage.getItem(name); localStorage.setItem(name, value); } catch { return null; } return value; };// Whether the host serves this page at /roadmap as well as at /, so the Roadmap's address is a path;@@ -450,7 +451,11 @@ function flowSvg(p) {/** Read or move through API v1, retaining the rule and repair guidance in a refusal. */async function api(path, body) {if (body && (snapshot || readOnly)) throw new Error(snapshot ? 'This is a read-only snapshot.' : 'This is a read-only view.');- if (transport) return transport.request(path, body);+ if (transportModule) {+ if (transport) return transport.request(path, body);+ if (transportLoadError) throw transportLoadError;+ throw new Error('The browser transport is still loading.');+ }path = snapshot ? path.split('?')[0].slice(1) + '.json' : connection.base + path;const res = await fetch(path, { method: body ? 'POST' : 'GET', headers: snapshot ? {} : { ...connection.headers, ...(body ? { 'content-type': 'application/json' } : {}) }, body: body ? JSON.stringify(body) : undefined });const json = await res.json();@@ -1338,15 +1343,21 @@ if (snapshot) {/** Load an explicitly configured transport before the first read; its updates refresh this page. */async function startPage() {if (transportModule) {- const module = await import(transportModule);- if (typeof module.createTransport !== 'function') throw new Error('The browser transport must export createTransport({ onUpdate }).');- transport = await module.createTransport({ onUpdate: () => transport ? refresh().catch((error) => { $('live').textContent = 'offline: ' + error.message; }) : Promise.resolve() });- if (!transport || typeof transport.request !== 'function') throw new Error('The browser transport must provide request(path, body).');+ 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;+ throw error;+ }}await refresh();}startPage().catch((error) => { document.body.classList.remove('loading'); $('live').textContent = 'cannot reach the view: ' + error.message; });-if (!snapshot) setInterval(() => { if (!document.hidden) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, 3000);+if (!snapshot) setInterval(() => { if (!document.hidden && (!transportModule || transport)) refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }); }, 3000);setInterval(tickAges, 60000);</script></body>diff --git a/test/cockpit.test.js b/test/cockpit.test.jsindex 6e7272a2..901c00d2 100644--- a/test/cockpit.test.js+++ b/test/cockpit.test.js@@ -2750,6 +2750,109 @@ test('read-only pages use a local browser transport and refresh on its updates [}});+test('a configured transport never falls back while loading or after import failure [N26,N27]', { timeout: 90_000 }, async (t) => {+ const executable = chromeExecutable();+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for the transport startup proof.');++ const box = machine();+ const demo = project(box, 'transport-startup');+ box.run(demo.repo, 'add', 'web', 'Transport startup item', '--specs', 'G1', '--criterion', 'loads through the configured transport');+ const live = await startView(box);+ const slowPage = cockpitPage('', { transportModule: '/slow-transport.js' });+ const failedPage = cockpitPage('', { transportModule: '/failed-transport.js' });+ const localRequests = [];+ const relayRequests = [];+ let slowModuleRequested;+ const requested = new Promise((resolve) => { slowModuleRequested = resolve; });+ let releaseSlowModule;+ const slowModuleBarrier = new Promise((resolve) => { releaseSlowModule = resolve; });+ const transportSource = `export async function createTransport() {+ window.__transportReady = true;+ window.__transportCalls = [];+ return { async request(path, body) {+ window.__transportCalls.push(path);+ const response = await fetch('/relay' + path, { method: body ? 'POST' : 'GET', body: body ? JSON.stringify(body) : undefined });+ return response.json();+ } };+ }`;+ const server = createServer(async (request, response) => {+ const url = new URL(request.url, 'http://127.0.0.1');+ if (url.pathname === '/slow' || url.pathname === '/failed') {+ response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });+ response.end(url.pathname === '/slow' ? slowPage : failedPage);+ return;+ }+ if (url.pathname === '/slow-transport.js') {+ slowModuleRequested();+ await slowModuleBarrier;+ response.writeHead(200, { 'content-type': 'text/javascript; charset=utf-8' });+ response.end(transportSource);+ return;+ }+ if (url.pathname === '/failed-transport.js') {+ response.writeHead(200, { 'content-type': 'text/javascript; charset=utf-8' });+ response.end("throw new Error('fixture transport import failed');");+ return;+ }+ if (url.pathname === '/view.css') {+ response.writeHead(200, { 'content-type': 'text/css; charset=utf-8' });+ response.end(readFileSync(new URL('../src/view.css', import.meta.url), 'utf8'));+ return;+ }+ if (url.pathname.startsWith('/relay/')) {+ const path = url.pathname.slice('/relay'.length) + url.search;+ relayRequests.push(path);+ try {+ const reply = await fetch(live.base + path, { headers: { 'x-pullboard-key': live.key } });+ response.writeHead(reply.status, { 'content-type': 'application/json' });+ response.end(await reply.text());+ } catch (error) {+ response.writeHead(502, { 'content-type': 'application/json' });+ response.end(JSON.stringify({ error: String(error.message || error) }));+ }+ return;+ }+ if (url.pathname.startsWith('/api/v1/')) {+ localRequests.push(url.pathname);+ response.writeHead(503, { 'content-type': 'application/json' });+ response.end(JSON.stringify({ error: { code: 'LOCAL_FALLBACK', message: 'the page-local API must not be used' } }));+ return;+ }+ response.writeHead(404).end();+ });+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-transport-startup-chrome-'));+ let chrome;+ try {+ const origin = `http://127.0.0.1:${server.address().port}`;+ chrome = await openSnapshotChrome(executable, `${origin}/slow`, profile);+ await requested;+ const loadingCall = await chrome.evaluate("api('/api/v1/boards').then(() => 'unexpected success', error => error.message)");+ assert.match(loadingCall, /transport.*loading/i, 'direct API calls refuse while the configured module is loading');+ await browserPause(3200);+ assert.equal(await chrome.evaluate('window.__transportReady === true'), false, 'the delayed module is still loading during the proof');+ assert.deepEqual(localRequests, [], 'neither direct reads nor the poll fall back while loading');++ releaseSlowModule();+ await chrome.waitFor('window.__transportReady === true && !!data?.project');+ assert.ok(relayRequests.includes('/api/v1/boards'), 'the initial board read uses the configured transport');+ assert.deepEqual(localRequests, [], 'loading the configured module never touched the page-local API');++ await chrome.send('Page.navigate', { url: `${origin}/failed` });+ await chrome.waitFor("document.querySelector('#live').textContent.includes('fixture transport import failed')");+ await browserPause(3200);+ assert.match(await chrome.evaluate("document.querySelector('#live').textContent"), /cannot reach the view: fixture transport import failed/,+ 'the original module error remains visible after later poll intervals');+ assert.deepEqual(localRequests, [], 'a failed import also disables page-local polling');+ } finally {+ releaseSlowModule();+ if (chrome) await closeSnapshotChrome(chrome);+ await live.stop();+ await new Promise((resolve) => server.close(resolve));+ rmSync(profile, { recursive: true, force: true });+ }+});+test('real Chrome keeps the demo board usable at phone and desktop widths [H5,N26,N27]', { timeout: 120_000 }, async (t) => {const executable = chromeExecutable();if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for viewport checks.');