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: add API + ARKit-52 unit tests, plus deploy-page inspect script

nirholas4fc24e73cf37
diff --git a/inspect-deploy.mjs b/inspect-deploy.mjs
new file mode 100644
index 000000000..addf65077
--- /dev/null
+++ b/inspect-deploy.mjs
@@ -0,0 +1,54 @@
+import { chromium } from 'playwright';
+
+const browser = await chromium.launch();
+const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
+
+const errs = [];
+page.on('console', (m) => { if (m.type() === 'error' || m.type() === 'warn') errs.push(`[${m.type()}] ${m.text()}`); });
+page.on('pageerror', (e) => errs.push(`[pageerror] ${e.message}`));
+
+await page.goto('http://localhost:3000/deploy', { waitUntil: 'networkidle' });
+await page.waitForTimeout(2500);
+
+const info = await page.evaluate(() => {
+ const q = (sel) => document.querySelector(sel);
+ const dims = (el) => {
+ if (!el) return null;
+ const r = el.getBoundingClientRect();
+ const cs = getComputedStyle(el);
+ return {
+ tag: el.tagName,
+ cls: (el.className?.toString() || '').slice(0, 80),
+ x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height),
+ display: cs.display, position: cs.position, visibility: cs.visibility, opacity: cs.opacity,
+ z: cs.zIndex,
+ text: (el.textContent || '').trim().slice(0, 60),
+ };
+ };
+ return {
+ bodyClass: document.body.className,
+ shell: dims(q('.deploy-shell')),
+ hero: dims(q('.deploy-hero')),
+ heroText: dims(q('.deploy-hero-text')),
+ heroEyebrow: dims(q('.deploy-hero-eyebrow')),
+ heroTitle: dims(q('.deploy-hero-title')),
+ heroSub: dims(q('.deploy-hero-sub')),
+ heroMeta: dims(q('.deploy-hero-meta')),
+ heroControls: dims(q('.deploy-hero-controls')),
+ chainSelect: dims(q('.deploy-shell .erc8004-chain-select')),
+ walletBtn: dims(q('.deploy-wallet-btn')),
+ banner: dims(q('[data-role="mainnet-banner"]')),
+ grid: dims(q('.deploy-grid')),
+ preview: dims(q('.deploy-preview')),
+ previewThumb: dims(q('.deploy-preview-thumb')),
+ deployPage: dims(q('.deploy-page')),
+ };
+});
+
+console.log(JSON.stringify(info, null, 2));
+console.log('\n--- CONSOLE ---');
+console.log(errs.slice(0, 20).join('\n'));
+
+await page.screenshot({ path: '/tmp/deploy-actual.png', fullPage: false });
+
+await browser.close();
diff --git a/tests/api/assets.test.js b/tests/api/assets.test.js
new file mode 100644
index 000000000..a957e1a84
--- /dev/null
+++ b/tests/api/assets.test.js
@@ -0,0 +1,157 @@
+// Tests for /api/assets — public asset library REST API. Reads on-disk
+// manifests from /public/* via fs; no mocking needed for those (the real
+// committed files are stable for the test).
+
+import { describe, it, expect, beforeAll } from 'vitest';
+import { Readable } from 'node:stream';
+
+process.env.PUBLIC_APP_ORIGIN = 'https://three.ws';
+
+const { default: handler } = await import('../../api/assets/index.js');
+
+function makeReq(qs = '') {
+ const req = Readable.from([]);
+ req.method = 'GET';
+ req.url = qs ? `/api/assets?${qs}` : '/api/assets';
+ req.headers = { host: 'three.ws' };
+ return req;
+}
+
+function makeRes() {
+ return {
+ statusCode: 200,
+ headers: {},
+ body: '',
+ writableEnded: false,
+ setHeader(k, v) {
+ this.headers[k.toLowerCase()] = v;
+ },
+ end(chunk) {
+ if (chunk !== undefined) this.body += chunk;
+ this.writableEnded = true;
+ },
+ };
+}
+
+async function invoke(qs) {
+ const req = makeReq(qs);
+ const res = makeRes();
+ await handler(req, res);
+ return { res, status: res.statusCode, body: res.body ? JSON.parse(res.body) : null };
+}
+
+describe('GET /api/assets', () => {
+ let all;
+ beforeAll(async () => {
+ const result = await invoke('limit=500');
+ all = result.body;
+ });
+
+ it('returns ok=true and a total + items list', () => {
+ expect(all.ok).toBe(true);
+ expect(typeof all.total).toBe('number');
+ expect(Array.isArray(all.items)).toBe(true);
+ });
+
+ it('serves accessories, animations, and environments together by default', () => {
+ const types = new Set(all.items.map((i) => i.type));
+ expect(types.has('accessory')).toBe(true);
+ expect(types.has('animation')).toBe(true);
+ expect(types.has('environment')).toBe(true);
+ });
+
+ it('every item has an id, type, and name', () => {
+ for (const i of all.items) {
+ expect(i.id, JSON.stringify(i)).toBeTruthy();
+ expect(i.type).toBeTruthy();
+ expect(i.name).toBeTruthy();
+ }
+ });
+
+ it('rejects non-GET methods', async () => {
+ const req = makeReq();
+ req.method = 'POST';
+ const res = makeRes();
+ await handler(req, res);
+ expect(res.statusCode).toBe(405);
+ });
+
+ it('filters by type=accessory', async () => {
+ const { body } = await invoke('type=accessory');
+ expect(body.items.every((i) => i.type === 'accessory')).toBe(true);
+ });
+
+ it('filters by type=animation', async () => {
+ const { body } = await invoke('type=animation');
+ expect(body.items.every((i) => i.type === 'animation')).toBe(true);
+ // Animation items expose loop + clip_url
+ for (const i of body.items) {
+ expect(typeof i.loop).toBe('boolean');
+ expect(i.clip_url).toBeTruthy();
+ }
+ });
+
+ it('filters animations by loop=true', async () => {
+ const { body } = await invoke('type=animation&loop=true');
+ expect(body.items.length).toBeGreaterThan(0);
+ expect(body.items.every((i) => i.loop === true)).toBe(true);
+ });
+
+ it('filters animations by loop=false', async () => {
+ const { body } = await invoke('type=animation&loop=false');
+ expect(body.items.length).toBeGreaterThan(0);
+ expect(body.items.every((i) => i.loop === false)).toBe(true);
+ });
+
+ it('filters accessories by kind=hat', async () => {
+ const { body } = await invoke('type=accessory&kind=hat');
+ expect(body.items.length).toBeGreaterThan(0);
+ expect(body.items.every((i) => i.kind === 'hat')).toBe(true);
+ });
+
+ it('respects limit', async () => {
+ const { body } = await invoke('limit=2');
+ expect(body.items.length).toBeLessThanOrEqual(2);
+ expect(body.total).toBeGreaterThan(body.items.length);
+ });
+
+ it('clamps limit to 500 max', async () => {
+ const { body } = await invoke('limit=99999');
+ expect(body.items.length).toBeLessThanOrEqual(500);
+ });
+
+ it('sets a long-lived cache-control header', async () => {
+ const { res } = await invoke();
+ const cc = res.headers['cache-control'];
+ expect(cc).toContain('max-age=');
+ expect(cc).toContain('stale-while-revalidate');
+ });
+
+ it('sets a permissive CORS header so external sites can fetch the catalog', async () => {
+ const { res } = await invoke();
+ expect(res.headers['access-control-allow-origin']).toBe('*');
+ });
+
+ it('environments include the named "Venice Sunset" and "Footprint Court"', () => {
+ const envs = all.items.filter((i) => i.type === 'environment');
+ const names = envs.map((e) => e.name);
+ expect(names).toContain('Venice Sunset');
+ expect(names).toContain('Footprint Court');
+ });
+
+ it('accessories include the seven committed accessory ids', () => {
+ const accs = all.items.filter((i) => i.type === 'accessory');
+ const ids = new Set(accs.map((a) => a.id));
+ for (const id of [
+ 'hat-baseball',
+ 'hat-beanie',
+ 'hat-cowboy',
+ 'glasses-round',
+ 'glasses-shades',
+ 'earrings-hoops',
+ 'earrings-studs',
+ ]) {
+ expect(ids.has(id), `missing accessory id ${id}`).toBe(true);
+ }
+ });
+});
diff --git a/tests/api/persona.test.js b/tests/api/persona.test.js
new file mode 100644
index 000000000..e7fa78986
--- /dev/null
+++ b/tests/api/persona.test.js
@@ -0,0 +1,317 @@
+// Tests for /api/auth/persona/* — token issuance, verification, jwks,
+// tenant-origin allowlist. DB + r2 are mocked.
+
+import { describe, it, expect, beforeEach, vi } from 'vitest';
+import { Readable } from 'node:stream';
+
+// ── Env (must be set before the handler imports `env`) ────────────────────
+process.env.PUBLIC_APP_ORIGIN = 'https://three.ws';
+process.env.JWT_SECRET = 'test-secret-must-be-long-enough-32bytes!!';
+process.env.JWT_KID = 'k-test';
+
+// ── Mocks ─────────────────────────────────────────────────────────────────
+
+const authState = { session: null };
+vi.mock('../../api/_lib/auth.js', () => ({
+ getSessionUser: vi.fn(async () => authState.session),
+}));
+
+const sqlState = { queue: [] };
+vi.mock('../../api/_lib/db.js', () => ({
+ sql: vi.fn(async () => {
+ if (sqlState.queue.length === 0) return [];
+ return sqlState.queue.shift();
+ }),
+}));
+
+vi.mock('../../api/_lib/r2.js', () => ({
+ publicUrl: (key) => `https://cdn.three.ws/${key}`,
+}));
+
+vi.mock('../../api/_lib/crypto.js', () => ({
+ randomToken: (n) => 'r'.repeat(n),
+}));
+
+const { default: handler } = await import('../../api/auth/persona/[action].js');
+
+// ── Helpers ───────────────────────────────────────────────────────────────
+
+function makeReq({ method = 'GET', url = '/', query = {}, body = null } = {}) {
+ const base = body ? Readable.from([Buffer.from(JSON.stringify(body))]) : Readable.from([]);
+ base.method = method;
+ base.url = url;
+ base.query = query;
+ base.headers = {
+ host: 'three.ws',
+ ...(body ? { 'content-type': 'application/json' } : {}),
+ };
+ return base;
+}
+
+function makeRes() {
+ return {
+ statusCode: 200,
+ headers: {},
+ body: '',
+ writableEnded: false,
+ setHeader(k, v) {
+ this.headers[k.toLowerCase()] = v;
+ },
+ end(chunk) {
+ if (chunk !== undefined) this.body += chunk;
+ this.writableEnded = true;
+ },
+ };
+}
+
+async function invoke({ action, ...reqOpts }) {
+ const reqQuery = reqOpts.query || {};
+ // The handler reads `action` from `req.query` (Vercel populates it from
+ // the `[action].js` slug) but reads token/audience via `new URL(req.url)`.
+ // Encode the latter into the URL so both code paths see the values.
+ const qs = new URLSearchParams(reqQuery).toString();
+ const url = qs ? `/?${qs}` : '/';
+ const req = makeReq({ ...reqOpts, url, query: { action, ...reqQuery } });
+ const res = makeRes();
+ await handler(req, res);
+ const payload = res.body ? JSON.parse(res.body) : null;
+ return { res, status: res.statusCode, body: payload };
+}
+
+beforeEach(() => {
+ authState.session = null;
+ sqlState.queue = [];
+});
+
+// ── Tests ─────────────────────────────────────────────────────────────────
+
+describe('POST /api/auth/persona/issue', () => {
+ it('rejects unauthenticated callers with 401', async () => {
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws' },
+ });
+ expect(status).toBe(401);
+ expect(body.error).toBe('unauthorized');
+ });
+
+ it('rejects an arbitrary tenant origin (not on three.ws)', async () => {
+ authState.session = { id: 'user-1' };
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://evil.example' },
+ });
+ expect(status).toBe(400);
+ expect(body.error).toBe('invalid_request');
+ expect(body.error_description).toContain('three.ws');
+ });
+
+ it('rejects a tenant origin with a path / query / hash', async () => {
+ authState.session = { id: 'user-1' };
+ for (const bad of [
+ 'https://demo.three.ws/foo',
+ 'https://demo.three.ws/?x=1',
+ 'https://demo.three.ws/#h',
+ ]) {
+ const { status } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: bad },
+ });
+ expect(status).toBe(400);
+ }
+ });
+
+ it('accepts localhost dev origins on http', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([{ id: 'a-1', name: 'Av', storage_key: 'u/1/a.glb', thumbnail_key: null }]);
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'http://localhost:3000' },
+ });
+ expect(status).toBe(200);
+ expect(body.tenant_origin).toBe('http://localhost:3000');
+ });
+
+ it('returns 404 when the user has no avatar', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([]);
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws' },
+ });
+ expect(status).toBe(404);
+ expect(body.error).toBe('no_avatar');
+ });
+
+ it('issues a 24h HS256 token when no persona keypair is configured', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([
+ { id: 'a-1', name: 'My Avatar', storage_key: 'u/1/a.glb', thumbnail_key: null },
+ ]);
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws' },
+ });
+ expect(status).toBe(200);
+ expect(body.token).toMatch(/^[\w-]+\.[\w-]+\.[\w-]+$/);
+ expect(body.expires_in).toBe(60 * 60 * 24);
+ expect(body.avatar).toEqual({
+ id: 'a-1',
+ name: 'My Avatar',
+ url: 'https://cdn.three.ws/u/1/a.glb',
+ thumbnail_url: null,
+ });
+ expect(body.alg).toBe('HS256');
+ });
+
+ it('issues a token bound to a specific avatar id when provided', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([
+ {
+ id: 'a-2',
+ name: 'Other',
+ storage_key: 'u/1/other.glb',
+ thumbnail_key: 'u/1/other.png',
+ },
+ ]);
+ const { status, body } = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws', avatar_id: 'a-2' },
+ });
+ expect(status).toBe(200);
+ expect(body.avatar.id).toBe('a-2');
+ expect(body.avatar.thumbnail_url).toBe('https://cdn.three.ws/u/1/other.png');
+ });
+});
+
+describe('GET /api/auth/persona/verify', () => {
+ it('rejects a missing token', async () => {
+ const { status, body } = await invoke({
+ action: 'verify',
+ query: { audience: 'https://demo.three.ws' },
+ });
+ expect(status).toBe(400);
+ expect(body.error_description).toContain('token');
+ });
+
+ it('rejects a missing audience', async () => {
+ const { status, body } = await invoke({
+ action: 'verify',
+ query: { token: 'abc' },
+ });
+ expect(status).toBe(400);
+ expect(body.error_description).toContain('audience');
+ });
+
+ it('round-trips an issued token: issue then verify with matching audience', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([
+ { id: 'a-1', name: 'Av', storage_key: 'u/1/a.glb', thumbnail_key: null },
+ ]);
+ const issue = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws' },
+ });
+ expect(issue.status).toBe(200);
+
+ const verify = await invoke({
+ action: 'verify',
+ query: { token: issue.body.token, audience: 'https://demo.three.ws' },
+ });
+ expect(verify.status).toBe(200);
+ expect(verify.body.ok).toBe(true);
+ expect(verify.body.sub).toBe('user-1');
+ expect(verify.body.aud).toBe('https://demo.three.ws');
+ expect(verify.body.avatar.id).toBe('a-1');
+ expect(verify.body.scope).toBe('persona:read avatar:read');
+ });
+
+ it('rejects a token whose audience does not match the requested audience', async () => {
+ authState.session = { id: 'user-1' };
+ sqlState.queue.push([
+ { id: 'a-1', name: 'Av', storage_key: 'u/1/a.glb', thumbnail_key: null },
+ ]);
+ const issue = await invoke({
+ action: 'issue',
+ method: 'POST',
+ body: { tenant_origin: 'https://demo.three.ws' },
+ });
+ const verify = await invoke({
+ action: 'verify',
+ query: { token: issue.body.token, audience: 'https://evil.three.ws' },
+ });
+ expect(verify.status).toBe(401);
+ expect(verify.body.error).toBe('invalid_token');
+ });
+
+ it('rejects garbage tokens', async () => {
+ const { status, body } = await invoke({
+ action: 'verify',
+ query: { token: 'not-a-jwt', audience: 'https://demo.three.ws' },
+ });
+ expect(status).toBe(401);
+ expect(body.error).toBe('invalid_token');
+ });
+});
+
+describe('GET /api/auth/persona/me', () => {
+ it('requires a session', async () => {
+ const { status, body } = await invoke({ action: 'me' });
+ expect(status).toBe(401);
+ expect(body.error).toBe('unauthorized');
+ });
+
+ it('returns the user’s avatars when signed in', async () => {
+ authState.session = { id: 'user-1', email: '[email protected]' };
+ sqlState.queue.push([
+ {
+ id: 'a-1',
+ name: 'A',
+ storage_key: 'u/1/a.glb',
+ thumbnail_key: null,
+ created_at: '2026-05-17',
+ visibility: 'public',
+ },
+ {
+ id: 'a-2',
+ name: 'B',
+ storage_key: 'u/1/b.glb',
+ thumbnail_key: 'u/1/b.png',
+ created_at: '2026-05-16',
+ visibility: 'private',
+ },
+ ]);
+ const { status, body } = await invoke({ action: 'me' });
+ expect(status).toBe(200);
+ expect(body.user.email).toBe('[email protected]');
+ expect(body.avatars).toHaveLength(2);
+ expect(body.avatars[1].thumbnail_url).toBe('https://cdn.three.ws/u/1/b.png');
+ });
+});
+
+describe('GET /.well-known/jwks.json (action=jwks)', () => {
+ it('returns an empty key set when no persona keypair is configured', async () => {
+ // Make sure no env key is set.
+ delete process.env.PERSONA_JWKS_PRIVATE_KEY_PEM;
+ const { status, body, res } = await invoke({ action: 'jwks' });
+ expect(status).toBe(200);
+ expect(body.keys).toEqual([]);
+ expect(res.headers['x-three-ws-status']).toContain('HS256');
+ });
+});
+
+describe('dispatcher', () => {
+ it('returns 404 for unknown actions', async () => {
+ const { status, body } = await invoke({ action: 'who' });
+ expect(status).toBe(404);
+ expect(body.error).toBe('not_found');
+ });
+});
diff --git a/tests/arkit52.test.js b/tests/arkit52.test.js
new file mode 100644
index 000000000..d8f482135
--- /dev/null
+++ b/tests/arkit52.test.js
@@ -0,0 +1,206 @@
+import { describe, it, expect } from 'vitest';
+import {
+ ARKIT_52,
+ ARKIT_VISEMES,
+ MORPH_ALIASES,
+ resolveMorphTargets,
+ setCanonicalMorph,
+ conformanceReport,
+} from '../src/runtime/arkit52.js';
+
+// Stand-in for a Three.js mesh: the resolver only walks `.traverse()` and
+// reads `morphTargetDictionary` + `morphTargetInfluences`, so a plain object
+// with those fields is enough for unit tests.
+function fakeMesh(targetNames) {
+ const dict = {};
+ targetNames.forEach((n, i) => (dict[n] = i));
+ return {
+ isMesh: true,
+ morphTargetDictionary: dict,
+ morphTargetInfluences: new Array(targetNames.length).fill(0),
+ };
+}
+
+function fakeScene(meshes) {
+ return {
+ traverse(fn) {
+ for (const m of meshes) fn(m);
+ },
+ };
+}
+
+describe('ARKIT_52 spec', () => {
+ it('lists exactly 52 canonical names', () => {
+ expect(ARKIT_52).toHaveLength(52);
+ });
+
+ it('includes the named regions covering eyes, jaw, mouth, brows, cheeks, nose, tongue', () => {
+ expect(ARKIT_52).toContain('eyeBlinkLeft');
+ expect(ARKIT_52).toContain('eyeLookUpRight');
+ expect(ARKIT_52).toContain('jawOpen');
+ expect(ARKIT_52).toContain('mouthSmileLeft');
+ expect(ARKIT_52).toContain('mouthSmileRight');
+ expect(ARKIT_52).toContain('mouthFunnel');
+ expect(ARKIT_52).toContain('browInnerUp');
+ expect(ARKIT_52).toContain('cheekPuff');
+ expect(ARKIT_52).toContain('noseSneerLeft');
+ expect(ARKIT_52).toContain('tongueOut');
+ });
+
+ it('does not duplicate any name', () => {
+ const set = new Set(ARKIT_52);
+ expect(set.size).toBe(ARKIT_52.length);
+ });
+});
+
+describe('ARKIT_VISEMES', () => {
+ it('contains the 15 standard viseme_ shapes', () => {
+ expect(ARKIT_VISEMES).toHaveLength(15);
+ expect(ARKIT_VISEMES).toContain('viseme_aa');
+ expect(ARKIT_VISEMES).toContain('viseme_sil');
+ });
+});
+
+describe('MORPH_ALIASES', () => {
+ it('maps every alias to a canonical ARKit-52 name', () => {
+ for (const [alias, canonical] of Object.entries(MORPH_ALIASES)) {
+ expect(
+ ARKIT_52.includes(canonical),
+ `alias ${alias} → ${canonical} is not in ARKIT_52`,
+ ).toBe(true);
+ }
+ });
+
+ it('routes snake_case to camelCase', () => {
+ expect(MORPH_ALIASES.mouth_smile_left).toBe('mouthSmileLeft');
+ expect(MORPH_ALIASES.brow_inner_up).toBe('browInnerUp');
+ expect(MORPH_ALIASES.jaw_open).toBe('jawOpen');
+ });
+
+ it('routes _L / _R suffix variants', () => {
+ expect(MORPH_ALIASES.eyeBlink_L).toBe('eyeBlinkLeft');
+ expect(MORPH_ALIASES.mouthSmile_R).toBe('mouthSmileRight');
+ });
+
+ it('routes combined shapes to a Left side so the auto-mirror handles the pair', () => {
+ expect(MORPH_ALIASES.mouthSmile).toBe('mouthSmileLeft');
+ expect(MORPH_ALIASES.mouthFrown).toBe('mouthFrownLeft');
+ expect(MORPH_ALIASES.eyesClosed).toBe('eyeBlinkLeft');
+ });
+
+ it('routes mouthOpen to jawOpen for backwards-compat', () => {
+ expect(MORPH_ALIASES.mouthOpen).toBe('jawOpen');
+ });
+});
+
+describe('resolveMorphTargets', () => {
+ it('builds a canonical → [{mesh, index}] map for an ARKit-named rig', () => {
+ const mesh = fakeMesh(['mouthSmileLeft', 'mouthSmileRight', 'jawOpen']);
+ const resolved = resolveMorphTargets(fakeScene([mesh]));
+
+ expect(resolved.get('mouthSmileLeft')).toHaveLength(1);
+ expect(resolved.get('mouthSmileLeft')[0].mesh).toBe(mesh);
+ expect(resolved.get('mouthSmileLeft')[0].index).toBe(0);
+ expect(resolved.get('jawOpen')[0].index).toBe(2);
+ });
+
+ it('normalizes snake_case morph names to canonical entries', () => {
+ const mesh = fakeMesh(['mouth_smile_left', 'jaw_open']);
+ const resolved = resolveMorphTargets(fakeScene([mesh]));
+ expect(resolved.has('mouthSmileLeft')).toBe(true);
+ expect(resolved.has('jawOpen')).toBe(true);
+ });
+
+ it('handles a combined mouthSmile by registering it as mouthSmileLeft', () => {
+ const mesh = fakeMesh(['mouthSmile', 'jawOpen']);
+ const resolved = resolveMorphTargets(fakeScene([mesh]));
+ expect(resolved.has('mouthSmileLeft')).toBe(true);
+ expect(resolved.has('mouthSmileRight')).toBe(false);
+ });
+
+ it('ignores morphs that are neither canonical nor aliased', () => {
+ const mesh = fakeMesh(['custom_lipPucker', 'brand_X']);
+ const resolved = resolveMorphTargets(fakeScene([mesh]));
+ expect(resolved.size).toBe(0);
+ });
+
+ it('aggregates slots across multiple meshes', () => {
+ const a = fakeMesh(['jawOpen']);
+ const b = fakeMesh(['jawOpen', 'browInnerUp']);
+ const resolved = resolveMorphTargets(fakeScene([a, b]));
+ expect(resolved.get('jawOpen')).toHaveLength(2);
+ expect(resolved.get('browInnerUp')).toHaveLength(1);
+ });
+
+ it('returns an empty map for a null root', () => {
+ expect(resolveMorphTargets(null).size).toBe(0);
+ });
+});
+
+describe('setCanonicalMorph', () => {
+ it('applies a weight to all mesh slots bound to that canonical name', () => {
+ const a = fakeMesh(['jawOpen']);
+ const b = fakeMesh(['jawOpen']);
+ const resolved = resolveMorphTargets(fakeScene([a, b]));
+ setCanonicalMorph(resolved, 'jawOpen', 0.7);
+ expect(a.morphTargetInfluences[0]).toBeCloseTo(0.7);
+ expect(b.morphTargetInfluences[0]).toBeCloseTo(0.7);
+ });
+
+ it('clamps weight to [0, 1]', () => {
+ const m = fakeMesh(['jawOpen']);
+ const resolved = resolveMorphTargets(fakeScene([m]));
+ setCanonicalMorph(resolved, 'jawOpen', 2.5);
+ expect(m.morphTargetInfluences[0]).toBe(1);
+ setCanonicalMorph(resolved, 'jawOpen', -1);
+ expect(m.morphTargetInfluences[0]).toBe(0);
+ });
+
+ it('mirrors a Left set to the matching Right side', () => {
+ const m = fakeMesh(['mouthSmileLeft', 'mouthSmileRight']);
+ const resolved = resolveMorphTargets(fakeScene([m]));
+ setCanonicalMorph(resolved, 'mouthSmileLeft', 0.8);
+ expect(m.morphTargetInfluences[0]).toBeCloseTo(0.8);
+ expect(m.morphTargetInfluences[1]).toBeCloseTo(0.8);
+ });
+
+ it('does not mirror when opts.mirror is false', () => {
+ const m = fakeMesh(['mouthSmileLeft', 'mouthSmileRight']);
+ const resolved = resolveMorphTargets(fakeScene([m]));
+ setCanonicalMorph(resolved, 'mouthSmileLeft', 0.6, { mirror: false });
+ expect(m.morphTargetInfluences[0]).toBeCloseTo(0.6);
+ expect(m.morphTargetInfluences[1]).toBe(0);
+ });
+
+ it('no-ops for unknown canonical names', () => {
+ const m = fakeMesh(['jawOpen']);
+ const resolved = resolveMorphTargets(fakeScene([m]));
+ expect(() => setCanonicalMorph(resolved, 'doesNotExist', 1)).not.toThrow();
+ });
+});
+
+describe('conformanceReport', () => {
+ it('reports 100% coverage for a rig that ships every ARKit-52 morph', () => {
+ const mesh = fakeMesh([...ARKIT_52]);
+ const r = conformanceReport(fakeScene([mesh]));
+ expect(r.coverage).toBe(1);
+ expect(r.implemented).toHaveLength(52);
+ expect(r.missing).toHaveLength(0);
+ });
+
+ it('reports 0% coverage for a rig with no recognized morphs', () => {
+ const mesh = fakeMesh(['unrelatedMorph']);
+ const r = conformanceReport(fakeScene([mesh]));
+ expect(r.coverage).toBe(0);
+ expect(r.missing).toHaveLength(52);
+ });
+
+ it('counts aliased shapes toward coverage', () => {
+ const mesh = fakeMesh(['mouth_smile_left', 'mouth_smile_right', 'jaw_open']);
+ const r = conformanceReport(fakeScene([mesh]));
+ expect(r.implemented).toContain('mouthSmileLeft');
+ expect(r.implemented).toContain('mouthSmileRight');
+ expect(r.implemented).toContain('jawOpen');
+ expect(r.coverage).toBeCloseTo(3 / 52);
+ });
+});