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): package all browser runtime files in image [H5,H18]

Corey Olson95d4b0dc4025
diff --git a/relay/Dockerfile b/relay/Dockerfile
index f4aec861..97ca72db 100644
--- a/relay/Dockerfile
+++ b/relay/Dockerfile
@@ -5,8 +5,8 @@ ENV NODE_ENV=production \
WORKDIR /app
COPY --chown=node:node package.json ./package.json
-COPY --chown=node:node src/api-http.js src/json.js src/refused.js ./src/
-COPY --chown=node:node relay/auth-http.js relay/auth.js relay/github.js relay/journal.js relay/retention.js relay/server.mjs relay/service.js ./relay/
+COPY --chown=node:node src/ ./src/
+COPY --chown=node:node relay/ ./relay/
RUN mkdir -p /data && chown node:node /data && chmod 700 /data
USER node
diff --git a/test/relay-deploy.test.js b/test/relay-deploy.test.js
index d0fa4db0..7ce954aa 100644
--- a/test/relay-deploy.test.js
+++ b/test/relay-deploy.test.js
@@ -2,7 +2,7 @@
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { createServer } from 'node:http';
-import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, copyFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { tmpdir } from 'node:os';
import { test } from 'node:test';
@@ -13,6 +13,106 @@ const SMOKE = resolve(import.meta.dirname, '../relay/smoke.mjs');
const SERVER = resolve(import.meta.dirname, '../relay/server.mjs');
const DOCKERFILE = resolve(import.meta.dirname, '../relay/Dockerfile');
const README = resolve(import.meta.dirname, '../relay/README.md');
+const ROOT = resolve(import.meta.dirname, '..');
+
+/** Copy one declared Docker source to its Dockerfile destination, optionally omitting a runtime file. */
+function copyDockerSource(source, destinationPath, omitted) {
+ if (omitted.has(source)) return;
+ const sourcePath = join(ROOT, source);
+ if (statSync(sourcePath).isDirectory()) {
+ mkdirSync(destinationPath, { recursive: true });
+ for (const entry of readdirSync(sourcePath)) copyDockerSource(join(source, entry), join(destinationPath, entry), omitted);
+ } else {
+ mkdirSync(join(destinationPath, '..'), { recursive: true });
+ copyFileSync(sourcePath, destinationPath);
+ }
+}
+
+/** Build an empty image root from exactly the sources named by Dockerfile COPY instructions. */
+function copiedImage(t, omitted = []) {
+ const image = mkdtempSync(join(tmpdir(), 'pullboard-relay-image-'));
+ t.after(() => rmSync(image, { recursive: true, force: true }));
+ const excluded = new Set(omitted);
+ for (const line of readFileSync(DOCKERFILE, 'utf8').split(/\r?\n/u)) {
+ const tokens = line.trim().split(/\s+/u);
+ if (tokens[0] !== 'COPY') continue;
+ const paths = tokens.slice(1).filter(token => !token.startsWith('--'));
+ const destination = paths.pop();
+ assert.ok(paths.length > 0 && destination, 'Docker COPY names at least one source and a destination');
+ const destinationPath = join(image, destination.replace(/^\.\//u, '').replace(/\/$/u, ''));
+ for (const source of paths) copyDockerSource(source.replace(/\/$/u, ''), destinationPath, excluded);
+ }
+ return image;
+}
+
+/** Start the copied production entry point with private fixture storage and no inherited selectors. */
+function copiedServer(t, image, port, provider) {
+ const privateHome = mkdtempSync(join(tmpdir(), 'pullboard-relay-image-home-'));
+ const data = join(privateHome, 'data');
+ const env = {
+ PATH: process.env.PATH ?? '/usr/bin:/bin',
+ NODE_ENV: 'production',
+ HOME: join(privateHome, 'home'), PULLBOARD_HOME: join(privateHome, 'pullboard-home'),
+ PULLBOARD_MACHINE_HOME: join(privateHome, 'machine-home'), PULLBOARD_RELAY_DATA: data,
+ PULLBOARD_PUBLIC_ORIGIN: `http://127.0.0.1:${port}`, PORT: String(port),
+ GITHUB_APP_CLIENT_ID: provider.config.clientId,
+ GITHUB_APP_CLIENT_SECRET: provider.config.clientSecret,
+ GITHUB_APP_PRIVATE_KEY: provider.config.privateKey,
+ };
+ mkdirSync(env.HOME, { recursive: true, mode: 0o700 });
+ t.after(() => rmSync(privateHome, { recursive: true, force: true }));
+ const child = spawn(process.execPath, [join(image, 'relay/server.mjs')], { cwd: image, env, stdio: ['ignore', 'ignore', 'ignore'] });
+ t.after(async () => {
+ if (child.exitCode !== null || child.signalCode !== null) return;
+ child.kill('SIGTERM');
+ if (await childClosesWithin(child, 5000)) return;
+ child.kill('SIGKILL');
+ await childClosesWithin(child, 5000);
+ });
+ return { child, privateHome };
+}
+
+/** Fetch with the remaining portion of the copied server's shared readiness deadline. */
+function fetchBeforeDeadline(url, deadline) {
+ const remaining = deadline - Date.now();
+ if (remaining <= 0) throw new Error('the copied relay exceeded its five-second readiness budget');
+ return fetch(url, { signal: AbortSignal.timeout(remaining) });
+}
+
+/** Stop waiting once a copied entry point exits or its private readiness route answers. */
+async function copiedServerHealthy(child, origin, deadline) {
+ while (Date.now() < deadline && child.exitCode === null) {
+ try {
+ const response = await fetchBeforeDeadline(new URL('/health', origin), deadline);
+ if (response.status === 200 && (await response.text()) === 'ok\n') return true;
+ } catch { /* The copied entry point is still starting. */ }
+ await new Promise(ready => setTimeout(ready, 25));
+ }
+ return false;
+}
+
+/** Wait a bounded interval for the process close event. */
+function childClosesWithin(child, milliseconds) {
+ if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve(true);
+ return new Promise(ready => {
+ const closed = () => {
+ clearTimeout(timer);
+ ready(true);
+ };
+ const timer = setTimeout(() => {
+ child.off('close', closed);
+ ready(false);
+ }, milliseconds);
+ child.once('close', closed);
+ });
+}
+
+/** Require an omitted Docker source to produce a real nonzero process exit before readiness. */
+async function copiedServerFailureCode(child) {
+ if (child.exitCode !== null) return child.exitCode;
+ if (!await childClosesWithin(child, 1500)) return null;
+ return child.exitCode;
+}
/** Extract a documented setting so the checklist can be checked against executable config. */
function setting(text, pattern, description) {
@@ -172,3 +272,37 @@ test('[H5,H18] the container entry point serves readiness and stays available',
await waitHealthy(child, origin);
assert.equal(child.exitCode, null, 'the long-running relay remains available after its health probe');
});
+
+test('[H5,H18] Docker COPY sources boot the relay and serve its browser page, while omitted runtime files refuse startup', async (t) => {
+ const provider = await githubFixture(t);
+ const image = copiedImage(t);
+ const port = await unusedPort();
+ const origin = `http://127.0.0.1:${port}`;
+ const running = copiedServer(t, image, port, provider);
+ const deadline = Date.now() + 5000;
+ assert.equal(await copiedServerHealthy(running.child, origin, deadline), true, 'the Dockerfile-only copy starts the production entry point and reaches health');
+ const page = await fetchBeforeDeadline(origin, deadline);
+ assert.equal(page.status, 200);
+ assert.match(await page.text(), /Sign in to see your linked boards/u, 'the copied image serves the browser page');
+ const browser = await fetchBeforeDeadline(new URL('/relay/client.js', origin), deadline);
+ assert.equal(browser.status, 200);
+ assert.match(await browser.text(), /rememberPairing/u, 'the browser route serves its runtime client asset');
+ assert.equal(running.child.exitCode, null, 'the copied relay stays alive after serving browser routes');
+ assert.equal(running.child.signalCode, null, 'the copied relay was not stopped by a probe timeout');
+ assert.equal(existsSync(join(running.privateHome, 'data', 'auth.sqlite')), true, 'the private auth database was created in its configured volume');
+
+ for (const omitted of [
+ 'src/cockpit.js',
+ 'src/machine.js',
+ 'src/view.css',
+ 'src/seal.js',
+ 'relay/browser-client.js',
+ 'relay/browser-model.js',
+ 'src/refused.js',
+ ]) {
+ const damagedImage = copiedImage(t, [omitted]);
+ const damagedPort = await unusedPort();
+ const damaged = copiedServer(t, damagedImage, damagedPort, provider);
+ assert.ok((await copiedServerFailureCode(damaged.child)) > 0, `omitting ${omitted} from the Dockerfile copy causes a real nonzero startup exit`);
+ }
+});