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.

chore(core): integrate relay load proof [H16,C7,H15]

Corey Olson755fd97fc103
diff --cc test/relay-browser-fixture.test.js
index a1fd8afc,22cae731..0b5a7314
--- a/test/relay-browser-fixture.test.js
+++ b/test/relay-browser-fixture.test.js
@@@ -36,19 -36,33 +36,33 @@@ test('paired Chrome excludes idle even
skip: !findChromeExecutable() && 'Chrome is not installed',
}, async t => {
const box = await relayClientFixture(t);
- const title = 'RELAY_BROWSER_PENDING_DIAGNOSTIC';
- assert.equal((await box.cli('add', box.lane, title)).code, 0);
await box.link();
const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
- const key = readFileSync(box.keyFile, 'utf8').trim();
- const chrome = await startChrome();
+ const chrome = await startChrome({ commandTimeoutMs: 15000 });
t.after(() => chrome.close());
const cookie = await chrome.send('Network.setCookie', {
- name: 'pb_session', value: link.token, url: box.origin, httpOnly: true, sameSite: 'Lax',
+ name: 'pb_session', value: (await box.phoneSession()).token, url: box.origin, httpOnly: true, sameSite: 'Lax',
});
assert.equal(cookie.success, true);
- await chrome.navigate(box.origin + '/#board=' + link.board + '&key=' + key);
- await chrome.waitFor("document.querySelector('#chain')?.textContent.includes(" + JSON.stringify(title) + ')');
+ // A static same-origin document has no cockpit refresh timer to start ordinary reads mid-probe.
+ await chrome.navigate(box.origin + '/view.css');
+ await chrome.waitFor('document.readyState === "complete"');
+ const stateResponse = await fetch(box.origin + '/api/v1/boards/' + link.board + '/state', {
+ headers: { authorization: 'Bearer ' + link.token, 'x-pullboard-engine': String(ENGINE_VERSION) },
+ });
+ assert.equal(stateResponse.status, 200);
+ const snapshot = (await stateResponse.json()).state;
+ const streamPath = '/api/v1/boards/' + link.board + '/events?after=' + snapshot.sequence;
+ const streamTask = await chrome.startTask(`fetch(${JSON.stringify(streamPath)}, {
+ credentials: 'same-origin', headers: { 'x-pullboard-engine': ${ENGINE_VERSION}, accept: 'text/event-stream' }
+ }).then(response => { window.__diagnosticStream = response.body.getReader();
+ return { status: response.status, type: response.headers.get('content-type') }; })`, 'authenticated idle event stream');
+ const stream = await chrome.pollTask(streamTask);
+ assert.equal(stream.status, 200);
+ assert.match(stream.type, /text\/event-stream/);
+ assert.ok(box.calls.some(call => call.path === streamPath && call.accept === 'text/event-stream'),
+ 'the real relay accepted the idle event stream before the stalled probe');
+ await assert.doesNotReject(chrome.waitForRelayIdle(), 'a real idle event stream is excluded from ordinary pending requests');
await stalledCommand(chrome, 'idle paired stream probe', false);
const before = box.stateReadStarted();
diff --cc test/relay-client-fixture.js
index 6b8760e3,b2365f25..ea68a6eb
--- a/test/relay-client-fixture.js
+++ b/test/relay-client-fixture.js
@@@ -1,6 -1,6 +1,7 @@@
+import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
/** Private real CLI, auth and relay fixture; credentials never enter assertion messages [H1,H7,H18]. */
import assert from 'node:assert/strict';
+ import { createHash } from 'node:crypto';
import { spawn, spawnSync } from 'node:child_process';
import { createServer } from 'node:http';
import { Transform } from 'node:stream';
@@@ -72,7 -118,56 +119,56 @@@ export async function relayClientFixtur
GIT_AUTHOR_NAME: 'Relay Fixture', GIT_AUTHOR_EMAIL: '[email protected]',
GIT_COMMITTER_NAME: 'Relay Fixture', GIT_COMMITTER_EMAIL: '[email protected]',
};
+ writeFileSync(tracePreload, `
+ import { appendFileSync } from 'node:fs';
+ import { createHash } from 'node:crypto';
+ const originalFetch = globalThis.fetch;
+ /** Record safe request, caller and checkpoint details for this private relay only. */
+ globalThis.fetch = function tracedFetch(input, init) {
+ const target = new URL(input instanceof URL ? input.href : typeof input === 'string' ? input : input.url);
+ const method = init?.method ?? input?.method ?? 'GET';
+ if (target.origin !== process.env.PULLBOARD_TEST_RELAY_TRACE_ORIGIN || method !== 'PUT'
+ || !/^\\/api\\/v1\\/boards\\/[0-9a-f]{32}\\/state$/u.test(target.pathname)) {
+ return originalFetch.call(this, input, init);
+ }
+ const startedAt = Date.now();
+ const body = init?.body;
+ let sequence = null;
+ let ciphertext = null;
+ try {
+ const document = JSON.parse(String(body));
+ if (Number.isSafeInteger(document.sequence)) sequence = document.sequence;
+ if (typeof document.sealed === 'string') ciphertext = createHash('sha256').update(document.sealed).digest('hex');
+ } catch { /* Record only metadata for malformed fixture traffic. */ }
+ const callers = (new Error().stack ?? '').split('\\n')
+ .filter(line => line.includes('/src/'))
+ .slice(0, 8)
+ .map(line => {
+ const name = line.match(/^\\s*at (.*?) \\(/u)?.[1] ?? '<anonymous>';
+ const location = line.match(/\\/src\\/([^/():]+\\.js:\\d+:\\d+)/u)?.[1] ?? 'unknown';
+ return name + '@' + location;
+ });
+ const signal = init?.signal ?? input?.signal;
+ let abort = signal?.aborted ? { at: Date.now(), name: signal.reason?.name ?? null, code: signal.reason?.code ?? null } : null;
+ const onAbort = () => { abort = { at: Date.now(), name: signal.reason?.name ?? null, code: signal.reason?.code ?? null }; };
+ signal?.addEventListener('abort', onAbort, { once: true });
+ const record = { at: startedAt, method, path: target.pathname.replace(/\\/[0-9a-f]{32}\\//u, '/<board>/'), sequence, ciphertext, callers };
+ /** Persist one bounded request outcome while excluding the sealed payload and credentials. */
+ function finish(details) {
+ appendFileSync(process.env.PULLBOARD_TEST_RELAY_TRACE_FILE, JSON.stringify({ ...record, abort, ...details }) + '\\n', { mode: 0o600 });
+ signal?.removeEventListener('abort', onAbort);
+ }
+ return originalFetch.call(this, input, init).then(response => {
+ finish({ status: response.status, elapsedMs: Date.now() - startedAt });
+ return response;
+ }, error => {
+ finish({ errorName: error.name, errorCode: error.code ?? null, elapsedMs: Date.now() - startedAt });
+ throw error;
+ });
+ };
+ `, { mode: 0o600 });
+ writeFileSync(traceFile, '', { mode: 0o600 });
- for (const name of ['PULLBOARD_RELAY_KEY', 'PULLBOARD_RELAY_TOKEN']) delete env[name];
+ for (const name of ['PULLBOARD_RELAY_KEY', 'PULLBOARD_RELAY_TOKEN', ...AGENT_SHELL_MARKERS, ...SSH_SHELL_MARKERS]) delete env[name];
const provider = await githubFixture(t);
provider.state.deviceAuthorized = true;
const authDatabase = join(scratch, 'auth.sqlite');
@@@ -201,13 -316,11 +320,14 @@@
await new Promise(resolveDelay => setTimeout(resolveDelay, delay));
snapshotWriteDelays.push(Date.now() - delayedAt);
}
- if (stateReadDelayMs && req.method === 'GET' && /\/api\/v1\/boards\/[0-9a-f]{32}\/state$/.test(req.url ?? '')) {
+ if ((stateReadDelayMs || stateReadHold) && req.method === 'GET' && /\/api\/v1\/boards\/[0-9a-f]{32}\/state$/.test(req.url ?? '')) {
stateReadStarted += 1;
- await new Promise(resolveDelay => setTimeout(resolveDelay, stateReadDelayMs));
+ if (stateReadHold) await stateReadHold;
+ else await new Promise(resolveDelay => setTimeout(resolveDelay, stateReadDelayMs));
}
+ if (beforeMove && req.method === 'POST' && /\/api\/v1\/boards\/[0-9a-f]{32}\/moves$/.test(req.url ?? '')) {
+ const action = beforeMove; beforeMove = null; await action();
+ }
if (await signIn(request, res)) return;
await api(request, res);
});
@@@ -390,7 -525,7 +546,7 @@@
}
return {
transit, relayDirectory: join(scratch, 'relay'), authDatabase, otherDeviceJoin,
- root, env, origin, lane, before, linkFile, keyFile, calls, moveAcks, cli, cliAt, cliWithSnapshotUploads, link, phoneSession, requireEngineThree, otherDeviceOff, additionalBoard, script, stopRelay, restartRelay,
- root, env, origin, lane, before, linkFile, keyFile, calls, moveAcks, cli, cliAt, cliWithSnapshotUploads, cliWithSnapshotTrace, link, requireEngineThree, otherDeviceOff, additionalBoard, script, stopRelay, restartRelay,
++ root, env, origin, lane, before, linkFile, keyFile, calls, moveAcks, cli, cliAt, cliWithSnapshotUploads, cliWithSnapshotTrace, link, phoneSession, requireEngineThree, otherDeviceOff, additionalBoard, script, stopRelay, restartRelay,
/** Assert the test consumed every declared child budget, with no hidden CLI calls. */
assertCliChildrenComplete() {
if (cliChildren) assert.equal(cliChildIndex, cliChildren.length, 'every planned private CLI child ran exactly once');