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.

3.7 KB
Raw Blame
// No source file may point at an asset host that does not exist.
//
// `cdn.three.ws` has no DNS record and never has. It appeared in 181 places
// across 55 files: API output examples served live through the service catalog
// and discovery endpoints, every code sample in docs/3d-api.md, docs/mcp.md and
// docs/api-reference.md, the embed skill agents read to build <agent-3d> tags,
// package READMEs, and test fixtures. Anyone who copy-pasted one of those got a
// DNS failure, and an agent following the skill emitted a dead body URL.
//
// The real first-party CDN is the `/cdn/<r2-key>` route (api/cdn-object.js),
// which streams the same R2 namespace through three.ws with
// `access-control-allow-origin: *` and a 30-day edge cache. It exists precisely
// because the bucket's public `*.r2.dev` origin is Cloudflare rate-limited and
// "not meant for production traffic" — so that origin is also not a valid
// substitute in anything user- or developer-facing.
//
// Scope note, so nobody widens this into a sweep it should not be: `*.r2.dev` is
// deliberately NOT policed here. Every occurrence in the repo is legitimate —
// generic placeholders that document the bucket-origin shape (`pub-<hash>.r2.dev`),
// `.r2.dev` as a suffix in api/ibm/vision.js's host allowlist, presigned-download
// examples whose signatures are elided so they cannot be pasted anyway, and
// api/_lib/r2.js computing real URLs from S3_PUBLIC_DOMAIN. Those hosts resolve
// and those uses are honest. Only the host that does not exist is a defect.

import { describe, it, expect } from 'vitest';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');

/**
 * Every tracked file containing `pattern`, via git grep so the search honours
 * .gitignore and never walks node_modules or dist.
 * @param {string} pattern a fixed string
 * @returns {string[]} repo-relative paths
 */
function filesContaining(pattern) {
	try {
		const out = execFileSync('git', ['grep', '-l', '--fixed-strings', pattern], {
			cwd: ROOT,
			encoding: 'utf8',
			maxBuffer: 32 * 1024 * 1024,
		});
		return out.split('\n').filter(Boolean);
	} catch (err) {
		// git grep exits 1 with no output when there are no matches.
		if (err.status === 1 && !err.stdout?.trim()) return [];
		throw err;
	}
}

// Generated aggregates and build artifacts mirror their sources; fixing the
// source is the fix. docs/ALL.md is regenerated by scripts/combine-docs.mjs and
// public/chat/assets/* is compiled output.
const DERIVED = [/^docs\/ALL\.md$/, /^public\/chat\/assets\//, /\.min\.js$/, /^package-lock\.json$/];
const isDerived = (file) => DERIVED.some((re) => re.test(file));

describe('asset hosts that actually resolve', () => {
	it('no source file references the dead cdn.three.ws host', () => {
		const offenders = filesContaining('cdn.three.ws')
			.filter((file) => !isDerived(file))
			// This test names the host to forbid it, so it matches itself.
			.filter((file) => file !== 'tests/asset-host-liveness.test.js')
			// One historical note is allowed to name it: the generator comment that
			// explains why the sample manifest points elsewhere.
			.filter((file) => file !== 'scripts/build-discovery-cards.mjs');
		expect(offenders, 'use https://three.ws/cdn/<r2-key> (api/cdn-object.js)').toEqual([]);
	});

	it('the first-party CDN route that replaced it still exists', () => {
		// If this route is ever removed or renamed, every URL the sweep above
		// rewrote breaks at once, so the guard and the route are one unit.
		const routed = filesContaining('/api/cdn-object?key=$1');
		expect(routed).toContain('vercel.json');
	});
});