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
import { describe, it, expect } from 'vitest';
import { existsSync, readFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import {
validateEventConfig, isNoEventSentinel, NO_EVENT_DOC, CONFIG_PATH, isoOf, zoneLines,
} from '../scripts/check-event-window.mjs';
// The shape of public/event.json, minus the fields the validator ignores. Kept
// close to the real file so a rule that only passes on a toy config fails here.
const BASE = {
id: 'three-first-meetup',
name: '$THREE First Holders Meetup',
startsAt: '2026-08-09T17:00:00Z',
endsAt: '2026-08-09T19:30:00Z',
link: '/play?coin=FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump&name=three.ws&symbol=three',
souvenir: { cosmeticId: 'laurel-meetup' },
agenda: [
{ atMin: 0, title: 'Doors open in the plaza', icon: '👋' },
{ atMin: 105, title: 'Fireworks finale', icon: '🎆' },
],
};
const CHECK_SCRIPT = fileURLToPath(new URL('../scripts/check-event-window.mjs', import.meta.url));
const BEFORE = Date.parse('2026-08-09T12:00:00Z');
const DURING = Date.parse('2026-08-09T18:00:00Z');
const AFTER = Date.parse('2026-08-10T00:00:00Z');
const cfg = (over = {}) => ({ ...BASE, ...over });
const reasons = (doc, now) => validateEventConfig(doc, now).failures.join(' | ');
describe('validateEventConfig', () => {
it('accepts a coherent upcoming event', () => {
const { failures, state } = validateEventConfig(cfg(), BEFORE);
expect(failures).toEqual([]);
expect(state).toBe('upcoming');
});
it('accepts the event while it is running', () => {
const { failures, state } = validateEventConfig(cfg(), DURING);
expect(failures).toEqual([]);
expect(state).toBe('live');
});
// The bug this check exists for: a rehearsal window left in the file. Every
// surface reads it as "no event" and mounts nothing, silently.
it('rejects a window that has already ended', () => {
const { failures, state } = validateEventConfig(cfg(), AFTER);
expect(state).toBe('over');
expect(failures).toHaveLength(1);
expect(failures[0]).toMatch(/ENDED/);
});
it('rejects a config with no usable start time', () => {
expect(reasons(cfg({ startsAt: 'tomorrow-ish' }), BEFORE)).toMatch(/startsAt/);
expect(reasons(cfg({ startsAt: undefined }), BEFORE)).toMatch(/startsAt/);
});
// An end that loses to the start is dropped by the parser for a silent
// six-hour default, which is never what whoever typed it meant.
it('rejects an end that does not beat the start', () => {
expect(reasons(cfg({ endsAt: '2026-08-09T16:00:00Z' }), BEFORE)).toMatch(/not after startsAt/);
expect(reasons(cfg({ endsAt: 'never' }), BEFORE)).toMatch(/unparseable/);
});
it('rejects a window long enough to be a typo', () => {
expect(reasons(cfg({ endsAt: '2026-08-19T17:00:00Z' }), BEFORE)).toMatch(/reads like a typo/);
});
describe('souvenir', () => {
it('rejects a cosmetic that is not in the catalog', () => {
expect(reasons(cfg({ souvenir: { cosmeticId: 'laurel-imaginary' } }), BEFORE)).toMatch(/not in multiplayer/);
});
// The server only grants tier 'event', so any other tier grants nothing.
it('rejects a cosmetic the server would refuse to grant', () => {
expect(reasons(cfg({ souvenir: { cosmeticId: 'hat-cowboy' } }), BEFORE)).toMatch(/only grants tier 'event'/);
});
it('rejects a souvenir with no cosmeticId', () => {
expect(reasons(cfg({ souvenir: {} }), BEFORE)).toMatch(/names no cosmeticId/);
});
// The grant is scoped to the coin world the CTA points at.
it('rejects a souvenir whose link names no world', () => {
expect(reasons(cfg({ link: '/play' }), BEFORE)).toMatch(/no \?coin=/);
expect(reasons(cfg({ link: '' }), BEFORE)).toMatch(/no \?coin=/);
});
it('allows an event that grants nothing', () => {
expect(validateEventConfig(cfg({ souvenir: undefined, link: '/play' }), BEFORE).failures).toEqual([]);
});
});
describe('agenda', () => {
it('rejects a beat scheduled past the end of the window', () => {
const late = cfg({ agenda: [{ atMin: 0, title: 'Doors' }, { atMin: 999, title: 'Fireworks finale' }] });
expect(reasons(late, BEFORE)).toMatch(/never fires/);
});
it('rejects beats that run backwards', () => {
const jumbled = cfg({ agenda: [{ atMin: 45, title: 'Wheel' }, { atMin: 20, title: 'Totem' }] });
expect(reasons(jumbled, BEFORE)).toMatch(/must be in order/);
});
it('rejects a beat with no usable minute offset', () => {
expect(reasons(cfg({ agenda: [{ atMin: -5, title: 'Doors' }] }), BEFORE)).toMatch(/non-negative/);
expect(reasons(cfg({ agenda: [{ atMin: 'soon', title: 'Doors' }] }), BEFORE)).toMatch(/non-negative/);
});
});
// The formatters feed the announcement copy, and copy that disagrees with the
// config is the other way this event has gone wrong.
describe('clock rendering', () => {
it('renders the window in the zones the announcements quote', () => {
const lines = zoneLines(Date.parse('2026-08-09T17:00:00Z'));
expect(lines).toHaveLength(4);
expect(lines[0]).toBe('Aug 9, 2026, 10:00 AM Pacific');
expect(lines[1]).toBe('Aug 9, 2026, 1:00 PM Eastern');
expect(lines[2]).toBe('Aug 9, 2026, 6:00 PM London');
expect(lines[3]).toBe('Aug 9, 2026, 7:00 PM Berlin');
});
it('writes instants back in the config\'s own format', () => {
expect(isoOf(Date.parse('2026-08-09T17:00:00Z'))).toBe('2026-08-09T17:00:00Z');
});
});
});
// The between-events resting state: the file exists (so /event.json answers
// 200 in every visitor console instead of 404ing four times per /play load)
// and carries an explicitly null window every reader parses as "no event".
describe('the no-event resting state', () => {
it('recognises the canonical resting document', () => {
expect(isNoEventSentinel(NO_EVENT_DOC)).toBe(true);
});
it('is what every reader parses as "no event"', () => {
expect(validateEventConfig(NO_EVENT_DOC, BEFORE).window).toBeNull();
});
// A config that nulls the window but keeps event-bearing fields is a broken
// event, not a resting state, and must keep failing validation loudly.
it('refuses a null window that still carries event fields', () => {
expect(isNoEventSentinel({ ...NO_EVENT_DOC, name: '$THREE meetup' })).toBe(false);
expect(isNoEventSentinel({ ...NO_EVENT_DOC, link: '/play?coin=x' })).toBe(false);
expect(isNoEventSentinel({ ...NO_EVENT_DOC, souvenir: { cosmeticId: 'laurel-meetup' } })).toBe(false);
expect(isNoEventSentinel(null)).toBe(false);
expect(isNoEventSentinel({})).toBe(false);
});
});
// The config that ships is the one that matters; a green suite over fixtures
// while the real file is broken would be the same silent failure in a new place.
// Between events the file carries the no-event resting document (see above), so
// these run only when an event is actually shipping.
// Read inside the tests rather than in the suite body: vitest still collects a
// skipped suite's body, so an eager read would throw on an unreadable file.
const shippedEvent = () => JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
const shippedIsResting = () => {
try { return isNoEventSentinel(shippedEvent()); } catch { return false; }
};
describe.skipIf(!existsSync(CONFIG_PATH) || shippedIsResting())('the configured event that ships', () => {
it('is coherent when judged at its own start', () => {
const doc = shippedEvent();
const { failures } = validateEventConfig(doc, Date.parse(doc.startsAt));
expect(failures).toEqual([]);
});
// Judged on an injected clock, never today's: whether the shipped event is
// still ahead is a fact about the calendar, which `npm run check:event` (in
// gate) reports at run time. What this suite pins is that the guard reads
// the shipped window the way every surface does: live for its whole span,
// and flagged ENDED from the instant it closes, so a finished event left in
// the file fails the gate until it is rescheduled or cleared.
it('reads as live for its whole window and as ENDED from the instant it closes', () => {
const doc = shippedEvent();
const { window: win } = validateEventConfig(doc, Date.parse(doc.startsAt));
expect(win).not.toBeNull();
for (const at of [win.startsAt, win.endsAt - 1]) {
const judged = validateEventConfig(doc, at);
expect(judged.state).toBe('live');
expect(judged.failures).toEqual([]);
}
const closed = validateEventConfig(doc, win.endsAt);
expect(closed.state).toBe('over');
expect(closed.failures.join(' | ')).toMatch(/ENDED/);
});
it('passes the gate CLI at the event\'s start and fails it once the event is over', () => {
const doc = shippedEvent();
const run = (at) => spawnSync(process.execPath, [CHECK_SCRIPT, '--at', at], { encoding: 'utf8' });
const atStart = run(doc.startsAt);
expect(atStart.status, atStart.stderr).toBe(0);
expect(atStart.stdout).toMatch(/OK: the configured event is coherent/);
const dayAfter = run(isoOf(validateEventConfig(doc, Date.parse(doc.startsAt)).window.endsAt + 24 * 3600 * 1000));
expect(dayAfter.status).toBe(1);
expect(dayAfter.stderr).toMatch(/the event window ENDED 24h ago/);
});
});
describe.skipIf(!existsSync(CONFIG_PATH) || !shippedIsResting())('the resting config that ships', () => {
it('passes the gate CLI at any instant, since there is no window to expire', () => {
for (const at of ['2020-01-01T00:00:00Z', '2099-01-01T00:00:00Z']) {
const r = spawnSync(process.execPath, [CHECK_SCRIPT, '--at', at], { encoding: 'utf8' });
expect(r.status, r.stderr).toBe(0);
expect(r.stdout).toMatch(/explicit no-event state/);
}
});
});