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.

test(view): define paired LAN board access [H19]

Corey Olsonc98d49e10f71
diff --git a/test/cockpit/lan-fixture.js b/test/cockpit/lan-fixture.js
new file mode 100644
index 00000000..18ffbc68
--- /dev/null
+++ b/test/cockpit/lan-fixture.js
@@ -0,0 +1,65 @@
+/** Own one private LAN view process without logging its pairing link [H19,C7]. */
+import assert from 'node:assert/strict';
+import { spawn } from 'node:child_process';
+import { BIN } from './fixture.js';
+
+/** Start the actual CLI, register cleanup before startup, and keep its private link in memory. */
+export async function startLanView(t, box) {
+ const child = spawn(process.execPath, [BIN, 'view', '--lan', '--no-open', '--port', '0'], {
+ cwd: box.dir, env: { ...box.env, PULLBOARD_VIEW_FOREGROUND: '1' }, stdio: ['ignore', 'pipe', 'pipe'],
+ });
+ let stopped;
+ /** Stop only the process this fixture started, including a failed startup. */
+ const stop = () => stopped ??= new Promise(done => {
+ if (child.exitCode !== null || child.signalCode !== null) return done();
+ child.once('close', done);
+ child.kill('SIGTERM');
+ });
+ t.after(stop);
+ return await new Promise((resolve, reject) => {
+ let output = '', failure = '';
+ const timer = setTimeout(() => { void stop(); reject(new Error('the LAN view did not print its link before the startup deadline')); },
+ 35_000); // budget: the CLI's registry-lock ceiling and normal background startup allowance.
+ child.stderr.setEncoding('utf8');
+ child.stderr.on('data', part => { failure += part; });
+ child.stdout.setEncoding('utf8');
+ child.stdout.on('data', part => {
+ output += part;
+ const match = /Pullboard view: (http:\/\/[^\s]+\/\?k=[^\s]+)/u.exec(output);
+ if (!match) return;
+ clearTimeout(timer);
+ const link = new URL(match[1]);
+ resolve({ link, base: link.origin, key: link.searchParams.get('k'), stop });
+ });
+ child.once('error', () => { clearTimeout(timer); reject(new Error('the LAN view process could not start')); });
+ child.once('exit', code => {
+ clearTimeout(timer);
+ // Startup errors may contain a private link; report only the typed refusal or an option error.
+ const reason = /\[([A-Z_]+)\]/u.exec(failure)?.[1]
+ ?? (/Unknown option/u.test(failure) ? 'unknown CLI option' : 'unclassified startup failure');
+ reject(new Error(`the LAN view exited before startup (${code}; ${reason})`));
+ });
+ });
+}
+
+/** A real HTTP request with an explicit Host, so a refusal cannot be confused with DNS failure. */
+export async function lanBoundaryReply(view, path, headers = {}) {
+ const { request } = await import('node:http');
+ return await new Promise((resolve, reject) => {
+ const call = request(new URL(path, view.base), { headers, agent: false }, response => {
+ const chunks = [];
+ response.on('data', chunk => chunks.push(chunk));
+ response.once('end', () => resolve({ status: response.statusCode, body: Buffer.concat(chunks).toString('utf8') }));
+ });
+ call.once('error', reject);
+ call.setTimeout(10_000, () => call.destroy(new Error('the LAN boundary request did not finish'))); // budget: bounded refusal hang ceiling.
+ call.end();
+ });
+}
+
+/** Refusals must carry neither a board title nor the secret needed to open its view. */
+export function assertLanRefusal(reply, view, title) {
+ assert.ok([401, 403].includes(reply.status), 'an unauthenticated or foreign-origin request is refused');
+ assert.equal(reply.body.includes(title), false, 'the refusal contains no board data');
+ assert.equal(reply.body.includes(view.key), false, 'the refusal contains no pairing secret');
+}
diff --git a/test/cockpit/lan.test.js b/test/cockpit/lan.test.js
new file mode 100644
index 00000000..39e058aa
--- /dev/null
+++ b/test/cockpit/lan.test.js
@@ -0,0 +1,70 @@
+/** @pullboard-test-gui */
+/** A private board is usable through its actual LAN address, with explicit pairing authority [H19]. */
+import assert from 'node:assert/strict';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { networkInterfaces, tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import {
+ chromeExecutable, closeSnapshotChrome, fetchLive, machine, openSnapshotChrome, project, startView,
+} from './fixture.js';
+import { assertLanRefusal, lanBoundaryReply, startLanView } from './lan-fixture.js';
+
+test('a phone reaches the board on the local network [H19]', { timeout: 180_000 }, async t => { // budget: one real private board, two owned view listeners and a mobile Chrome session.
+ const box = machine();
+ const alpha = project(box, 'private-lan-fixture');
+ const title = 'LAN fixture obligation';
+ box.run(alpha.repo, 'add', 'web', title, '--specs', 'G1', '--criterion', 'remains visible to its paired person');
+ const view = await startLanView(t, box);
+ const assigned = Object.values(networkInterfaces()).flat().filter(row => row && row.family === 'IPv4' && !row.internal)
+ .map(row => row.address);
+ assert.ok(assigned.includes(view.link.hostname), 'the printed link names an assigned non-loopback interface');
+ assert.ok(view.key && view.key.length >= 24, 'the pairing code has at least 144 bits of random capacity');
+ assert.notEqual(view.link.hostname, '0.0.0.0', 'a wildcard bind is never printed as a usable address');
+
+ const headers = { 'x-pullboard-key': view.key };
+ const boardsReply = await fetchLive(view.base + '/api/v1/boards', { headers });
+ assert.equal(boardsReply.status, 200, 'the authenticated API answers on the actual LAN interface');
+ const boards = (await boardsReply.json()).boards;
+ assert.deepEqual(boards.map(board => board.root), [alpha.repo], 'only the private fixture is exposed');
+ for (const [path, requestHeaders] of [
+ ['/', {}], ['/api/v1/boards', {}], ['/?k=invalid-fixture-code', {}],
+ ['/api/v1/boards', { 'x-pullboard-key': 'invalid-fixture-code' }],
+ ['/', { ...headers, host: 'foreign.invalid:' + view.link.port }],
+ ['/api/v1/boards', { ...headers, host: 'foreign.invalid:' + view.link.port }],
+ ['/', { ...headers, origin: 'https://foreign.invalid' }],
+ ['/api/v1/boards', { ...headers, origin: 'https://foreign.invalid' }],
+ ['/local/view', {}], ['/local/connect', {}],
+ ]) assertLanRefusal(await lanBoundaryReply(view, path, requestHeaders), view, title);
+
+ const executable = chromeExecutable();
+ assert.ok(executable, 'real Chrome is required for the mobile LAN view');
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-lan-chrome-'));
+ let chrome;
+ t.after(async () => { if (chrome) await closeSnapshotChrome(chrome); rmSync(profile, { recursive: true, force: true }); });
+ chrome = await openSnapshotChrome(executable, view.link.href, profile);
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 375, height: 812, deviceScaleFactor: 1, mobile: false });
+ await chrome.waitFor(`innerWidth === 375 && document.body.innerText.includes(${JSON.stringify(title)})`);
+ assert.equal(await chrome.stable('location.hostname'), view.link.hostname, 'the browser uses the LAN address, not a loopback stand-in');
+ await chrome.click('document.querySelector(\'[data-tab="shouts"]\')');
+ const message = 'LAN fixture person request';
+ await chrome.stable(`document.querySelector('#shout-text').value = ${JSON.stringify(message)}`);
+ await chrome.click("document.querySelector('#shout-send')");
+ await chrome.waitFor(`document.querySelector('#shout-text').value === '' && document.body.innerText.includes(${JSON.stringify(message)})`);
+ const native = JSON.parse(box.run(alpha.repo, 'export', '--json'));
+ const recorded = native.tables.shout.filter(row => row.shout_text === message)
+ .map(({ shout_from, shout_to, shout_request }) => ({ shout_from, shout_to, shout_request }));
+ assert.deepEqual(recorded, [{ shout_from: 'person', shout_to: 'coordinator', shout_request: 1 }],
+ 'the mobile action is a real native person request, recorded exactly once');
+ assert.equal(await chrome.stable('document.documentElement.scrollWidth <= document.documentElement.clientWidth'), true,
+ 'the phone view stays within its viewport');
+
+ const local = await startView(box);
+ t.after(() => local.stop());
+ assert.equal(local.link.hostname, '127.0.0.1', 'ordinary view still starts as loopback only');
+ const localForeign = await lanBoundaryReply({ ...local, base: local.base }, '/api/v1/boards', {
+ 'x-pullboard-key': local.key, host: view.link.hostname + ':' + local.link.port,
+ });
+ assertLanRefusal(localForeign, local, title);
+ t.diagnostic('Real LAN-interface HTTP and 375px Chrome; both clients run on this machine, not a second physical phone.');
+});