From 1758f5ebb70bd9ac2636bc8284e66a242c4dac18 Mon Sep 17 00:00:00 2001 From: Greg Soucy Date: Fri, 20 Mar 2026 16:41:50 -0400 Subject: [PATCH] [runtime] harden chain verify warmup handling Why: keep the signing chain test deterministic while schema validator startup can briefly return 202 in CI. Contract impact: none --- runtime/tests/runtime-signing.test.mjs | 34 ++++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/runtime/tests/runtime-signing.test.mjs b/runtime/tests/runtime-signing.test.mjs index 7032880..a8801f2 100644 --- a/runtime/tests/runtime-signing.test.mjs +++ b/runtime/tests/runtime-signing.test.mjs @@ -471,15 +471,28 @@ test("full chain clean -> summarize -> classify verifies with schema using parti async function verifyReceiptWithTimeout(receipt) { const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 5000); + const timeout = setTimeout(() => controller.abort(), 10000); - try { - const res = await fetch(`${srv.base}/verify?schema=1`, { + async function postVerify() { + return fetch(`${srv.base}/verify?schema=1`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(receipt), signal: controller.signal, }); + } + + try { + let res = await postVerify(); + console.log("[chain] verify response status", res.status); + + if (res.status === 202) { + console.log("validator warming"); + await new Promise((resolve) => setTimeout(resolve, 1200)); + res = await postVerify(); + console.log("[chain] verify response status", res.status); + } + const text = await res.text(); let json; @@ -489,7 +502,7 @@ test("full chain clean -> summarize -> classify verifies with schema using parti json = null; } - if (!res.ok && res.status !== 202) { + if (!res.ok) { throw new Error(`HTTP ${res.status}: ${text}`); } @@ -526,20 +539,9 @@ test("full chain clean -> summarize -> classify verifies with schema using parti assert.equal(finalReceipt.x402.entry, "x402://classifyagent.eth/classify/v1.1.0"); console.log("[chain] before verify request"); - let verifyAttempt = await verifyReceiptWithTimeout(finalReceipt); + const verifyAttempt = await verifyReceiptWithTimeout(finalReceipt); console.log("[chain] after verify response", verifyAttempt.res.status, verifyAttempt.json ?? verifyAttempt.text); - if ( - verifyAttempt.res.status === 202 - && verifyAttempt.json?.reason === "validator_not_warmed_yet" - ) { - console.log("[chain] verify warmup 202 response", verifyAttempt.json); - await new Promise((resolve) => setTimeout(resolve, 1200)); - console.log("[chain] before verify request retry"); - verifyAttempt = await verifyReceiptWithTimeout(finalReceipt); - console.log("[chain] after verify response retry", verifyAttempt.res.status, verifyAttempt.json ?? verifyAttempt.text); - } - const verifyRes = verifyAttempt.res; const verifyJson = verifyAttempt.json;