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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
test(ops): cover the ops boards' read bucket and degraded status, and document them
nirholasf0934dd6b0bf
diff --git a/api/ops/money-health.js b/api/ops/money-health.jsindex 836adf52e..898b660bf 100644--- a/api/ops/money-health.js+++ b/api/ops/money-health.js@@ -14,7 +14,8 @@// of those; and ADMIN_TOKEN is set nowhere (no getter on the env facade, no// Cloud Run var), so that second door was dead code guarding nothing.-import { cors, json, method, wrap, error } from '../_lib/http.js';+import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';+import { limits, clientIp } from '../_lib/rate-limit.js';import { sql } from '../_lib/db.js';import { authorizeOps } from '../_lib/ops-auth.js';@@ -52,6 +53,13 @@ export async function lastActivity(table, ts) {export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,OPTIONS' })) return;if (!method(req, res, ['GET'])) return;++ // Same ceiling as the sibling boards: a session lookup runs before the gate can+ // answer, and the board itself is six aggregate queries. `authedReadIp` keeps a+ // polled dashboard out of the strict `authIp` credential budget.+ const rl = await limits.authedReadIp(clientIp(req));+ if (!rl.success) return rateLimited(res, rl);+const auth = await authorizeOps(req);if (!auth.ok) return error(res, 401, 'unauthorized', 'ops secret or admin session required');diff --git a/docs/ops/payment-outcomes.md b/docs/ops/payment-outcomes.mdindex 185dfd193..61d8d35a7 100644--- a/docs/ops/payment-outcomes.md+++ b/docs/ops/payment-outcomes.md@@ -15,6 +15,26 @@ means open in dev and denied in production. Read-only; it moves no funds andnever fires alerts (balance reads go through the ring monitor with alertingdisabled; the scheduled monitor owns paging).+Per-IP ceiling: the `authedReadIp` bucket (300 requests / 5 min), shared with+`/api/ops/health` and `/api/ops/money-health`. It is deliberately not the strict+`authIp` credential bucket, so polling a board cannot 429 an operator's login+from the same address. Over the ceiling the response is `429 rate_limited` with+a `retry-after` header.++## The response envelope++```json+{ "ok": true, "degraded": [], "generated_at": "…", "inbound": {…}, "ring_settle": {…}, "sponsor": {…} }+```++The three panels are read independently, so one failing never blanks the others+(an RPC outage is exactly when the settle panels matter most). `ok` reports+whether the BOARD rendered, never whether payments are healthy: that verdict is+per panel. A panel that threw is replaced by `{ "error": "…" }`, named in+`degraded`, and the status code is `207 Multi-Status` instead of `200`, the same+convention `/api/ops/health` uses. Alert on `degraded` being non-empty: a board+that cannot see is not a board that is fine.+## The three panels### `inbound` (from `x402_audit_log`)diff --git a/tests/api/ops-endpoints.test.js b/tests/api/ops-endpoints.test.jsindex 7e1544c8f..a788eda41 100644--- a/tests/api/ops-endpoints.test.js+++ b/tests/api/ops-endpoints.test.js@@ -14,6 +14,12 @@// authorizeOps with its neighbours now.// 3. money-health's activity probe swallowed every error, so a wrong column// name rendered as "no activity" forever. Only a missing table is silence.+// 4. payment-outcomes answered a literal ok:true even when all three panels+// threw, so a blind board reported success. It names the failed panels in+// `degraded` and answers 207 now.+// 5. all three boards spent the strict `authIp` credential budget, so polling+// a dashboard could 429 the operator's login from the same IP. They use the+// `authedReadIp` polled-read bucket.import { describe, it, expect, vi, beforeEach } from 'vitest';@@ -22,8 +28,11 @@ vi.mock('../../api/_lib/ops-auth.js', () => ({authorizeOps: vi.fn(async () => (authOk ? { ok: true, actor: 'ops-secret' } : { ok: false, actor: '' })),}));+let rateLimitOk = true;vi.mock('../../api/_lib/rate-limit.js', () => ({- limits: { authIp: vi.fn(async () => ({ success: true })) },+ limits: {+ authedReadIp: vi.fn(async () => ({ success: rateLimitOk, limit: 300, remaining: 0, reset: Date.now() + 1000 })),+ },clientIp: () => '127.0.0.1',}));@@ -74,6 +83,7 @@ const MIN = 60 * 1000;beforeEach(() => {authOk = true;+ rateLimitOk = true;sqlImpl = async () => [];settleHealthImpl = async () => ({ name: 'x402_settle', status: 'ok' });ringWalletsImpl = async () => ({ wallets: [], sponsorRunway: null });@@ -194,15 +204,44 @@ describe('GET /api/ops/payment-outcomes', () => {expect(body.error).toBe('unauthorized');});- it('keeps the surviving panels when one panel fails', async () => {+ it('keeps the surviving panels when one panel fails, and says which is blind', async () => {// An RPC outage is exactly when the settle panels matter most, so a dead- // sponsor read must not blank the inbound ledger.+ // sponsor read must not blank the inbound ledger. It must also not be+ // reported as a healthy board: the failure is named and the status is 207.ringWalletsImpl = async () => { throw new Error('rpc unreachable'); };sqlImpl = async () => [{ event_type: 'payment_settled', h1: 1, h3: 2, h24: 9 }];const { res, body } = await call(paymentOutcomesHandler, '/api/ops/payment-outcomes');- expect(res.statusCode).toBe(200);+ expect(res.statusCode).toBe(207);+ expect(body.ok).toBe(false);+ expect(body.degraded).toEqual(['sponsor']);expect(body.sponsor.error).toBe('rpc unreachable');expect(body.inbound.windows['24h'].settled).toBe(9);expect(body.ring_settle.status).toBe('ok');});++ it('reports ok with an empty degraded list when every panel renders', async () => {+ const { res, body } = await call(paymentOutcomesHandler, '/api/ops/payment-outcomes');+ expect(res.statusCode).toBe(200);+ expect(body.ok).toBe(true);+ expect(body.degraded).toEqual([]);+ });+});++describe('the ops boards share the polled-read bucket, not the credential bucket', () => {+ // A dashboard poll used to spend the same 50/10m `authIp` budget that gates+ // logins from that IP, so watching the board could 429 the operator's sign-in.+ const boards = [+ ['health', () => health.default],+ ['money-health', () => moneyHealthHandler],+ ['payment-outcomes', () => paymentOutcomesHandler],+ ];++ for (const [name, handler] of boards) {+ it(`answers 429 on /api/ops/${name} when the read bucket is exhausted`, async () => {+ rateLimitOk = false;+ const { res, body } = await call(handler(), `/api/ops/${name}`);+ expect(res.statusCode).toBe(429);+ expect(body.error).toBe('rate_limited');+ });+ }});