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(relay): trace delayed person snapshot uploads [H12,H16,H17]

Corey Olsond59962f45a23
diff --git a/test/relay-client-fixture.js b/test/relay-client-fixture.js
index 6e50e882..086d1e56 100644
--- a/test/relay-client-fixture.js
+++ b/test/relay-client-fixture.js
@@ -1,5 +1,6 @@
/** 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';
@@ -7,6 +8,7 @@ import { once } from 'node:events';
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { delimiter, join, resolve } from 'node:path';
import { tmpdir } from 'node:os';
+import { pathToFileURL } from 'node:url';
import { createAuthHandler } from '../relay/auth-http.js';
import { createRelayAuth } from '../relay/auth.js';
import { createRelayHandler } from '../relay/service.js';
@@ -16,37 +18,49 @@ import { githubFixture } from './relay-fixture.js';
const CLI = resolve(import.meta.dirname, '../bin/pullboard.js');
const CLI_PRODUCT_DEADLINE_MS = 15_000;
const SNAPSHOT_UPLOAD_BOUND_MS = 10_000;
-const STATUS_SNAPSHOT_UPLOADS = 3;
const CLI_DEADLINE_MARGIN_MS = 10_000;
+const MAX_OBSERVED_SNAPSHOT_UPLOADS = 6;
+const DEFAULT_SNAPSHOT_UPLOADS = 3;
-/** Derive a private CLI child deadline from the product bound and its asserted upload count. */
-export function cliChildDeadlineMs(snapshotUploads) {
- assert.ok(Number.isSafeInteger(snapshotUploads) && snapshotUploads >= 0, 'snapshot upload count is a nonnegative integer');
- return Math.max(CLI_PRODUCT_DEADLINE_MS, snapshotUploads * SNAPSHOT_UPLOAD_BOUND_MS) + CLI_DEADLINE_MARGIN_MS;
+/** Derive a private CLI child deadline from observed uploads, with a finite runaway guard. */
+export function cliChildDeadlineMs(observedUploads) {
+ assert.ok(Number.isSafeInteger(observedUploads) && observedUploads >= 0 && observedUploads <= MAX_OBSERVED_SNAPSHOT_UPLOADS,
+ 'observed snapshot upload count is within the finite fixture bound');
+ return Math.max(CLI_PRODUCT_DEADLINE_MS, observedUploads * SNAPSHOT_UPLOAD_BOUND_MS) + CLI_DEADLINE_MARGIN_MS;
}
/** Capture a real child result without exposing its private output in failure diagnostics. */
-function childResult(root, env, argv, snapshotUploads = STATUS_SNAPSHOT_UPLOADS) {
+function childResult(root, env, argv, observedSnapshotUploads, initialSnapshotUploads = DEFAULT_SNAPSHOT_UPLOADS) {
return new Promise((resolveResult, reject) => {
const startedAt = Date.now();
const command = argv[0] === CLI ? (argv[1] ?? 'CLI') : (argv[0] ?? 'script');
- const childDeadlineMs = cliChildDeadlineMs(snapshotUploads);
+ let deadlineAt = startedAt + cliChildDeadlineMs(initialSnapshotUploads);
const child = spawn(process.execPath, argv, { cwd: root, env, stdio: ['ignore', 'pipe', 'pipe'] });
let stdout = '';
let exceededDeadline = false;
- const timer = setTimeout(() => { exceededDeadline = true; child.kill('SIGKILL'); }, childDeadlineMs);
+ const timer = setInterval(() => {
+ const count = observedSnapshotUploads?.() ?? initialSnapshotUploads;
+ if (count > MAX_OBSERVED_SNAPSHOT_UPLOADS) {
+ exceededDeadline = true;
+ child.kill('SIGKILL');
+ return;
+ }
+ deadlineAt = Math.max(deadlineAt, startedAt + cliChildDeadlineMs(count));
+ if (Date.now() >= deadlineAt) { exceededDeadline = true; child.kill('SIGKILL'); }
+ }, 20);
child.stdout.setEncoding('utf8').on('data', part => { stdout += part; });
child.stderr.resume();
- child.once('error', error => { clearTimeout(timer); reject(error); });
+ child.once('error', error => { clearInterval(timer); reject(error); });
child.once('close', (code, signal) => {
- clearTimeout(timer);
+ clearInterval(timer);
if (signal) return reject(new Error(exceededDeadline
- ? `Private relay fixture ${command} exceeded its ${childDeadlineMs}ms deadline after ${Date.now() - startedAt}ms.`
+ ? `Private relay fixture ${command} exceeded its ${deadlineAt - startedAt}ms upload-derived deadline after ${Date.now() - startedAt}ms.`
: `Private relay fixture ${command} ended with signal ${signal} after ${Date.now() - startedAt}ms.`));
let document;
try { document = JSON.parse(stdout); }
catch { return reject(new Error('private relay fixture child did not return JSON')); }
- resolveResult({ code, document });
+ resolveResult({ code, document, snapshotUploads: observedSnapshotUploads?.() ?? initialSnapshotUploads,
+ snapshotDeadlineMs: deadlineAt - startedAt });
});
});
}
@@ -57,6 +71,8 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
const root = join(scratch, 'repo');
const home = join(scratch, 'home');
const privateBin = join(scratch, 'path');
+ const traceFile = join(scratch, 'snapshot-fetch-trace.jsonl');
+ const tracePreload = join(scratch, 'snapshot-fetch-trace.mjs');
mkdirSync(root);
mkdirSync(home, { mode: 0o700 });
mkdirSync(privateBin, { mode: 0o700 });
@@ -71,6 +87,55 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
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];
const provider = await githubFixture(t);
provider.state.deviceAuthorized = true;
@@ -86,6 +151,7 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
let snapshotWriteDelayMs = 0;
let snapshotWriteCount = 0;
const snapshotWriteDelays = [];
+ const snapshotWriteRecords = [];
let stateReadDelayMs = 0;
let stateReadStarted = 0;
let refuseSnapshotWrites = false;
@@ -98,9 +164,13 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
const privateKeys = new Set();
let keyLeaked = false;
const server = createServer(async (req, res) => {
- if (req.method === 'PUT' && /\/api\/v1\/boards\/[0-9a-f]{32}\/state$/.test(req.url ?? '')) snapshotWriteCount += 1;
+ const snapshotWrite = req.method === 'PUT' && /\/api\/v1\/boards\/[0-9a-f]{32}\/state$/.test(req.url ?? '');
+ if (snapshotWrite) snapshotWriteCount += 1;
const requestChunks = [];
const responseChunks = [];
+ const snapshotStartedAt = Date.now();
+ const snapshotRecord = snapshotWrite ? { at: snapshotStartedAt, sequence: null, ciphertext: null, status: null, elapsedMs: null, responseClosedBeforeFinish: false } : null;
+ if (snapshotRecord) snapshotWriteRecords.push(snapshotRecord);
const request = new Transform({
transform(chunk, _encoding, callback) {
requestChunks.push(Buffer.from(chunk));
@@ -109,6 +179,22 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
});
Object.assign(request, { method: req.method, url: req.url, headers: req.headers });
req.pipe(request);
+ if (snapshotRecord) {
+ request.once('finish', () => {
+ let checkpoint = {};
+ try { checkpoint = JSON.parse(Buffer.concat(requestChunks).toString('utf8')); } catch { /* Keep the transport trace safe when a malformed request arrives. */ }
+ snapshotRecord.sequence = Number.isSafeInteger(checkpoint.sequence) ? checkpoint.sequence : null;
+ snapshotRecord.ciphertext = typeof checkpoint.sealed === 'string' ? createHash('sha256').update(checkpoint.sealed).digest('hex') : null;
+ });
+ req.once('aborted', () => { snapshotRecord.requestAborted = true; });
+ res.once('finish', () => {
+ snapshotRecord.status = res.statusCode;
+ snapshotRecord.elapsedMs = Date.now() - snapshotStartedAt;
+ });
+ res.once('close', () => {
+ if (snapshotRecord.status === null) snapshotRecord.responseClosedBeforeFinish = true;
+ });
+ }
/** Capture a response chunk for boolean-only transport audits without changing the response. */
function captureResponse(chunk) {
if (chunk !== undefined && chunk !== null && typeof chunk !== 'function') responseChunks.push(Buffer.from(chunk));
@@ -213,14 +299,40 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
return step.snapshotUploads;
}
/** Run one CLI child and verify its observed uploads against the plan when the test supplied one. */
- async function runCliChild(args, requestedUploads) {
+ async function runCliChild(args, requestedUploads, traceSnapshotWrites = false) {
const plannedUploads = plannedSnapshotUploads(args);
const snapshotUploads = plannedUploads ?? requestedUploads;
const writesBefore = snapshotWriteCount;
- const result = await childResult(root, env, [CLI, ...args, '--json'], snapshotUploads);
+ const childEnv = traceSnapshotWrites ? { ...env, PULLBOARD_TEST_RELAY_TRACE_FILE: traceFile,
+ PULLBOARD_TEST_RELAY_TRACE_ORIGIN: origin,
+ NODE_OPTIONS: [env.NODE_OPTIONS, '--import=' + pathToFileURL(tracePreload).href].filter(Boolean).join(' ') } : env;
+ const traceLinesBefore = traceSnapshotWrites ? readFileSync(traceFile, 'utf8').split('\n').filter(Boolean).length : 0;
+ const initialUploads = traceSnapshotWrites ? 0 : snapshotUploads ?? DEFAULT_SNAPSHOT_UPLOADS;
+ /** Read only this child’s sanitized fetch records, retaining evidence before fixture cleanup. */
+ function childTrace() {
+ if (!traceSnapshotWrites) return [];
+ return readFileSync(traceFile, 'utf8').split('\n').filter(Boolean)
+ .slice(traceLinesBefore).map(line => JSON.parse(line));
+ }
+ let result;
+ try {
+ result = await childResult(root, childEnv, [CLI, ...args, '--json'],
+ traceSnapshotWrites ? () => snapshotWriteCount - writesBefore : undefined, initialUploads);
+ } catch (error) {
+ if (traceSnapshotWrites) {
+ const evidence = JSON.stringify({ fetches: childTrace(), relayReceives: snapshotWriteRecords.slice(writesBefore) });
+ const message = error instanceof Error ? error.message : String(error);
+ throw new Error(`${message}; safe snapshot transport evidence: ${evidence}`, { cause: error });
+ }
+ throw error;
+ }
+ if (traceSnapshotWrites) result.snapshotTrace = childTrace();
if (cliChildren) {
- assert.equal(snapshotWriteCount - writesBefore, snapshotUploads,
- `private CLI child ${cliChildIndex} uploads its declared number of snapshots`);
+ const observedUploads = snapshotWriteCount - writesBefore;
+ const observedWrites = snapshotWriteRecords.slice(writesBefore);
+ const safeTrace = result.snapshotTrace ?? [];
+ assert.equal(observedUploads, snapshotUploads,
+ `private CLI child ${cliChildIndex} uploads its declared number of snapshots; client fetches: ${JSON.stringify(safeTrace)}; relay receives: ${JSON.stringify(observedWrites)}`);
}
if (cliChildren && requestedUploads !== undefined) {
assert.equal(requestedUploads, snapshotUploads, `private CLI child ${cliChildIndex} uses its declared upload count`);
@@ -229,12 +341,17 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
}
/** Invoke the production CLI in this private repository under its planned budget, when present. */
async function cli(...args) {
- return runCliChild(args);
+ return runCliChild(args, undefined, args[0] === 'status');
}
/** Bound a CLI child using the exact snapshot count asserted by its fixture flow. */
async function cliWithSnapshotUploads(snapshotUploads, ...args) {
cliChildDeadlineMs(snapshotUploads);
- return runCliChild(args, snapshotUploads);
+ return runCliChild(args, snapshotUploads, args[0] === 'status');
+ }
+ /** Run a CLI child with sanitized local snapshot callsite tracing for diagnosis. */
+ async function cliWithSnapshotTrace(snapshotUploads, ...args) {
+ cliChildDeadlineMs(snapshotUploads);
+ return runCliChild(args, snapshotUploads, true);
}
assert.equal(spawnSync('git', ['init', '-q', '-b', 'main'], { cwd: root, env }).status, 0);
writeFileSync(join(root, 'README.md'), 'private relay fixture project\n', { mode: 0o600 });
@@ -334,7 +451,7 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
}
return {
transit, relayDirectory: join(scratch, 'relay'), authDatabase, otherDeviceJoin,
- root, env, origin, lane, before, linkFile, keyFile, calls, moveAcks, cli, cliWithSnapshotUploads, link, requireEngineThree, otherDeviceOff, additionalBoard, script, stopRelay, restartRelay,
+ root, env, origin, lane, before, linkFile, keyFile, calls, moveAcks, cli, cliWithSnapshotUploads, cliWithSnapshotTrace, link, 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');
@@ -350,6 +467,8 @@ export async function relayClientFixture(t, { cliChildren } = {}) {
},
/** Return observed delays for the fixture's real snapshot endpoint. */
snapshotWriteDelays() { return [...snapshotWriteDelays]; },
+ /** Return sanitized per-child transport callsites and checkpoint fingerprints. */
+ snapshotWriteRecords() { return snapshotWriteRecords.map(record => ({ ...record })); },
/** Hold real state reads long enough to observe their pending-request diagnostic. */
delayStateReads(ms) {
assert.ok(Number.isSafeInteger(ms) && ms >= 0 && ms <= 30000, 'state read hold is bounded');
diff --git a/test/relay-person-outbox.test.js b/test/relay-person-outbox.test.js
index fc771495..a1356b9d 100644
--- a/test/relay-person-outbox.test.js
+++ b/test/relay-person-outbox.test.js
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
import { findChromeExecutable, startChrome } from './relay-browser-fixture.js';
-import { relayClientFixture } from './relay-client-fixture.js';
+import { cliChildDeadlineMs, relayClientFixture } from './relay-client-fixture.js';
/** Install only the private fixture's person cookie in the real browser. */
async function signIn(chrome, box) {
@@ -109,13 +109,26 @@ test('real Chrome keeps an interrupted person request sealed and retries it once
assert.deepEqual(outbox, [], 'the relay acknowledgement removes the device outbox entry');
const delayedBefore = box.snapshotWriteDelays().length;
+ const writeRecordsBefore = box.snapshotWriteRecords().length;
box.delaySnapshotWrites(8000);
- const native = box.cliWithSnapshotUploads(3, 'status').then(result => ({ result }), error => ({ error }));
+ const native = box.cliWithSnapshotTrace(3, 'status').then(result => ({ result }), error => ({ error }));
const status = await native;
box.delaySnapshotWrites(0);
assert.equal(status.error, undefined, 'the native linked machine executes the recovered request');
assert.equal(status.result.code, 0, 'the native linked machine reports success');
const delays = box.snapshotWriteDelays().slice(delayedBefore);
+ const trace = status.result.snapshotTrace;
+ const writeRecords = box.snapshotWriteRecords().slice(writeRecordsBefore);
+ t.diagnostic('status snapshot PUT sources: ' + JSON.stringify(trace.map(write => ({
+ at: write.at, sequence: write.sequence, ciphertext: write.ciphertext, callers: write.callers, elapsedMs: write.elapsedMs,
+ }))));
+ assert.equal(trace.length, delays.length, 'every delayed state upload has a matching private fetch trace');
+ assert.deepEqual(trace.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ writeRecords.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ 'the private trace matches only snapshots received by the isolated relay');
+ assert.ok(trace.every(write => write.callers.some(line => line.includes('publishCheckpoint'))), 'each traced upload came from checkpoint publication');
+ assert.equal(status.result.snapshotUploads, trace.length);
+ assert.equal(status.result.snapshotDeadlineMs, cliChildDeadlineMs(trace.length), 'the child deadline follows this run’s observed upload count');
assert.equal(delays.length, 3, 'this three-upload status flow uploads exactly three snapshots');
assert.ok(delays.every(delay => delay >= 7900), 'the relay delayed every native snapshot by 8 seconds');
const completed = await waitForRequest(chrome, link.board, requestId, 'done');
@@ -125,7 +138,10 @@ test('real Chrome keeps an interrupted person request sealed and retries it once
assert.equal(completed.state.personRequests.find(row => row.id === requestId).status, 'done');
const repeatedState = await finalState(chrome, link.board);
assert.equal(repeatedState.state.personRequests.find(row => row.id === requestId).status, 'done');
- assert.equal((await box.cli('status')).code, 0, 'repeated native replay stays idempotent');
+ const control = await box.cliWithSnapshotTrace(0, 'status');
+ assert.equal(control.code, 0, 'repeated native replay stays idempotent');
+ assert.equal(control.snapshotTrace.length, 0, 'a completed request status has no checkpoint to republish');
+ assert.equal(control.snapshotDeadlineMs, cliChildDeadlineMs(0), 'a no-upload control keeps only the product bound and margin');
const repeatedExport = (await box.cli('export')).document;
assert.equal(repeatedExport.tables.shout.filter(row => row.shout_from === 'person' && row.shout_text === text).length, 1);
});
diff --git a/test/relay-person-requests.test.js b/test/relay-person-requests.test.js
index 5b792522..ec9b6207 100644
--- a/test/relay-person-requests.test.js
+++ b/test/relay-person-requests.test.js
@@ -158,13 +158,26 @@ test('real paired Chrome transports a person shout while its native snapshot is
await installRequestTransport(chrome);
const delayedBefore = box.snapshotWriteDelays().length;
+ const writeRecordsBefore = box.snapshotWriteRecords().length;
box.delaySnapshotWrites(8000);
- const native = box.cliWithSnapshotUploads(3, 'status').then(result => ({ result }), error => ({ error }));
+ const native = box.cliWithSnapshotTrace(3, 'status').then(result => ({ result }), error => ({ error }));
const status = await native;
box.delaySnapshotWrites(0);
assert.equal(status.error, undefined, 'the next native status receives and executes the queued intent');
assert.equal(status.result.code, 0, 'the next native status reports success');
const delays = box.snapshotWriteDelays().slice(delayedBefore);
+ const trace = status.result.snapshotTrace;
+ const writeRecords = box.snapshotWriteRecords().slice(writeRecordsBefore);
+ t.diagnostic('person shout status snapshot PUT sources: ' + JSON.stringify(trace.map(write => ({
+ at: write.at, sequence: write.sequence, ciphertext: write.ciphertext, callers: write.callers, elapsedMs: write.elapsedMs,
+ }))));
+ assert.equal(trace.length, delays.length, 'every delayed state upload has a matching private fetch trace');
+ assert.deepEqual(trace.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ writeRecords.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ 'the private trace matches only snapshots received by the isolated relay');
+ assert.ok(trace.every(write => write.callers.some(line => line.includes('publishCheckpoint'))), 'each traced upload came from checkpoint publication');
+ assert.equal(status.result.snapshotUploads, trace.length);
+ assert.equal(status.result.snapshotDeadlineMs, cliChildDeadlineMs(trace.length), 'the child deadline follows this run’s observed upload count');
assert.equal(delays.length, 3, 'this three-upload status flow uploads exactly three snapshots');
assert.ok(delays.every(delay => delay >= 7900), 'the relay delayed every native snapshot by 8 seconds');
const latest = await waitForRequest(chrome, link.board, receipt.result.request.id, 'done');
@@ -294,12 +307,27 @@ test('coordinator decline resolves a paired approval request with a reason and l
const link = await pairedTransport(chrome, box, title);
const queued = await sendPersonIntent(chrome, link.board, { verb: 'spec-approve', args: { ids: 'G96' } });
const delayedBefore = box.snapshotWriteDelays().length;
+ const writeRecordsBefore = box.snapshotWriteRecords().length;
box.delaySnapshotWrites(8000);
const native = await box.cliWithSnapshotUploads(4, 'status').then(result => ({ result }), error => ({ error }));
box.delaySnapshotWrites(0);
assert.equal(native.error, undefined, 'the four-upload decline status fits its derived deadline');
assert.equal(native.result.code, 0);
const delays = box.snapshotWriteDelays().slice(delayedBefore);
+ const trace = native.result.snapshotTrace;
+ const writeRecords = box.snapshotWriteRecords().slice(writeRecordsBefore);
+ t.diagnostic('decline status snapshot PUT evidence: ' + JSON.stringify({
+ fetches: trace, relayReceives: writeRecords, delays,
+ }));
+ assert.equal(trace.length, delays.length, 'every delayed decline upload has a matching client fetch trace');
+ assert.deepEqual(trace.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ writeRecords.map(({ sequence, ciphertext }) => ({ sequence, ciphertext })),
+ 'the private client and relay traces identify each decline checkpoint');
+ assert.ok(trace.every(write => write.callers.some(caller => caller.includes('publishCheckpoint'))),
+ 'each decline upload comes from checkpoint publication');
+ assert.equal(native.result.snapshotUploads, trace.length);
+ assert.equal(native.result.snapshotDeadlineMs, cliChildDeadlineMs(trace.length),
+ 'the decline status deadline follows its observed uploads');
assert.equal(delays.length, 4, 'the decline status flow uploads exactly four snapshots');
assert.ok(delays.every(delay => delay >= 7900), 'the relay delayed every decline snapshot by 8 seconds');
const pending = (await finalState(chrome, link.board)).state.personRequests.find(record => record.id === queued.result.request.id);