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.

refactor(core): catch-up and send move to their own module [H21,H16]

Corey Olson28953fd6208f
diff --git a/src/relay-local-first.js b/src/relay-local-first.js
index e96781a9..6ad64739 100644
--- a/src/relay-local-first.js
+++ b/src/relay-local-first.js
@@ -4,7 +4,10 @@
* background sender per machine pushes the queued moves and pulls other machines' moves, for every board on it.
*/
import { spawn } from 'node:child_process';
-import { createHash, randomUUID } from 'node:crypto';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
import {
existsSync,
mkdirSync,
@@ -20,7 +23,8 @@ import { pullboardHome } from './local-state.js';
/** Set to 0 to send inside each command instead, as before #1013; the test runner sets it, like the view. */
export const SENDER_BACKGROUND_ENV = 'PULLBOARD_RELAY_SENDER_BACKGROUND';
-const WORKER = fileURLToPath(new URL('./relay-sender-worker.js', import.meta.url));
+/** The machine sender's entry file, which every sender process runs. */
+export const SENDER_WORKER = fileURLToPath(new URL('./relay-sender-worker.js', import.meta.url));
/**
* Whether this process leaves sending to the machine's background sender.
@@ -111,7 +115,7 @@ export function nudgeRelaySender(root, file) {
if (senderHolding() || !startingSender()) return;
const env = { ...process.env };
delete env.PULLBOARD_RELAY_TOKEN; // The sender works only with this machine's own saved credentials.
- const child = spawn(process.execPath, [WORKER], { cwd: root, detached: true, stdio: 'ignore', env });
+ const child = spawn(process.execPath, [SENDER_WORKER], { cwd: root, detached: true, stdio: 'ignore', env });
child.unref();
} catch { /* A board the sender misses now is served by the next command's nudge; the move is already saved. */ }
}
diff --git a/src/relay-ordering.js b/src/relay-ordering.js
new file mode 100644
index 00000000..04a01939
--- /dev/null
+++ b/src/relay-ordering.js
@@ -0,0 +1,195 @@
+/**
+ * Following the relay's order (#1013): catch-up applies the relay's records to this board, and a send posts one
+ * sealed move as its actor. Built over relay.js's own link and transport helpers, which it cannot import without a
+ * cycle, as the checkpoint publisher is.
+ */
+import { join } from 'node:path';
+import * as store from './board.js';
+import * as conflictRecords from './relay-conflict-record.js';
+import {
+ appliedSequence,
+ engineReceipt,
+} from './engine.js';
+import { restoreRelaySnapshot } from './exchange.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+} from './git.js';
+import { refusalFromReceipt } from './recorded-refusal.js';
+import { Refused } from './refused.js';
+import { readBoardKey } from './relay-key.js';
+import {
+ outboxAhead,
+ outboxWaiting,
+} from './relay-outbox.js';
+import { withOutboxGuard } from './relay-outbox-guard.js';
+import {
+ actorTransport,
+ cacheSeatToken,
+ nameNextSeat,
+ seatReceipt,
+} from './relay-seats.js';
+import {
+ credentialActor,
+ relaySenderProblem,
+} from './relay-sender.js';
+
+/**
+ * Build catch-up and send over relay.js's helpers.
+ *
+ * @param {{ request: Function, localRecords: Function, decoded: Function, replayRelayRecord: Function,
+ * reportRecoveredReply: Function, saveLink: Function, sealedRecord: Function, flush: Function }} relay
+ * @returns {{ applyRecords: Function, fetchCheckpoint: Function, catchUp: Function, postPending: Function, sendPending: Function }}
+ */
+export function relayOrdering({ request, localRecords, decoded, replayRelayRecord, reportRecoveredReply, saveLink, sealedRecord, flush }) {
+ /** Apply authenticated relay records in order, each in its own board transaction with a durable receipt. */
+ async function applyRecords(root, key, state, records) {
+ const outcomes = [];
+ for (const record of records) {
+ const board = store.openBoard(join(repoInfo(root).commonDir, 'pullboard', 'board.sqlite'), undefined, { isMain: codeIsFromMain() });
+ try { outcomes.push(await replayRelayRecord(board, key, state, record)); } finally { store.closeBoard(board); }
+ }
+ return outcomes;
+ }
+
+ /** Read and authenticate the relay's checkpoint without touching the board; the caller restores it. */
+ async function fetchCheckpoint(state, io, key) {
+ const document = await request(state, '/api/v1/boards/' + state.board + '/state', {}, io);
+ const snapshot = document.state;
+ if (!snapshot || !Number.isSafeInteger(snapshot.sequence) || snapshot.sequence < 0) throw new Refused('RELAY_RESPONSE', 'the relay snapshot has no valid coverage sequence; fetch it again');
+ const senderProblem = relaySenderProblem(null, snapshot.sender, 'snapshot');
+ if (senderProblem) throw senderProblem;
+ return { native: await decoded(key, snapshot, state, 'snapshot', snapshot.sequence), sequence: snapshot.sequence };
+ }
+
+ /** Most catch-up passes one command makes when moves keep queuing on this machine meanwhile. */
+ const CATCH_UP_PASSES = 10;
+
+ /** Apply a validated relay prefix with durable, transaction-bound receipts on this replica. */
+ async function catchUp(root, file, state, io, pass = 0) {
+ if (pass >= CATCH_UP_PASSES) throw new Refused('RELAY_BUSY', 'moves kept queuing on this machine while it caught up; they stay queued for the next send');
+ // Queued moves sit on top of this board: the outbox rebuilds it from the relay's order with them on top (#1013).
+ if (outboxAhead(state) || outboxWaiting(file)) await flush(root, file, state, io);
+ const key = readBoardKey(state.board);
+ const after = localRecords(root, appliedSequence);
+ let remote;
+ try { remote = await request(state, '/api/v1/boards/' + state.board + '/events?after=' + after, {}, io); }
+ catch (error) {
+ if (error.code !== 'SNAPSHOT_REQUIRED') throw error;
+ const checkpoint = await fetchCheckpoint(state, io, key);
+ const restored = await withOutboxGuard(file, () => {
+ if (outboxWaiting(file)) return false;
+ localRecords(root, (board) => restoreRelaySnapshot(board, checkpoint.native, checkpoint.sequence));
+ return true;
+ });
+ if (!restored) return catchUp(root, file, state, io, pass + 1);
+ if (localRecords(root, appliedSequence) <= after) throw new Refused('RELAY_RESPONSE', 'the relay checkpoint did not advance the missing prefix; fetch a consistent newer snapshot');
+ return catchUp(root, file, state, io, pass);
+ }
+ if ([remote.warning, ...(remote.warnings ?? [])].some((warning) => warning?.code === 'KEY_REQUESTS')) io.keyRequestsWaiting = true;
+ if (!Array.isArray(remote.events) || remote.events.some((record, index) => !record || record.event_id !== after + index + 1 || !['move', 'request'].includes(record.kind) || typeof record.sealed !== 'string')) {
+ throw new Refused('RELAY_RESPONSE', 'the relay returned an invalid ordered prefix; fetch a consistent relay snapshot');
+ }
+ // Another machine's moves land only on a board with nothing queued on top; a move may have queued meanwhile.
+ const outcomes = await withOutboxGuard(file, async () => {
+ if (outboxWaiting(file) || localRecords(root, appliedSequence) !== after) return null;
+ return applyRecords(root, key, state, remote.events);
+ });
+ if (!outcomes) return catchUp(root, file, state, io, pass + 1);
+ let pendingRefusal;
+ remote.events.forEach((record, index) => {
+ const outcome = outcomes[index];
+ // Exact ciphertext identifies an interrupted send even when its document was refused before replay.
+ if (record.kind === 'move' && state.pending?.move && record.event_id === state.pending.sequence
+ && record.sealed === state.pending.sealed && outcome?.error
+ && !localRecords(root, board => engineReceipt(board, state.pending.move.id))) {
+ pendingRefusal = outcome.error;
+ reportRecoveredReply(state.pending, io);
+ delete state.pending;
+ delete state.recovered;
+ }
+ });
+ state.sequence = localRecords(root, appliedSequence);
+ if (state.pending?.move && localRecords(root, (board) => engineReceipt(board, state.pending.move.id))) {
+ reportRecoveredReply(state.pending, io);
+ state.recovered = state.pending;
+ delete state.pending;
+ }
+ saveLink(file, state);
+ if (pendingRefusal) throw refusalFromReceipt(pendingRefusal);
+ }
+
+ /**
+ * Post one sealed move to the relay as its actor, renewing an expired seat token once and taking the next free seat
+ * name for a registration the relay already gave out. Network only: it applies nothing, so the outbox can send a
+ * move while this machine's board still shows its queued moves on top (#1013).
+ */
+ async function postPending(root, file, state, pending, io) {
+ let renewedAgentToken = false;
+ for (let tries = 0; tries < 100; tries += 1) {
+ const actor = credentialActor(pending.move);
+ try {
+ const transport = await conflictRecords.transport(root, pending.move, localRecords, () => actorTransport(root, file, state, actor, io));
+ const reply = await request(transport, '/api/v1/boards/' + state.board + '/moves', { method: 'POST',
+ body: { sequence: pending.sequence, sealed: pending.sealed, ...(pending.registration ? { registration: pending.registration } : {}) } }, io);
+ if (reply.event?.event_id !== pending.sequence || reply.event.sealed !== pending.sealed) throw new Refused('RELAY_RESPONSE', 'the relay acknowledgement differs from this executable send; fetch the configured relay');
+ if (pending.registration) {
+ const enrollment = reply.enrollment;
+ if (!enrollment || enrollment.board !== state.board || enrollment.agent !== pending.registration.target || typeof enrollment.id !== 'string') {
+ throw new Refused('RELAY_RESPONSE', 'the relay registered the seat without its issuance; repeat this command to recover its token');
+ }
+ // A retried registration returns the same issuance without a token; its creator reissues it on first use.
+ if (enrollment.token !== undefined) cacheSeatToken(file, state, pending.registration.target, enrollment);
+ }
+ return;
+ } catch (error) {
+ if (error.code === 'AUTH_REQUIRED' && !renewedAgentToken && actor !== 'machine' && actor !== 'person'
+ && process.env.PULLBOARD_RELAY_TOKEN === undefined && state.agentTokens?.[actor]?.token) {
+ // An expired cache renews only through the seat's creator; a live one the relay refused was revoked.
+ if (state.agentTokens[actor].expires > Date.now()) {
+ state.agentTokens[actor].revoked = true;
+ saveLink(file, state);
+ throw new Refused('TOKEN_REVOKED', `the relay token of ${actor} was revoked on this board; work from a seat with its own token, or ask the coordinator for a fresh worktree`);
+ }
+ delete state.agentTokens[actor].token;
+ saveLink(file, state);
+ renewedAgentToken = true;
+ continue;
+ }
+ if (error.code === 'SEAT_TAKEN' && pending.registration) {
+ // The relay already gave this name a token (a machine first mint): take the next free name.
+ nameNextSeat(root, pending.move, Number(pending.move.args[0].id.slice(pending.move.args[0].lane.length + 1)) + 1);
+ pending.sealed = await sealedRecord(readBoardKey(state.board), pending.move, state, 'move', pending.sequence);
+ pending.registration = seatReceipt(pending.move, pending.sequence, pending.sealed);
+ saveLink(file, state);
+ continue;
+ }
+ throw error;
+ }
+ }
+ throw new Refused('RELAY_BUSY', 'the relay kept refusing this seat name; retry this command after other clients finish');
+ }
+
+ /** Finish a durable executable send; a collision reseals its unchanged id after applying the winner. */
+ async function sendPending(root, file, state, io) {
+ for (let tries = 0; state.pending && tries < 100; tries += 1) {
+ try { await postPending(root, file, state, state.pending, io); }
+ catch (error) {
+ if (!['SEQUENCE_REPEAT', 'SEQUENCE_GAP'].includes(error.code)) throw error;
+ await catchUp(root, file, state, io);
+ if (state.pending) {
+ state.pending.sequence = state.sequence + 1;
+ if (state.pending.registration) nameNextSeat(root, state.pending.move, 0);
+ state.pending.sealed = await sealedRecord(readBoardKey(state.board), state.pending.move, state, 'move', state.pending.sequence);
+ state.pending.registration = seatReceipt(state.pending.move, state.pending.sequence, state.pending.sealed);
+ saveLink(file, state);
+ }
+ continue;
+ }
+ await catchUp(root, file, state, io);
+ }
+ if (state.pending) throw new Refused('RELAY_BUSY', 'the relay order stayed busy; retry this command after other clients finish');
+ }
+
+ return { applyRecords, fetchCheckpoint, catchUp, postPending, sendPending };
+}
diff --git a/src/relay.js b/src/relay.js
index ac947bb5..e5cb5b4c 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -86,9 +86,7 @@ import {
} from './relay-sender.js';
import {
actorTransport,
- cacheSeatToken,
ensurePersonCoordinator,
- nameNextSeat,
seatReceipt,
withSeatName,
} from './relay-seats.js';
@@ -119,6 +117,7 @@ import { terminalQr } from './qr.js';
import { environmentLink } from './relay-environment.js';
import { locked } from './relay-lock.js';
import { withOutboxGuard } from './relay-outbox-guard.js';
+import { relayOrdering } from './relay-ordering.js';
import { nudgeRelaySender } from './relay-local-first.js';
import { checkpointPublisher } from './relay-checkpoint-publish.js';
import {
@@ -138,11 +137,9 @@ import {
} from './relay-move-fallback.js';
import {
flushOutbox,
- outboxAhead,
outboxFields,
outboxFile,
outboxQueueable,
- outboxWaiting,
readOutboxSummary,
queueMove,
} from './relay-outbox.js';
@@ -979,154 +976,10 @@ function reportRecoveredReply(record, io) {
delete record.lostReply;
}
-/** Apply authenticated relay records in order, each in its own board transaction with a durable receipt. */
-async function applyRecords(root, key, state, records) {
- const outcomes = [];
- for (const record of records) {
- const board = store.openBoard(join(repoInfo(root).commonDir, 'pullboard', 'board.sqlite'), undefined, { isMain: codeIsFromMain() });
- try { outcomes.push(await replayRelayRecord(board, key, state, record)); } finally { store.closeBoard(board); }
- }
- return outcomes;
-}
-
-/** Read and authenticate the relay's checkpoint without touching the board; the caller restores it. */
-async function fetchCheckpoint(state, io, key) {
- const document = await request(state, '/api/v1/boards/' + state.board + '/state', {}, io);
- const snapshot = document.state;
- if (!snapshot || !Number.isSafeInteger(snapshot.sequence) || snapshot.sequence < 0) throw new Refused('RELAY_RESPONSE', 'the relay snapshot has no valid coverage sequence; fetch it again');
- const senderProblem = relaySenderProblem(null, snapshot.sender, 'snapshot');
- if (senderProblem) throw senderProblem;
- return { native: await decoded(key, snapshot, state, 'snapshot', snapshot.sequence), sequence: snapshot.sequence };
-}
-
-/** Most catch-up passes one command makes when moves keep queuing on this machine meanwhile. */
-const CATCH_UP_PASSES = 10;
-
-/** Apply a validated relay prefix with durable, transaction-bound receipts on this replica. */
-async function catchUp(root, file, state, io, pass = 0) {
- if (pass >= CATCH_UP_PASSES) throw new Refused('RELAY_BUSY', 'moves kept queuing on this machine while it caught up; they stay queued for the next send');
- // Queued moves sit on top of this board: the outbox rebuilds it from the relay's order with them on top (#1013).
- if (outboxAhead(state) || outboxWaiting(file)) await flushOutbox(outboxLink(root, file, state, io));
- const key = readBoardKey(state.board);
- const after = localRecords(root, appliedSequence);
- let remote;
- try { remote = await request(state, '/api/v1/boards/' + state.board + '/events?after=' + after, {}, io); }
- catch (error) {
- if (error.code !== 'SNAPSHOT_REQUIRED') throw error;
- const checkpoint = await fetchCheckpoint(state, io, key);
- const restored = await withOutboxGuard(file, () => {
- if (outboxWaiting(file)) return false;
- localRecords(root, (board) => restoreRelaySnapshot(board, checkpoint.native, checkpoint.sequence));
- return true;
- });
- if (!restored) return catchUp(root, file, state, io, pass + 1);
- if (localRecords(root, appliedSequence) <= after) throw new Refused('RELAY_RESPONSE', 'the relay checkpoint did not advance the missing prefix; fetch a consistent newer snapshot');
- return catchUp(root, file, state, io, pass);
- }
- if ([remote.warning, ...(remote.warnings ?? [])].some((warning) => warning?.code === 'KEY_REQUESTS')) io.keyRequestsWaiting = true;
- if (!Array.isArray(remote.events) || remote.events.some((record, index) => !record || record.event_id !== after + index + 1 || !['move', 'request'].includes(record.kind) || typeof record.sealed !== 'string')) {
- throw new Refused('RELAY_RESPONSE', 'the relay returned an invalid ordered prefix; fetch a consistent relay snapshot');
- }
- // Another machine's moves land only on a board with nothing queued on top; a move may have queued meanwhile.
- const outcomes = await withOutboxGuard(file, async () => {
- if (outboxWaiting(file) || localRecords(root, appliedSequence) !== after) return null;
- return applyRecords(root, key, state, remote.events);
- });
- if (!outcomes) return catchUp(root, file, state, io, pass + 1);
- let pendingRefusal;
- remote.events.forEach((record, index) => {
- const outcome = outcomes[index];
- // Exact ciphertext identifies an interrupted send even when its document was refused before replay.
- if (record.kind === 'move' && state.pending?.move && record.event_id === state.pending.sequence
- && record.sealed === state.pending.sealed && outcome?.error
- && !localRecords(root, board => engineReceipt(board, state.pending.move.id))) {
- pendingRefusal = outcome.error;
- reportRecoveredReply(state.pending, io);
- delete state.pending;
- delete state.recovered;
- }
- });
- state.sequence = localRecords(root, appliedSequence);
- if (state.pending?.move && localRecords(root, (board) => engineReceipt(board, state.pending.move.id))) {
- reportRecoveredReply(state.pending, io);
- state.recovered = state.pending;
- delete state.pending;
- }
- saveLink(file, state);
- if (pendingRefusal) throw refusalFromReceipt(pendingRefusal);
-}
-
-/**
- * Post one sealed move to the relay as its actor, renewing an expired seat token once and taking the next free seat
- * name for a registration the relay already gave out. Network only: it applies nothing, so the outbox can send a
- * move while this machine's board still shows its queued moves on top (#1013).
- */
-async function postPending(root, file, state, pending, io) {
- let renewedAgentToken = false;
- for (let tries = 0; tries < 100; tries += 1) {
- const actor = credentialActor(pending.move);
- try {
- const transport = await conflictRecords.transport(root, pending.move, localRecords, () => actorTransport(root, file, state, actor, io));
- const reply = await request(transport, '/api/v1/boards/' + state.board + '/moves', { method: 'POST',
- body: { sequence: pending.sequence, sealed: pending.sealed, ...(pending.registration ? { registration: pending.registration } : {}) } }, io);
- if (reply.event?.event_id !== pending.sequence || reply.event.sealed !== pending.sealed) throw new Refused('RELAY_RESPONSE', 'the relay acknowledgement differs from this executable send; fetch the configured relay');
- if (pending.registration) {
- const enrollment = reply.enrollment;
- if (!enrollment || enrollment.board !== state.board || enrollment.agent !== pending.registration.target || typeof enrollment.id !== 'string') {
- throw new Refused('RELAY_RESPONSE', 'the relay registered the seat without its issuance; repeat this command to recover its token');
- }
- // A retried registration returns the same issuance without a token; its creator reissues it on first use.
- if (enrollment.token !== undefined) cacheSeatToken(file, state, pending.registration.target, enrollment);
- }
- return;
- } catch (error) {
- if (error.code === 'AUTH_REQUIRED' && !renewedAgentToken && actor !== 'machine' && actor !== 'person'
- && process.env.PULLBOARD_RELAY_TOKEN === undefined && state.agentTokens?.[actor]?.token) {
- // An expired cache renews only through the seat's creator; a live one the relay refused was revoked.
- if (state.agentTokens[actor].expires > Date.now()) {
- state.agentTokens[actor].revoked = true;
- saveLink(file, state);
- throw new Refused('TOKEN_REVOKED', `the relay token of ${actor} was revoked on this board; work from a seat with its own token, or ask the coordinator for a fresh worktree`);
- }
- delete state.agentTokens[actor].token;
- saveLink(file, state);
- renewedAgentToken = true;
- continue;
- }
- if (error.code === 'SEAT_TAKEN' && pending.registration) {
- // The relay already gave this name a token (a machine first mint): take the next free name.
- nameNextSeat(root, pending.move, Number(pending.move.args[0].id.slice(pending.move.args[0].lane.length + 1)) + 1);
- pending.sealed = await sealedRecord(readBoardKey(state.board), pending.move, state, 'move', pending.sequence);
- pending.registration = seatReceipt(pending.move, pending.sequence, pending.sealed);
- saveLink(file, state);
- continue;
- }
- throw error;
- }
- }
- throw new Refused('RELAY_BUSY', 'the relay kept refusing this seat name; retry this command after other clients finish');
-}
-
-/** Finish a durable executable send; a collision reseals its unchanged id after applying the winner. */
-async function sendPending(root, file, state, io) {
- for (let tries = 0; state.pending && tries < 100; tries += 1) {
- try { await postPending(root, file, state, state.pending, io); }
- catch (error) {
- if (!['SEQUENCE_REPEAT', 'SEQUENCE_GAP'].includes(error.code)) throw error;
- await catchUp(root, file, state, io);
- if (state.pending) {
- state.pending.sequence = state.sequence + 1;
- if (state.pending.registration) nameNextSeat(root, state.pending.move, 0);
- state.pending.sealed = await sealedRecord(readBoardKey(state.board), state.pending.move, state, 'move', state.pending.sequence);
- state.pending.registration = seatReceipt(state.pending.move, state.pending.sequence, state.pending.sealed);
- saveLink(file, state);
- }
- continue;
- }
- await catchUp(root, file, state, io);
- }
- if (state.pending) throw new Refused('RELAY_BUSY', 'the relay order stayed busy; retry this command after other clients finish');
-}
+// Catch-up and send live in their own module, over these link and transport helpers (#1013).
+const ordering = relayOrdering({ request, localRecords, decoded, replayRelayRecord, reportRecoveredReply, saveLink, sealedRecord,
+ flush: (root, file, state, io) => flushOutbox(outboxLink(root, file, state, io)) });
+const { applyRecords, fetchCheckpoint, catchUp, postPending, sendPending } = ordering;
/** Set up this machine's coordinator token inside a paired join's own person sign-in (#579). */
export async function relayPersonCoordinator(root, session, io) {
diff --git a/test/relay-local-first.test.js b/test/relay-local-first.test.js
index 96ea8523..b5489bab 100644
--- a/test/relay-local-first.test.js
+++ b/test/relay-local-first.test.js
@@ -10,13 +10,13 @@ import { fileURLToPath } from 'node:url';
import { ACCESS_WINDOW_MS } from '../relay/auth.js';
import * as store from '../src/board.js';
import { captureBoardChanges } from '../src/board-capture.js';
+import { SENDER_WORKER } from '../src/relay-local-first.js';
import { outboxGuardFile } from '../src/relay-outbox-guard.js';
import { undoQueued } from '../src/relay-outbox-undo.js';
import { runFixtureChildAsync, runFixtureGit } from './fixture-child.js';
import { relayClientFixture, relayFixtureChild } from './relay-client-fixture.js';
const CLI = fileURLToPath(new URL('../bin/pullboard.js', import.meta.url));
-const WORKER = fileURLToPath(new URL('../src/relay-sender-worker.js', import.meta.url));
// Budget: the criterion's bar for a move or a read, measured from spawn to exit of the real CLI.
const LOCAL_MS = 1_000;
// Budget: how long a test waits for the background sender to reach the relay; it polls every 200 ms here.
@@ -60,7 +60,7 @@ async function stopSender(env) {
/** Every running sender process from this checkout's worker file. */
function runningSenders() {
return execFileSync('ps', ['-Ao', 'pid=,command='], { encoding: 'utf8' }).split('\n')
- .filter(line => line.includes(WORKER)).length;
+ .filter(line => line.includes(SENDER_WORKER)).length;
}
/** Wait until `ready()` holds, or fail naming what never happened and what `detail()` says. */
@@ -97,7 +97,7 @@ async function local(box, t, cwd, env, name, args) {
const fetches = existsSync(trace) ? readFileSync(trace, 'utf8').trim().split('\n').length : 0;
t.diagnostic(JSON.stringify({ name, elapsedMs: result.elapsedMs, status: result.status, foregroundFetches: fetches }));
assert.equal(result.status, 0, result.context);
- assert.ok(result.elapsedMs < LOCAL_MS, `${name} took ${result.elapsedMs} ms; a local-first command returns within one second`);
+ assert.ok(result.elapsedMs < LOCAL_MS, `${name} took ${result.elapsedMs} ms; a local-first command returns within one second`); // budget: declared by #1013's frozen bar: a local move or read returns within one second.
assert.equal(fetches, 0, `${name} made no network call`);
return { document: JSON.parse(result.stdout), stderr: result.stderr };
}