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): name transport failures; refuse stale drops [H3,H16]

Corey Olson62b7a12d0de1
diff --git a/src/relay.js b/src/relay.js
index 78ed272b..129d02bf 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -142,6 +142,17 @@ function notices(document, io) {
}
}
+/**
+ * Name how a relay request failed before any response, from the error's own fields only.
+ * Why: a bare "did not answer" hid whether a request timed out, was refused or lost its socket,
+ * so load-dependent relay failures could not be attributed (#512).
+ */
+function transportFailure(error) {
+ if (error?.name === 'TimeoutError' || error?.name === 'AbortError') return 'timed out';
+ const code = error?.cause?.code ?? error?.code;
+ return typeof code === 'string' && /^[A-Z][A-Z0-9_]{1,40}$/u.test(code) ? code : 'no connection';
+}
+
/** The sole outbound transport in the CLI: explicit sign-in or a saved, opted-in board link. */
async function request(state, path, { method = 'GET', body, allowMissing = false, initialBaseline = false } = {}, io) {
const supplied = process.env.PULLBOARD_RELAY_TOKEN;
@@ -149,13 +160,18 @@ async function request(state, path, { method = 'GET', body, allowMissing = false
if (readToken !== undefined && !/^pa_[A-Za-z0-9_-]{43}$/.test(readToken)) throw new Refused('AUTH_REQUIRED', 'supply a current scoped board token without including it in command arguments');
const token = readToken ?? state.token;
let response;
+ const startedAt = Date.now();
try {
response = await fetch(relayOrigin(state.url) + path, {
method, redirect: 'error', signal: AbortSignal.timeout(10000),
headers: { 'x-pullboard-engine': String(ENGINE_VERSION), ...(token ? { authorization: 'Bearer ' + token } : {}), ...(body === undefined ? {} : { 'content-type': 'application/json' }), ...(initialBaseline ? { 'if-none-match': '*' } : {}) },
...(body === undefined ? {} : { body: JSON.stringify(body) }),
});
- } catch { throw new Refused('RELAY_UNAVAILABLE', `the relay ${state.url} did not answer; read the local board offline, then retry this move when the relay is reachable`); }
+ } catch (error) {
+ const refusal = new Refused('RELAY_UNAVAILABLE', `the relay ${state.url} did not answer (${transportFailure(error)} after ${Date.now() - startedAt} ms on ${method} ${path.split('?')[0]}); read the local board offline, then retry this move when the relay is reachable`);
+ refusal.transportFailure = transportFailure(error);
+ throw refusal;
+ }
let document;
try { document = await response.json(); }
catch {
diff --git a/test/relay-client.test.js b/test/relay-client.test.js
index 17ae375b..e22a9f39 100644
--- a/test/relay-client.test.js
+++ b/test/relay-client.test.js
@@ -235,7 +235,22 @@ async function relayServer(t, directory, auth) {
server.closeAllConnections();
await closed;
});
- return { origin, calls, uploads, failMoves(value) { refuseMoves = value; }, dropNextReply({ offline = false } = {}) { loseReply = true; blockAfterDrop = offline; }, failReads(value) { refuseReads = value; }, advance(days) { now = Date.now() + days * 86400000; } };
+ let dropArmedAt = null;
+ /**
+ * Refuse to continue while an armed reply drop was never consumed by a move.
+ * Why: the drop is global, so a step that failed before posting its move left it armed,
+ * and the next step's move (an innocent retry) was destroyed instead (#512).
+ */
+ function requireDropConsumed(at) {
+ if (!loseReply) return;
+ const since = calls.slice(dropArmedAt).map(({ method, path }) => `${method} ${path.split('?')[0]}`);
+ throw new Error(`relay fixture: the reply drop armed before ${at} was never consumed by a move; relay calls since arming: ${since.join(', ') || 'none'}`);
+ }
+ return { origin, calls, uploads, failMoves(value) { refuseMoves = value; },
+ dropNextReply({ offline = false } = {}) { requireDropConsumed('arming another drop'); loseReply = true; blockAfterDrop = offline; dropArmedAt = calls.length; },
+ dropPending() { return loseReply; },
+ failReads(value) { if (!value) requireDropConsumed('reads were restored'); refuseReads = value; },
+ advance(days) { now = Date.now() + days * 86400000; } };
}
test('[H1,H3,H7,H15,H16] relay on snapshots and orders ciphertext, refuses offline moves, and off preserves the board', async (t) => {