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(avatar-agent-mcp): cover the on-chain name resolver and the published schema copy
nirholas6793327cbe46
diff --git a/packages/avatar-agent-mcp/test/ens-sns.test.mjs b/packages/avatar-agent-mcp/test/ens-sns.test.mjsnew file mode 100644index 000000000..30bb16f6e--- /dev/null+++ b/packages/avatar-agent-mcp/test/ens-sns.test.mjs@@ -0,0 +1,71 @@+// Name-resolution routing for `ens_sns_resolve`: which lane a given input is+// dispatched to, and what a caller sees when no lane can answer.+//+// The lanes themselves are live chain reads (ENS over ETH_RPC_URL, SNS over the+// SPL Name Service accounts on SOLANA_RPC_URL), so this file covers what the+// module decides before any request is made: routing, normalization, the+// shared timeout budget, and the refusal shape. Nothing here mocks a chain.+//+// Run: node --test packages/avatar-agent-mcp/test/ens-sns.test.mjs++import { test } from 'node:test';+import assert from 'node:assert/strict';++import { classifyName, resolveName } from '../src/lib/ens-sns.js';+import { NAME_RESOLVE_TIMEOUT_MS } from '../src/config.js';++test('the shared per-lane timeout leaves room for a cold multi-hop lookup', () => {+ // A cold ENS resolution (registry → resolver → addr) measured ~4.4s against a+ // public RPC, and the SNS resolver adds its own account reads. A low-seconds+ // budget reports "timed out" for names that resolve fine.+ assert.equal(NAME_RESOLVE_TIMEOUT_MS, 15000);+ assert.ok(NAME_RESOLVE_TIMEOUT_MS >= 10000, 'budget must survive a cold public RPC');+});++test('a .eth name routes to ENS only', () => {+ for (const input of ['vitalik.eth', 'sub.domain.eth', 'EXAMPLE.ETH']) {+ const { isEns, isSol } = classifyName(input);+ assert.equal(isEns, true, `${input} should be an ENS name`);+ assert.equal(isSol, false, `${input} must not be dispatched to SNS`);+ }+});++test('a .sol name and a bare label both route to SNS only', () => {+ for (const input of ['bonfida.sol', 'toly.sol', 'bonfida']) {+ const { isEns, isSol } = classifyName(input);+ assert.equal(isSol, true, `${input} should be an SNS name`);+ assert.equal(isEns, false, `${input} must not be dispatched to ENS`);+ }+});++test('classification normalizes case and surrounding whitespace', () => {+ assert.equal(classifyName(' BONFIDA.SOL ').trimmed, 'bonfida.sol');+ assert.equal(classifyName(' Vitalik.ETH ').trimmed, 'vitalik.eth');+});++test('an unroutable input matches no lane', () => {+ for (const input of ['not a name!!', '', ' ', null, undefined, 'foo.bar']) {+ const { isEns, isSol } = classifyName(input);+ assert.equal(isEns || isSol, false, `${JSON.stringify(input)} should match no lane`);+ }+});++test('an unroutable input is refused without touching a chain', async () => {+ const started = Date.now();+ const out = await resolveName('not a name!!');+ assert.equal(out.ok, false);+ assert.equal(out.error, 'invalid_name');+ assert.ok(Date.now() - started < 1000, 'refusal must not wait on any network call');+});++test('an SNS label longer than 63 characters is declined locally', async () => {+ const started = Date.now();+ const out = await resolveName(`${'a'.repeat(64)}.sol`);+ assert.equal(out.ok, false);+ assert.equal(out.error, 'not_found');+ // The lane ran and rejected the label on shape rather than erroring upstream.+ assert.equal(out.sns, null);+ assert.equal(out.ens, null);+ assert.ok(typeof out.fetchedAt === 'string' && !Number.isNaN(Date.parse(out.fetchedAt)));+ assert.ok(Date.now() - started < 1000, 'an invalid label must not reach the chain');+});diff --git a/tests/avatar-schema-published-copy.test.js b/tests/avatar-schema-published-copy.test.jsnew file mode 100644index 000000000..313b7f54b--- /dev/null+++ b/tests/avatar-schema-published-copy.test.js@@ -0,0 +1,30 @@+// The avatar manifest schema is published at its own `$id`+// (https://three.ws/schema/avatar.v1.json) so any third-party validator can+// dereference it, which means the bytes under public/ must stay identical to+// the canonical copy inside @three-ws/avatar-schema. Nothing copies them at+// build time (public/ is Vite's publicDir, verbatim), so this is the guard:+// edit the package copy and this fails until the served copy is updated too.++import { describe, it, expect } from 'vitest';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';++const CANONICAL = fileURLToPath(new URL('../packages/avatar-schema/schema/avatar.v1.json', import.meta.url));+const PUBLISHED = fileURLToPath(new URL('../public/schema/avatar.v1.json', import.meta.url));++describe('published avatar schema', () => {+ it('is byte-identical to the package copy', () => {+ expect(readFileSync(PUBLISHED)).toEqual(readFileSync(CANONICAL));+ });++ it('declares the $id it is served from', () => {+ const schema = JSON.parse(readFileSync(PUBLISHED, 'utf8'));+ expect(schema.$id).toBe('https://three.ws/schema/avatar.v1.json');+ });++ it('matches the SCHEMA_ID the package advertises', async () => {+ const { SCHEMA_ID, schema } = await import('../packages/avatar-schema/src/index.js');+ expect(SCHEMA_ID).toBe('https://three.ws/schema/avatar.v1.json');+ expect(schema.$id).toBe(SCHEMA_ID);+ });+});