Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

Enhance tests by mocking SSRF guard to enforce maxBytes validation for staged responses

nirholas9802a5e40d1a
diff --git a/tests/api/forge-health.test.js b/tests/api/forge-health.test.js
index 9f42955af..e159c9e04 100644
--- a/tests/api/forge-health.test.js
+++ b/tests/api/forge-health.test.js
@@ -23,6 +23,11 @@ const ENV_VARS = [
'three_KV_REST_API_TOKEN',
'KV_REST_API_URL',
'KV_REST_API_TOKEN',
+ // The host shell can leak a real OpenAI key into the suite (workspaces and
+ // CI both carry one); the health probe treats any present key as a
+ // configured backend and would probe api.openai.com, breaking the
+ // nothing-configured assertions. Scrub it with the rest.
+ 'OPENAI_API_KEY',
'VERCEL_ENV',
];
const savedEnv = {};
diff --git a/tests/api/x402-pipeline-stages.test.js b/tests/api/x402-pipeline-stages.test.js
index a4b1781c0..353748276 100644
--- a/tests/api/x402-pipeline-stages.test.js
+++ b/tests/api/x402-pipeline-stages.test.js
@@ -20,6 +20,32 @@ import { dirname, resolve } from 'node:path';
import Ajv2020 from 'ajv/dist/2020.js';
import addFormats from 'ajv-formats';
+// pipeline-stage.js fetches through the pinned SSRF guard (raw sockets, no
+// sandbox egress). Route the guard through the per-test fetch spy so those
+// staged responses stay authoritative, and enforce opts.maxBytes the way the
+// real guard does so the byte-cap branches keep their meaning.
+vi.mock('../../api/_lib/ssrf-guard.js', async () => {
+ const actual = await vi.importActual('../../api/_lib/ssrf-guard.js');
+ return {
+ ...actual,
+ fetchSafePublicUrlPinned: async (url, init, opts) => {
+ const resp = await globalThis.fetch(url, init);
+ if (opts?.maxBytes == null) return resp;
+ const buf = await resp.arrayBuffer();
+ if (buf.byteLength > opts.maxBytes) {
+ throw new actual.MaxBytesExceededError(buf.byteLength, opts.maxBytes);
+ }
+ return {
+ ok: resp.ok,
+ status: resp.status,
+ headers: resp.headers ?? new Headers(),
+ arrayBuffer: async () => buf,
+ text: async () => Buffer.from(buf).toString('utf8'),
+ };
+ },
+ };
+});
+
import {
StageError,
isGlbMagic,