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.

test(x402,oracle): extend the identity studio batch pricing and database outage coverage

nirholasfdbaeb5a9479
diff --git a/tests/api/okx-identity-studio.test.js b/tests/api/okx-identity-studio.test.js
index 4974e8a9a..ebaba7351 100644
--- a/tests/api/okx-identity-studio.test.js
+++ b/tests/api/okx-identity-studio.test.js
@@ -11,6 +11,7 @@
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Readable } from 'node:stream';
+import { encodeAbiParameters, parseAbiParameters } from 'viem';
process.env.PUBLIC_APP_ORIGIN = 'https://three.ws';
process.env.X402_PAY_TO_BASE ||= '0x0000000000000000000000000000000000000001';
@@ -85,7 +86,16 @@ vi.mock('../../api/_lib/llm.js', () => ({
// The pipeline is a pure HTTP client over three.ws surfaces — mock global
// fetch with a tiny programmable router.
-const fetchRoutes = { chat: null, forgeSubmit: null, forgePoll: null, rig: null, render: null, ref: null };
+const fetchRoutes = {
+ chat: null,
+ forgeSubmit: null,
+ forgePoll: null,
+ rig: null,
+ render: null,
+ manifest: null,
+ rpc: null,
+ ref: null,
+};
function jsonResponse(status, body) {
return new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
}
@@ -97,6 +107,46 @@ const FORGE_CATALOG = {
backends: [{ id: 'trellis' }, { id: 'hunyuan3d' }],
};
+// The payment-rail probe drives a real viem public client over chain 196, so
+// the only honest seam is the JSON-RPC wire itself. Answer the three calls
+// xlayerRailHealth() makes (block height, the fee token's symbol(), the
+// relayer's balance) with correctly encoded results.
+function jsonRpcBody(init) {
+ if (!init?.body || typeof init.body !== 'string') return null;
+ try {
+ const parsed = JSON.parse(init.body);
+ const one = Array.isArray(parsed) ? parsed[0] : parsed;
+ return one?.jsonrpc === '2.0' && typeof one.method === 'string' ? one : null;
+ } catch {
+ return null;
+ }
+}
+
+const XLAYER_RPC_RESULTS = {
+ eth_chainId: '0xc4',
+ eth_blockNumber: '0x40c8c01',
+ eth_getBalance: '0x2386f26fc10000',
+ eth_call: encodeAbiParameters(parseAbiParameters('string'), ['USD₮0']),
+ eth_gasPrice: '0x3b9aca00',
+};
+
+function healthyXlayerRpc(_url, init) {
+ const rpc = jsonRpcBody(init);
+ const result = XLAYER_RPC_RESULTS[rpc?.method] ?? '0x';
+ return jsonResponse(200, { jsonrpc: '2.0', id: rpc?.id ?? 1, result });
+}
+
+// The five subsystems GET /health actually probes: the forge tier/backend
+// matrix, the renderer's pose catalog, R2 (the in-memory mock above), the
+// animation clip manifest, and the X Layer rail. Mount a healthy shape for
+// each so the green path is proven through the real probe plumbing.
+function mountHealthyProbes() {
+ fetchRoutes.forgeSubmit = () => jsonResponse(200, FORGE_CATALOG);
+ fetchRoutes.render = () => jsonResponse(200, { poses: ['idle', 'walk', 'tpose'] });
+ fetchRoutes.manifest = () => jsonResponse(200, { animations: [{ id: 'idle' }, { id: 'walk' }] });
+ fetchRoutes.rpc = healthyXlayerRpc;
+}
+
const realFetch = globalThis.fetch;
beforeEach(() => {
r2Store.clear();
@@ -106,6 +156,10 @@ beforeEach(() => {
fetchRoutes.forgePoll = () => jsonResponse(200, { status: 'running' });
fetchRoutes.rig = () => jsonResponse(200, { job_id: 'forge-rig-1', status: 'queued' });
fetchRoutes.render = () => new Response(new Uint8Array(MODEL_PNG), { status: 200 });
+ fetchRoutes.manifest = () => jsonResponse(200, { animations: [{ id: 'idle' }] });
+ // Default: no rail. A case that wants a green payment-rail probe calls
+ // mountHealthyProbes().
+ fetchRoutes.rpc = () => new Response('rpc unavailable', { status: 503 });
fetchRoutes.ref = () => new Response(new Uint8Array([0xff]), { status: 206, headers: { 'content-type': 'image/png' } });
globalThis.fetch = vi.fn(async (url, init = {}) => {
const u = String(url);
@@ -114,6 +168,8 @@ beforeEach(() => {
if (u.includes('/api/forge?job=')) return fetchRoutes.forgePoll(u, init);
if (u.includes('/api/forge')) return fetchRoutes.forgeSubmit(u, init);
if (u.includes('/api/render/avatar-clip')) return fetchRoutes.render(u, init);
+ if (u.includes('/animations/manifest.json')) return fetchRoutes.manifest(u, init);
+ if (jsonRpcBody(init)) return fetchRoutes.rpc(u, init);
return fetchRoutes.ref(u, init);
});
return () => {
@@ -261,7 +317,7 @@ describe('free lanes over HTTP', () => {
// report is memoized for OKX_HEALTH_TTL_MS: a poll loop costs one sweep per
// window, not one per request.
it('GET /health memoizes the sweep within the TTL window', async () => {
- fetchRoutes.forgeSubmit = () => jsonResponse(200, FORGE_CATALOG);
+ mountHealthyProbes();
// First call with the memo off, so this case sweeps for real and seeds a
// reading of its own instead of inheriting an earlier test's.
const first = makeRes();
diff --git a/tests/oracle/api-db-outage.test.js b/tests/oracle/api-db-outage.test.js
index 7401eb5be..9451dc868 100644
--- a/tests/oracle/api-db-outage.test.js
+++ b/tests/oracle/api-db-outage.test.js
@@ -65,8 +65,17 @@ vi.mock('../../api/_lib/db.js', async () => {
};
});
-// A Neon transport failure, exactly as db.js classifies one.
-const CONN_ERROR = new Error('Error connecting to database: fetch failed');
+// A Neon transport failure, shaped the way the driver actually throws one: the
+// `name` field is load-bearing, because db.js only treats a connection-level
+// message as an outage when it arrives on a NeonDbError (or a bare fetch
+// TypeError). A plain Error with the same text is NOT an outage to the
+// classifier, so a fixture without the name would silently test nothing.
+const CONN_ERROR = Object.assign(new Error('Error connecting to database: fetch failed'), {
+ name: 'NeonDbError',
+});
+// The other real-world outage shape: an unset or rotated DATABASE_URL, which
+// makes the lazy client construction throw a plain Error.
+const NO_URL_ERROR = new Error('Missing required env var: DATABASE_URL');
// A deterministic SQL bug. Never a 503: the empty-result degrade is correct here.
const STATEMENT_ERROR = new Error('column "nope" does not exist');
@@ -118,7 +127,7 @@ beforeEach(() => {
describe('the classifier these handlers branch on', () => {
it('separates a connectivity failure from a statement fault', () => {
expect(isDbUnavailableError(CONN_ERROR)).toBe(true);
- expect(isDbUnavailableError(new Error('Missing required env var: DATABASE_URL'))).toBe(true);
+ expect(isDbUnavailableError(NO_URL_ERROR)).toBe(true);
expect(isDbUnavailableError(STATEMENT_ERROR)).toBe(false);
});
});
@@ -183,9 +192,10 @@ describe('/api/oracle/follow', () => {
});
it('DELETE propagates a failed delete instead of confirming an unsubscribe that never ran', async () => {
- nextDbError = CONN_ERROR;
+ // Uses the unset-DATABASE_URL shape so both outage shapes are exercised.
+ nextDbError = NO_URL_ERROR;
const req = fakeReq('/api/oracle/follow', { method: 'DELETE', body: { agent_id: AGENT_ID, chat_id: '12345' } });
- await expect(follow(req, fakeRes())).rejects.toThrow(/connecting to database/);
+ await expect(follow(req, fakeRes())).rejects.toThrow(/DATABASE_URL/);
});
it('GET still answers 200 following: false when the subscription genuinely is absent', async () => {