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.

Merge branch 'main' into core/183

Corey Olsone1b984ece4eb
diff --cc relay/journal.js
index 299b7247,b2a966db..78136642
--- a/relay/journal.js
+++ b/relay/journal.js
@@@ -3,9 -3,9 +3,10 @@@ import { DatabaseSync } from 'node:sqli
import { closeSync, lstatSync, mkdirSync, openSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { Refused } from '../src/refused.js';
+import { SEALED_SNAPSHOT_BYTES } from '../src/relay-limits.js';
+ import { createRelayPages } from './page-store.js';
- const FORMAT = 3;
+ const FORMAT = 4;
const DEFAULT_BYTES = 100_000;
/** Validate a persistent identity before it can name an internal file. */
diff --cc relay/service.js
index 21cadefe,ed61775a..a203b31c
--- a/relay/service.js
+++ b/relay/service.js
@@@ -13,10 -13,11 +13,12 @@@ import { createPairingStore } from './p
import { createPairingHandler } from './pairing-http.js';
import { createRelayBrowserHandler } from './browser-page.js';
import { VERIFIER_STANDING_ENGINE } from '../src/machine.js';
+import { SEALED_SNAPSHOT_BYTES, SNAPSHOT_BODY_BYTES } from '../src/relay-limits.js';
+ import { createRelayPagesHandler, snapshotPageRoot } from './pages-http.js';
+ import { createStorageQuota } from './storage-quota.js';
-const SNAPSHOT_BODY = 14_000_000;
-const STORED_BYTES = 10_000_000;
+const SNAPSHOT_BODY = SNAPSHOT_BODY_BYTES;
+const STORED_BYTES = SEALED_SNAPSHOT_BYTES;
/** Validate a board identity before deriving its private, internal database path. */
function identity(id) {
diff --cc src/api-http.js
index 3c2d3024,09b416d8..78d2554a
--- a/src/api-http.js
+++ b/src/api-http.js
@@@ -1,8 -1,8 +1,9 @@@
/** API v1's shared HTTP boundary; local and relay adapters supply the same board operations (A2). */
import { Refused } from './refused.js';
+ import { relayStorage } from './relay-storage.js';
import { refusalDocument } from './json.js';
import { withGitFacts } from './git.js';
+import { PAIR_PACKAGE_BODY_BYTES } from './relay-limits.js';
const BODY_BYTES = 100_000;
diff --cc src/relay-storage.js
index 00000000,13fd5af0..15a9cd7d
mode 000000,100644..100644
--- a/src/relay-storage.js
+++ b/src/relay-storage.js
@@@ -1,0 -1,15 +1,14 @@@
+ /** Shared credential-free account storage status for all transport versions [H15,H17]. */
+ /** Keep account quota status only after validating its credential-free response fields. */
+ export function relayStorage(value) {
+ if (!value || typeof value.account?.id !== 'string' || typeof value.account?.login !== 'string' ||
+ !/^[A-Za-z0-9_-]{1,100}$/u.test(value.account.id) || !/^[A-Za-z0-9_-]{1,100}$/u.test(value.account.login) ||
+ !Number.isSafeInteger(value.usedBytes) || value.usedBytes < 0 || !Number.isSafeInteger(value.limitBytes) || value.limitBytes < 1) return null;
+ return { account: { id: value.account.id, login: value.account.login }, usedBytes: value.usedBytes, limitBytes: value.limitBytes };
+ }
+
+ /** Print account, used bytes and the operator-set limit without importing server-only quota storage into the CLI. */
+ export function relayStorageLine(value) {
+ const storage = relayStorage(value);
+ return storage ? `relay storage: account ${storage.account.login}, ${(storage.usedBytes / 1_000_000).toFixed(1)} MB used of ${(storage.limitBytes / 1_000_000).toFixed(1)} MB` : '';
+ }
-
diff --cc src/relay.js
index b14f3011,0026b0c9..d9593c76
--- a/src/relay.js
+++ b/src/relay.js
@@@ -102,9 -108,17 +109,16 @@@ import
requireRelayOnChannel,
} from './person.js';
import { listApiProjects } from './projects.js';
+ import {
+ relaySnapshotRequest,
+ relayStorage,
+ relayStorageLine,
+ } from './relay-page-client.js';
+ export { relayStorageLine };
export const DEFAULT_RELAY = 'https://app.pullboard.dev';
-const SEALED_SNAPSHOT_LIMIT = 10_000_000;
const LINK_FILES = new WeakMap();
+ const STATE_FILES = new WeakMap();
const WARNED_COMMANDS = new WeakSet();
const KEY_WARNED_COMMANDS = new WeakSet();
const BASELINE_ATTEMPTS = new WeakMap();
diff --cc test/relay-snapshot-size.test.js
index fe751233,c2cecb7d..7b67ebb3
--- a/test/relay-snapshot-size.test.js
+++ b/test/relay-snapshot-size.test.js
@@@ -12,8 -11,11 +12,11 @@@ import { SEALED_SNAPSHOT_BYTES as RELAY
import { presentationDigest, relaySnapshot } from '../src/relay-presentation.js';
import { relayClientFixture } from './relay-client-fixture.js';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
+ import { readSealedDescriptor } from '../src/sealed-pages.js';
+ import { openPagedSnapshot } from '../src/relay-page-layout.js';
-const RELAY_LIMIT = 10_000_000;
-const BODY_LIMIT = 14_000_000;
+const LEGACY_BODY_THRESHOLD = 14_000_000;
++const LEGACY_RELAY_THRESHOLD = 10_000_000;
/** Preserve every SQLite value while normalizing row prototypes for JSON transport comparisons. */
function plainRows(rows) { return rows.map(row => ({ ...row })); }
@@@ -45,36 -47,6 +48,37 @@@ async function sealedSnapshot(box, docu
return Buffer.from(await seal(key, plaintext, { boardId: state.board, kind: 'snapshot', sequence })).toString('base64url');
}
+test('a 20 MB sealed snapshot syncs to the relay and reads back whole [H5,H15,H17]', { timeout: 180_000 }, async t => {
+ const box = await relayClientFixture(t);
++ box.legacySnapshotApi(); // Exercise the legacy whole-snapshot endpoint.
+ await box.link();
+ const local = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));
+ try {
+ store.shout(local, { from: 'coordinator', to: 'all', text: 'LARGE_SEALED_SNAPSHOT_' + randomBytes(14_000_000).toString('base64url'), lanes: [box.lane] });
+ } finally { store.closeBoard(local); }
+
+ const state = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const sealed = await sealedSnapshot(box, relaySnapshot(box.root), state.sequence, true);
+ const sealedBytes = Buffer.from(sealed, 'base64url');
+ assert.ok(sealedBytes.byteLength > 20_000_000, 'the gzip snapshot exceeds 20,000,000 decoded bytes');
+ assert.ok(sealedBytes.byteLength < RELAY_LIMIT, 'the gzip snapshot remains within the shared decoded limit');
+ const requestBody = JSON.stringify({ sequence: state.sequence, sealed });
+ assert.ok(Buffer.byteLength(requestBody) < BODY_LIMIT, 'the base64 request fits the shared HTTP body limit');
+
+ const path = box.origin + '/api/v1/boards/' + state.board + '/state';
+ const headers = { authorization: 'Bearer ' + state.token, 'x-pullboard-engine': String(ENGINE_VERSION), 'content-type': 'application/json' };
+ const upload = await fetch(path, { method: 'PUT', headers, body: requestBody });
+ const accepted = await upload.json();
+ assert.equal(upload.status, 200, 'the real local relay accepts the >20 MB sealed snapshot: ' + JSON.stringify(accepted));
+ assert.equal(accepted.state.sealed, sealed, 'the accepted response preserves every sealed byte');
+
+ const read = await fetch(path, { headers: { authorization: headers.authorization, 'x-pullboard-engine': headers['x-pullboard-engine'] } });
+ assert.equal(read.status, 200, 'the real local relay serves the stored large snapshot');
+ const returned = await read.json();
+ assert.equal(returned.state.sealed, sealed, 'a readback returns the exact sealed snapshot bytes');
+ assert.deepEqual(Buffer.from(returned.state.sealed, 'base64url'), sealedBytes);
+});
+
test('a large board syncs to the relay compressed [H5,H15,H17]', {
skip: !findChromeExecutable() && 'Chrome is not installed',
}, async t => {
@@@ -199,15 -172,18 +204,16 @@@
})()`, 'hash browser projection and native snapshot');
assert.deepEqual(browserRead, { projectionHash, tablesHash }, 'the production browser client reads the exact projection and browser gzip retains every native table byte');
- // A valid but still-too-large gzip checkpoint remains pending and is named by both CLI readers.
+ // An older relay that does not advertise paged snapshots keeps its explicit per-request refusal.
+ box.legacySnapshotApi();
const oversizedDocument = relaySnapshot(box.root);
- const randomTitle = 'OVERSIZE_SNAPSHOT_340_' + randomBytes(5_050_000).toString('base64');
- const itemId = oversizedDocument.tables.item[0].item_id;
- oversizedDocument.tables.item.find(row => row.item_id === itemId).item_title = randomTitle;
- oversizedDocument.presentation.state.items.find(row => row.id === itemId).title = randomTitle;
+ const randomTitle = 'OVERSIZE_SNAPSHOT_340_' + randomBytes(RELAY_LIMIT).toString('base64');
+ oversizedDocument.tables.board_meta.push({ meta_key: 'oversize_test_payload', meta_value: randomTitle });
const oversizedGzip = await sealedSnapshot(box, oversizedDocument, sourceState.sequence, true);
const oversizedBytes = Buffer.from(oversizedGzip, 'base64url').byteLength;
- assert.ok(oversizedBytes > RELAY_LIMIT, 'the compressed sealed snapshot still exceeds the relay journal limit');
+ assert.ok(oversizedBytes > RELAY_LIMIT, 'the compressed sealed snapshot exceeds the shared relay limit');
assert.ok(Buffer.byteLength(JSON.stringify({ sequence: sourceState.sequence, sealed: oversizedGzip })) < BODY_LIMIT,
- 'the oversized sealed snapshot remains below the unchanged HTTP body limit');
+ 'the oversized sealed snapshot remains below the shared HTTP body limit');
const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
const localDigest = presentationDigest(relaySnapshot(box.root).presentation);
link.checkpoint = { sequence: sourceState.sequence, sealed: oversizedGzip };
@@@ -222,5 -197,206 +228,206 @@@
const doctorJSON = await box.cli('doctor');
assert.equal(doctorJSON.code, 1);
assert.ok(doctorJSON.document.problems.some(problem => problem.code === 'RELAY_SNAPSHOT_LIMIT'), 'doctor JSON names the stable oversize rule');
- assert.match(doctor.stdout, new RegExp(`relay snapshot for ${sourceState.board}: sealed snapshot \\d+\\.\\d MB over the relay limit 10\\.0 MB`));
+ assert.match(doctor.stdout, new RegExp(`relay snapshot for ${sourceState.board}: sealed snapshot \\d+\\.\\d MB over the relay limit ${displayedLimit} MB`));
});
+
+ /** Authenticate one private fixture object's graph path without exposing credentials in diagnostics. */
+ function pagedReadContext(box, link, head, key) {
+ return { boardId: link.board, key, sequence: head.sequence,
+ /** Public HTTP still checks the principal's pinned root; only this device interprets the sealed directory. */
+ async get(id, parents) {
+ const response = await fetch(box.origin + '/api/v2/boards/' + link.board + '/objects/' + id
+ + '?pin=' + head.read.id + '&via=' + parents.join(','), {
+ headers: { authorization: 'Bearer ' + link.token, 'x-pullboard-engine': String(ENGINE_VERSION) },
+ });
+ const document = await response.json();
+ assert.equal(response.status, 200, document.error?.message);
+ return Buffer.from(document.page.sealed, 'base64url');
+ },
+ };
+ }
+
+ /** Select an old event leaf, so a controlled background hold cannot accidentally block the current-state boot. */
+ async function oldestEventPage(head, context) {
+ const root = await readSealedDescriptor(head.root, context);
+ const event = root.value.tables.indexOf('event');
+ assert.ok(event >= 0);
+ let reference = root.links[event + 3], parents = [head.root.id];
+ for (;;) {
+ const node = await readSealedDescriptor(reference, { ...context, parents });
+ const range = node.value.entries[0], child = node.links[0];
+ assert.ok(range && child);
+ if (range.leaf) return child.id;
+ parents = [...parents, reference.id]; reference = child;
+ }
+ }
+
+ test('thirty thousand events open on the phone within three seconds and stream all sealed history beside live moves [H5,H15,H17]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+ }, async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const pairing = await box.cli('relay', 'pair');
+ const second = await box.otherDeviceJoin(pairing.document.code);
+ const currentMarker = 'PAGED_CURRENT_STATE_903';
+ const oldestMarker = 'PAGED_OLDEST_SHOUT_903';
+ const liveMarker = 'LIVE_MOVE_DURING_HISTORY_903';
+ const native = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));
+ let oldest;
+ try {
+ // These are synthetic native fixture moves in one normal board transaction, never owner-board edits.
+ store.atomic(native, () => {
+ for (let index = 0; index < 900; index++) store.addItem(native, {
+ by: 'coordinator', lane: box.lane, title: index === 899 ? currentMarker : 'Retained current work ' + index, route: 'strong',
+ });
+ oldest = store.shout(native, { from: 'coordinator', to: 'all', text: oldestMarker, lanes: [box.lane] });
+ // Incompressible retained history proves several times the old cap in actual uploaded cipher bytes.
+ for (let index = 0; index < 32; index++) store.shout(native, {
+ from: 'coordinator', to: 'all', text: 'Private historical data ' + index + ':' + randomBytes(1_000_000).toString('base64'), lanes: [box.lane],
+ });
+ for (let index = 0; index < 30_017; index++) store.shout(native, {
+ from: 'coordinator', to: 'all', text: 'Recent and retained work ' + index, lanes: [box.lane],
+ });
+ });
+ assert.equal(store.allShouts(native)[0].shout_id, oldest, 'the addressed marker really is this board\'s oldest shout');
+ } finally { store.closeBoard(native); }
+ const before = relaySnapshot(box.root);
+ assert.ok(before.tables.event.length >= 30_000 && before.tables.event.length < 31_000);
- assert.ok(gzipSync(Buffer.from(JSON.stringify(before))).byteLength > RELAY_LIMIT * 3, 'even compressed whole-board state is several times the old limit');
++ assert.ok(gzipSync(Buffer.from(JSON.stringify(before))).byteLength > LEGACY_RELAY_THRESHOLD * 3, 'even compressed whole-board state is several times the old limit');
+ const uploadedStatus = await box.cli('status');
+ assert.equal(uploadedStatus.code, 0, 'the actual opted-in CLI publishes through bounded pages');
+ assert.equal(uploadedStatus.snapshotWork.observed, true);
+ assert.ok(uploadedStatus.snapshotWork.pageUploadBytes > 0 && uploadedStatus.snapshotWork.pageCheckpointAttempts > 0,
+ 'API2 page bytes and actual checkpoint attempts contribute non-zero recorded work');
+ assert.ok(uploadedStatus.snapshotWork.budgetUnits <= 6 && !uploadedStatus.snapshotWork.overLimit, 'observed attempts and bytes stay bounded without raising the existing time allowance');
+ t.diagnostic(JSON.stringify({ api2UploadWork: uploadedStatus.snapshotWork, derivedChildDeadlineMs: uploadedStatus.snapshotDeadlineMs }));
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ assert.equal(link.snapshotApiVersion, 2);
+ assert.equal(link.checkpoint, undefined);
+ const writes = box.transit.filter(row => row.method === 'PUT' && /\/api\/v2\/boards\/[^/]+\/uploads\/[^/]+\/objects\//u.test(row.path));
+ const uploaded = new Map(writes.map(row => [row.path.split('/').at(-1), Buffer.from(JSON.parse(row.request).sealed, 'base64url').byteLength]));
+ const cipherBytes = [...uploaded.values()].reduce((sum, bytes) => sum + bytes, 0);
- assert.ok(cipherBytes > RELAY_LIMIT * 3, 'real unique encrypted upload objects exceed thirty million bytes');
++ assert.ok(cipherBytes > LEGACY_RELAY_THRESHOLD * 3, 'real unique encrypted upload objects exceed thirty million bytes');
+ assert.ok(writes.every(row => row.request.byteLength < 600_000), 'no request carries the whole board');
+ assert.ok(writes.every(row => !row.request.includes(Buffer.from(oldestMarker))), 'the relay stores no historical plaintext');
+ const headers = { authorization: 'Bearer ' + link.token, 'x-pullboard-engine': String(ENGINE_VERSION) };
+ const headResponse = await fetch(box.origin + '/api/v2/boards/' + link.board + '/state', { headers });
+ const head = (await headResponse.json()).state;
+ const key = decodeBoardKey(readFileSync(box.keyFile, 'utf8').trim());
+ const context = pagedReadContext(box, link, head, key);
+ const root = await readSealedDescriptor(head.root, context);
+ assert.ok(root.links[0].bytes < 1_000_000, 'the authenticated current-state plaintext budget is under one megabyte');
+ const heldPage = await oldestEventPage(head, context);
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });
+ await chrome.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: String.raw`
+ window.__phoneTiming = { firstBoardPaint: null, objectRequests: 0, loopbackReads: 0, historyHeld: false };
+ window.__releaseOlderHistory = null;
+ const originalFetch = window.fetch;
+ window.fetch = async (input, options) => {
+ const url = new URL(typeof input === 'string' ? input : input.url, location.href);
+ if (['http://127.0.0.1:4890', 'http://localhost:4890'].includes(url.origin)) {
+ __phoneTiming.loopbackReads++; throw new TypeError('No local view in this private phone fixture');
+ }
+ if (/\/api\/v2\/boards\/[^/]+\/objects\//u.test(url.pathname)) __phoneTiming.objectRequests++;
+ if (url.pathname.endsWith('/objects/${heldPage}') && !window.__olderHistoryAllowed) {
+ __phoneTiming.historyHeld = true;
+ await new Promise(resolveHistory => { window.__releaseOlderHistory = resolveHistory; });
+ }
+ return originalFetch(input, options);
+ };
+ let queued = false;
+ new MutationObserver(() => {
+ const node = document.querySelector('#chain');
+ if (queued || !node?.textContent.includes('${currentMarker}') || !node.getBoundingClientRect().height) return;
+ queued = true;
+ requestAnimationFrame(() => { __phoneTiming.firstBoardPaint = performance.now(); });
+ }).observe(document, { childList: true, subtree: true, attributes: true, characterData: true });
+ ` });
+ await chrome.send('Network.setCookie', {
+ name: 'pb_session', value: (await box.phoneSession()).token, url: box.origin, httpOnly: true, sameSite: 'Lax',
+ });
+ await chrome.navigate(box.origin + '/#board=' + link.board + '&key=' + readFileSync(box.keyFile, 'utf8').trim());
+ // Budget: the owner's explicit first-readable-board bar is three seconds, independent of historical streaming.
+ await chrome.waitFor('Number.isFinite(window.__phoneTiming?.firstBoardPaint) && typeof transport !== "undefined" && !!transport?.historyProgress', 3000, 'bounded current board paints before all history'); // budget: declared frozen #903 first-readable-board ceiling is 3000ms; it cannot be relaxed.
+ const first = await chrome.evaluate(`({ ...__phoneTiming, phone: document.documentElement.dataset.relayDevice, progress: transport.historyProgress('${link.board}') })`);
+ assert.equal(first.phone, 'phone'); assert.ok(first.firstBoardPaint < 3000);
+ assert.equal(first.loopbackReads, 0); assert.equal(first.progress.complete, false);
+ // Budget: this fixture streams thirty thousand historical records before reaching its deliberately held oldest event leaf.
+ await chrome.waitFor('window.__phoneTiming.historyHeld', 30_000, 'old history is streaming after the first readable board'); // budget: hang ceiling for the deliberately held oldest-event-page handshake, independent of the 3s boot bar.
+ try {
+ assert.equal((await box.cli('add', box.lane, liveMarker)).code, 0, 'ordinary native moves continue while old history is pinned');
+ await chrome.waitFor(`document.querySelector('#chain')?.textContent.includes('${liveMarker}')`, 15_000, 'new current state arrives while an older history page is held'); // budget: hang ceiling for the live-move handshake while old history is held, not a throughput claim.
+ } finally {
+ await chrome.evaluate('window.__olderHistoryAllowed = true; window.__releaseOlderHistory?.(); true');
+ }
+ const expected = relaySnapshot(box.root);
+ const finalSequence = Number(expected.tables.board_meta.find(row => row.meta_key === 'relay_applied_sequence').meta_value);
+ // Budget: a complete loopback replay includes both the pinned predecessor and its live successor, never the three-second boot bar.
+ await chrome.waitFor(`transport.historyProgress('${link.board}').complete && transport.historyProgress('${link.board}').sequence === ${finalSequence}`, 45_000, 'all sealed history is held at the live checkpoint'); // budget: hang ceiling for two complete pinned background streams; the 3s boot bar is measured separately.
+ const oldestHash = createHash('sha256').update(oldestMarker).digest('hex');
+ const read = await chrome.evaluate(`(async () => {
+ const before = __phoneTiming.objectRequests;
+ const reply = await transport.request('/api/v1/boards/${link.board}/shouts/${oldest}');
+ const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(reply.shout.shout_text)));
+ return { hash: [...digest].map(byte => byte.toString(16).padStart(2, '0')).join(''), extraObjectReads: __phoneTiming.objectRequests - before,
+ progress: transport.historyProgress('${link.board}'), loopbackReads: __phoneTiming.loopbackReads };
+ })()`);
+ assert.equal(read.hash, oldestHash); assert.equal(read.extraObjectReads, 0, 'the oldest shout is already held after the background stream');
+ assert.equal(read.progress.loaded, read.progress.total); assert.equal(read.loopbackReads, 0);
+ await chrome.evaluate(`location.hash = '#shout-${oldest}'; true`);
+ await chrome.waitFor(`document.body.innerText.includes('${oldestMarker}')`, 3000, 'the actual phone view opens the streamed oldest shout'); // budget: hang ceiling for the addressed-shout render handshake after history completion.
+ assert.equal((await second.cli('status')).code, 0, 'an independent paired CLI restores the same paged checkpoint');
+ const restored = await second.cli('export');
+ assert.equal(restored.code, 0);
+ const nativeDigest = value => createHash('sha256').update(JSON.stringify(plainTables(value))).digest('hex');
+ assert.equal(nativeDigest(restored.document.tables), nativeDigest(expected.tables), 'every native row, counter and receipt is retained');
+ const metrics = { firstPaintMs: first.firstBoardPaint, events: expected.tables.event.length, uniqueCipherBytes: cipherBytes,
+ largestUploadBody: Math.max(...writes.map(row => row.request.byteLength)), currentSnapshotBytes: root.links[0].bytes,
+ progress: read.progress, oldestHash, nativeTablesHash: nativeDigest(expected.tables) };
+ t.diagnostic(JSON.stringify(metrics));
+ if (process.env.PULLBOARD_RELAY_PAGE_PROOF) {
+ const output = process.env.PULLBOARD_RELAY_PAGE_PROOF;
+ mkdirSync(output, { recursive: true, mode: 0o700 });
+ writeFileSync(join(output, 'metrics.json'), JSON.stringify(metrics, null, 2) + '\n', { mode: 0o600 });
+ const screenshot = await chrome.send('Page.captureScreenshot', { format: 'png' });
+ writeFileSync(join(output, 'oldest-shout-phone.png'), Buffer.from(screenshot.data, 'base64'), { mode: 0o600 });
+ }
+ });
+
+
+ test('large compressible history uses bounded pages even when its whole encrypted snapshot fits the old wire cap [H15,H17]', async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const board = store.openBoard(join(box.root, '.git/pullboard/board.sqlite'));
+ try {
+ store.atomic(board, () => {
+ for (let index = 0; index < 4_000; index++) store.shout(board, {
+ from: 'coordinator', to: 'all', lanes: [box.lane], text: 'Retained compressible history ' + index + ' ' + 'q'.repeat(1_000),
+ });
+ });
+ } finally { store.closeBoard(board); }
+ const before = relaySnapshot(box.root);
+ const raw = Buffer.from(JSON.stringify(before));
+ assert.ok(raw.byteLength > 1_000_000);
+ const compressedBytes = gzipSync(raw).byteLength;
- assert.ok(compressedBytes < RELAY_LIMIT, 'a whole encrypted carrier fits the old wire cap despite a large phone decode');
++ assert.ok(compressedBytes < LEGACY_RELAY_THRESHOLD, 'a whole encrypted carrier fits the former 10 MB wire cap despite a large phone decode');
+ t.diagnostic(JSON.stringify({ nativeBytes: raw.byteLength, compressedBytes }));
+ assert.equal((await box.cli('status')).code, 0);
+ const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ assert.equal(link.snapshotApiVersion, 2, 'large retained plaintext needs paging even when its encrypted carrier compresses well');
+ const response = await fetch(box.origin + '/api/v2/boards/' + link.board + '/state', {
+ headers: { authorization: 'Bearer ' + link.token, 'x-pullboard-engine': String(ENGINE_VERSION) },
+ });
+ const head = (await response.json()).state;
+ const key = decodeBoardKey(readFileSync(box.keyFile, 'utf8').trim());
+ const context = pagedReadContext(box, link, head, key);
+ const root = await readSealedDescriptor(head.root, context);
+ assert.ok(root.links[0].bytes < 1_000_000);
+ const page = await openPagedSnapshot(head.root, context, { maxEngine: ENGINE_VERSION });
+ const restored = await page.native();
+ const hash = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
+ assert.equal(hash(restored.tables), hash(before.tables), 'paged encoding retains all compressible history too');
+ });