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(forge): cover PartCrafter registration and the forge-holopart endpoint

nirholasa287682e159b
diff --git a/tests/api/forge-holopart.test.js b/tests/api/forge-holopart.test.js
new file mode 100644
index 000000000..e82f341f7
--- /dev/null
+++ b/tests/api/forge-holopart.test.js
@@ -0,0 +1,178 @@
+/**
+ * Tests for the hidden-part completion endpoint (api/forge-holopart.js).
+ *
+ * The HoloPart worker is stubbed at the provider boundary (createRegenProvider
+ * from api/_providers/gcp.js), so this exercises the endpoint's own logic:
+ * mesh_url validation (SSRF, FBX rejection), the async submit/poll job shape,
+ * and the parts/part_count/manifest_url passthrough Restyle Studio's
+ * "Regenerate part" flow reads. HoloPart's own mesh completion is covered by
+ * the worker's own Python tests.
+ */
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { Readable } from 'node:stream';
+
+const submit = vi.fn(async () => ({ extJobId: `task-holopart-${'x'.repeat(20)}`, eta: 60 }));
+const status = vi.fn(async () => ({
+ status: 'done',
+ resultGlbUrl: 'https://storage.googleapis.com/bucket/holopart/task.glb',
+ manifestUrl: 'https://storage.googleapis.com/bucket/holopart/task.manifest.json',
+ parts: [{ id: 'part_01', name: 'part_01' }, { id: 'part_02', name: 'part_02' }],
+ partCount: 2,
+}));
+let supportsHolopart = true;
+
+vi.mock('../../api/_providers/gcp.js', () => ({
+ createRegenProvider: () => ({
+ supportsMode: (m) => m === 'holopart' && supportsHolopart,
+ submit,
+ status,
+ }),
+}));
+
+// Stub SSRF so no DNS resolution happens in tests; passthrough public https URLs.
+vi.mock('../../api/_lib/ssrf.js', async (importOriginal) => {
+ const mod = await importOriginal();
+ return {
+ ...mod,
+ assertPublicHttpsUrl: vi.fn(async (url) => {
+ const parsed = new URL(url);
+ if (parsed.protocol !== 'https:') throw new mod.SsrfError('https required');
+ return url;
+ }),
+ };
+});
+
+vi.mock('../../api/_lib/rate-limit.js', async (importActual) => {
+ const actual = await importActual();
+ return {
+ ...actual,
+ clientIp: () => '203.0.113.9',
+ limits: {
+ ...actual.limits,
+ mcp3dGenerate: vi.fn(async () => ({ success: true, reset: Date.now() + 1000 })),
+ mcp3dStatus: vi.fn(async () => ({ success: true, reset: Date.now() + 1000 })),
+ },
+ };
+});
+
+const { default: handler } = await import('../../api/forge-holopart.js');
+
+function makeRes() {
+ return {
+ statusCode: 200,
+ headers: {},
+ body: null,
+ setHeader(n, v) {
+ this.headers[String(n).toLowerCase()] = v;
+ },
+ end(b) {
+ this.body = b ?? null;
+ },
+ };
+}
+
+function makeReq({ method = 'POST', url = '/api/forge-holopart', headers = {}, body = null } = {}) {
+ const payload = body == null ? '' : typeof body === 'string' ? body : JSON.stringify(body);
+ const stream = Readable.from(payload ? [Buffer.from(payload, 'utf8')] : []);
+ stream.method = method;
+ stream.url = url;
+ stream.headers = {
+ 'content-type': 'application/json',
+ 'x-forwarded-for': '203.0.113.9',
+ ...headers,
+ };
+ return stream;
+}
+
+const MESH = 'https://storage.googleapis.com/bucket/segment/part_02.glb';
+
+beforeEach(() => {
+ submit.mockClear();
+ status.mockClear();
+ supportsHolopart = true;
+});
+
+describe('POST /api/forge-holopart', () => {
+ it('queues a holopart job against the already part-segmented mesh', async () => {
+ const res = makeRes();
+ await handler(makeReq({ body: { mesh_url: MESH, seed: 7 } }), res);
+ expect(res.statusCode).toBe(202);
+ const body = JSON.parse(res.body);
+ expect(body.status).toBe('queued');
+ expect(typeof body.job_id).toBe('string');
+ expect(body.eta_seconds).toBe(60);
+
+ expect(submit).toHaveBeenCalledTimes(1);
+ const call = submit.mock.calls[0][0];
+ expect(call.mode).toBe('holopart');
+ expect(call.sourceUrl).toBe(MESH);
+ expect(call.params.seed).toBe(7);
+ });
+
+ it('rejects a non-public mesh_url before calling the worker', async () => {
+ const res = makeRes();
+ await handler(makeReq({ body: { mesh_url: 'http://169.254.169.254/latest/meta-data/' } }), res);
+ expect(res.statusCode).toBe(400);
+ expect(JSON.parse(res.body).error).toBe('invalid_mesh_url');
+ expect(submit).not.toHaveBeenCalled();
+ });
+
+ it('rejects an FBX mesh_url with the same unsupported-format message as segment', async () => {
+ const res = makeRes();
+ await handler(makeReq({ body: { mesh_url: 'https://storage.googleapis.com/bucket/character.fbx' } }), res);
+ expect(res.statusCode).toBe(400);
+ const body = JSON.parse(res.body);
+ expect(body.error).toBe('unsupported_mesh_format');
+ expect(body.message).toMatch(/holopart/);
+ expect(submit).not.toHaveBeenCalled();
+ });
+
+ it('rejects a negative or non-integer seed', async () => {
+ const res = makeRes();
+ await handler(makeReq({ body: { mesh_url: MESH, seed: -1 } }), res);
+ expect(res.statusCode).toBe(400);
+ expect(JSON.parse(res.body).error).toBe('invalid_seed');
+ expect(submit).not.toHaveBeenCalled();
+ });
+
+ it('answers 503 worker_unconfigured when MODEL_HOLOPART_URL is not set, not a generic failure', async () => {
+ supportsHolopart = false;
+ const res = makeRes();
+ await handler(makeReq({ body: { mesh_url: MESH } }), res);
+ expect(res.statusCode).toBe(503);
+ expect(JSON.parse(res.body).error).toBe('unconfigured');
+ expect(submit).not.toHaveBeenCalled();
+ });
+});
+
+describe('GET /api/forge-holopart?job=<id>', () => {
+ it('polls the job and surfaces the parts manifest fields for Restyle Studio', async () => {
+ const jobId = `task-holopart-${'x'.repeat(20)}`;
+ const res = makeRes();
+ await handler(makeReq({ method: 'GET', url: `/api/forge-holopart?job=${jobId}` }), res);
+ expect(res.statusCode).toBe(200);
+ const body = JSON.parse(res.body);
+ expect(body.job_id).toBe(jobId);
+ expect(body.status).toBe('done');
+ expect(body.result_url).toBe('https://storage.googleapis.com/bucket/holopart/task.glb');
+ expect(body.manifest_url).toBe('https://storage.googleapis.com/bucket/holopart/task.manifest.json');
+ expect(body.parts).toEqual([{ id: 'part_01', name: 'part_01' }, { id: 'part_02', name: 'part_02' }]);
+ expect(body.part_count).toBe(2);
+ });
+
+ it('rejects a malformed job id before calling the provider', async () => {
+ const res = makeRes();
+ await handler(makeReq({ method: 'GET', url: '/api/forge-holopart?job=short' }), res);
+ expect(res.statusCode).toBe(400);
+ expect(JSON.parse(res.body).error).toBe('invalid_job');
+ expect(status).not.toHaveBeenCalled();
+ });
+
+ it('requires a job id', async () => {
+ const res = makeRes();
+ await handler(makeReq({ method: 'GET', url: '/api/forge-holopart' }), res);
+ expect(res.statusCode).toBe(400);
+ expect(JSON.parse(res.body).error).toBe('missing_job');
+ });
+});
diff --git a/tests/api/forge-partcrafter.test.js b/tests/api/forge-partcrafter.test.js
new file mode 100644
index 000000000..213c97f66
--- /dev/null
+++ b/tests/api/forge-partcrafter.test.js
@@ -0,0 +1,222 @@
+// PartCrafter "editable parts" lane: registration, env-gated config, opt-in
+// routing (never a default or a failover target, same posture as AniGen and
+// Pixal3D), the catalog's `editableParts` discoverability flag, and the gcp
+// provider's `partcrafter` mode wire contract (images + num_parts in,
+// parts/part_count/manifest_url surfaced out so Restyle Studio's part picker
+// reads the result without a second fetch).
+
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import {
+ BACKENDS,
+ resolveBackendId,
+ backendIsConfigured,
+ buildCatalog,
+ isSelfHostImageLane,
+ nextSelfHostImageLane,
+ selfHostLaneName,
+ FREE_DEFAULT_FOR_TIERS,
+ FREE_FALLBACK_FOR_PATH,
+} from '../../api/_lib/forge-tiers.js';
+import { createRegenProvider } from '../../api/_providers/gcp.js';
+
+const VARS = ['MODEL_PARTCRAFTER_URL', 'MODEL_TRELLIS2_URL', 'MODEL_TRELLIS_URL', 'GCP_RECONSTRUCTION_KEY'];
+const saved = {};
+const ORIGINAL_FETCH = globalThis.fetch;
+
+beforeEach(() => {
+ for (const v of VARS) {
+ saved[v] = process.env[v];
+ delete process.env[v];
+ }
+});
+afterEach(() => {
+ for (const v of VARS) {
+ if (saved[v] === undefined) delete process.env[v];
+ else process.env[v] = saved[v];
+ }
+ globalThis.fetch = ORIGINAL_FETCH;
+ vi.restoreAllMocks();
+});
+
+describe('forge-tiers: PartCrafter backend registration', () => {
+ it('registers a free, platform-keyed, single-image backend that accepts user photos and reports editableParts:true', () => {
+ const b = BACKENDS.partcrafter;
+ expect(b).toBeTruthy();
+ expect(b.provider).toBe('gcp');
+ expect(b.byok).toBe(false);
+ expect(b.paths).toEqual(['image']);
+ expect(b.requiresEnv).toEqual(['MODEL_PARTCRAFTER_URL', 'GCP_RECONSTRUCTION_KEY']);
+ expect(b.free).toBe(true);
+ expect(b.userImages).toBe(true);
+ expect(b.editableParts).toBe(true);
+ expect(b.minParts).toBe(2);
+ expect(b.credits).toBeNull();
+ });
+
+ it('is configured only when BOTH the worker URL and the shared key are present', () => {
+ expect(backendIsConfigured('partcrafter')).toBe(false);
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ expect(backendIsConfigured('partcrafter')).toBe(false); // key still missing
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ expect(backendIsConfigured('partcrafter')).toBe(true);
+ });
+
+ it('surfaces in the catalog with the editable-parts discoverability flag set', () => {
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ const b = buildCatalog().backends.find((x) => x.id === 'partcrafter');
+ expect(b).toBeTruthy();
+ expect(b.free).toBe(true);
+ expect(b.user_images).toBe(true);
+ expect(b.configured).toBe(true);
+ expect(b.editable_parts).toBe(true);
+ });
+
+ it('every OTHER backend reports editable_parts:false in the catalog', () => {
+ const backends = buildCatalog().backends.filter((x) => x.id !== 'partcrafter');
+ expect(backends.length).toBeGreaterThan(0);
+ for (const b of backends) expect(b.editable_parts).toBe(false);
+ });
+
+ it('is a self-host image lane, but never a named default or a failover target', () => {
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ process.env.MODEL_TRELLIS2_URL = 'https://trellis2.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ expect(isSelfHostImageLane('partcrafter')).toBe(true);
+ expect(Object.values(FREE_DEFAULT_FOR_TIERS).some((v) => v.image === 'partcrafter')).toBe(false);
+ expect(FREE_FALLBACK_FOR_PATH.image).not.toContain('partcrafter');
+ expect(resolveBackendId({ path: 'image', tier: 'standard', userImages: true, country: 'US' })).not.toBe(
+ 'partcrafter',
+ );
+ // A down PartCrafter worker must never silently deliver an undivided
+ // mesh from another lane under the "editable parts" label.
+ expect(nextSelfHostImageLane('trellis2')).not.toBe('partcrafter');
+ expect(nextSelfHostImageLane('partcrafter')).toBeNull();
+ expect(selfHostLaneName('partcrafter')).toBe('PartCrafter');
+ });
+
+ it('stays explicitly selectable even when unconfigured (the handler owns rejection)', () => {
+ expect(
+ resolveBackendId({ path: 'image', tier: 'standard', backend: 'partcrafter', userImages: true, country: 'US' }),
+ ).toBe('partcrafter');
+ });
+});
+
+describe('gcp provider: partcrafter mode wire contract', () => {
+ it('submits the first reference image plus num_parts and seed', async () => {
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ let sent = null;
+ globalThis.fetch = vi.fn(async (url, opts) => {
+ expect(url).toBe('https://partcrafter.example.run.app/infer');
+ sent = JSON.parse(opts.body);
+ expect(opts.headers.authorization).toBe('Bearer secret');
+ return new Response(JSON.stringify({ task_id: 'task-partcrafter', status: 'queued' }), {
+ status: 202,
+ headers: { 'content-type': 'application/json' },
+ });
+ });
+
+ const provider = createRegenProvider();
+ const images = ['https://three.ws/cdn/front.png'];
+ const submitted = await provider.submit({
+ mode: 'partcrafter',
+ sourceUrl: images[0],
+ params: { images, num_parts: 6, seed: 3 },
+ });
+
+ expect(sent).toEqual({ images, num_parts: 6, seed: 3 });
+ expect(submitted.extJobId).toBeTruthy();
+ });
+
+ it('defaults num_parts to 4 when the caller omits it', async () => {
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ let sent = null;
+ globalThis.fetch = vi.fn(async (url, opts) => {
+ sent = JSON.parse(opts.body);
+ return new Response(JSON.stringify({ task_id: 'task-partcrafter', status: 'queued' }), {
+ status: 202,
+ headers: { 'content-type': 'application/json' },
+ });
+ });
+
+ const provider = createRegenProvider();
+ await provider.submit({
+ mode: 'partcrafter',
+ sourceUrl: 'https://three.ws/cdn/front.png',
+ params: { images: ['https://three.ws/cdn/front.png'] },
+ });
+
+ expect(sent.num_parts).toBe(4);
+ });
+
+ it('surfaces parts/part_count/manifest_url from the finished task record', async () => {
+ process.env.MODEL_PARTCRAFTER_URL = 'https://partcrafter.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ const parts = [
+ { id: 'part_01', name: 'part_01', face_count: 1200 },
+ { id: 'part_02', name: 'part_02', face_count: 980 },
+ { id: 'part_03', name: 'part_03', face_count: 760 },
+ ];
+ globalThis.fetch = vi.fn(async (url) => {
+ if (String(url).endsWith('/infer')) {
+ return new Response(JSON.stringify({ task_id: 'task-partcrafter', status: 'queued' }), {
+ status: 202,
+ headers: { 'content-type': 'application/json' },
+ });
+ }
+ return new Response(
+ JSON.stringify({
+ status: 'done',
+ result_gcs_url: 'https://cdn.example/parts.glb',
+ manifest_url: 'https://cdn.example/parts.manifest.json',
+ parts,
+ part_count: parts.length,
+ }),
+ { status: 200, headers: { 'content-type': 'application/json' } },
+ );
+ });
+
+ const provider = createRegenProvider();
+ const submitted = await provider.submit({
+ mode: 'partcrafter',
+ sourceUrl: 'https://three.ws/cdn/front.png',
+ params: { images: ['https://three.ws/cdn/front.png'] },
+ });
+ const result = await provider.status(submitted.extJobId);
+
+ expect(result.status).toBe('done');
+ expect(result.resultGlbUrl).toBe('https://cdn.example/parts.glb');
+ expect(result.manifestUrl).toBe('https://cdn.example/parts.manifest.json');
+ expect(result.parts).toEqual(parts);
+ expect(result.partCount).toBe(3);
+ });
+
+ it('a non-parts backend (trellis2) does not report parts/partCount', async () => {
+ process.env.MODEL_TRELLIS2_URL = 'https://trellis2.example.run.app';
+ process.env.GCP_RECONSTRUCTION_KEY = 'secret';
+ globalThis.fetch = vi.fn(async (url) => {
+ if (String(url).endsWith('/infer')) {
+ return new Response(JSON.stringify({ task_id: 'task-t2', status: 'queued' }), {
+ status: 202,
+ headers: { 'content-type': 'application/json' },
+ });
+ }
+ return new Response(JSON.stringify({ status: 'done', result_gcs_url: 'https://cdn.example/plain.glb' }), {
+ status: 200,
+ headers: { 'content-type': 'application/json' },
+ });
+ });
+
+ const provider = createRegenProvider();
+ const submitted = await provider.submit({
+ mode: 'trellis2',
+ sourceUrl: 'https://three.ws/cdn/front.png',
+ params: { images: ['https://three.ws/cdn/front.png'] },
+ });
+ const result = await provider.status(submitted.extJobId);
+ expect(result.parts).toBeUndefined();
+ expect(result.partCount).toBeUndefined();
+ });
+});
diff --git a/tests/forge-options.test.js b/tests/forge-options.test.js
index d1f5c6852..49a160c0f 100644
--- a/tests/forge-options.test.js
+++ b/tests/forge-options.test.js
@@ -136,6 +136,29 @@ describe('normalizeForgeOptions: view_labels & fill_other_sides', () => {
});
});
+describe('normalizeForgeOptions: num_parts (PartCrafter)', () => {
+ it('accepts an in-range integer and defaults to null when omitted', () => {
+ expect(normalizeForgeOptions({ num_parts: 6 }).numParts).toBe(6);
+ expect(normalizeForgeOptions({}).numParts).toBeNull();
+ });
+
+ it('rejects a value below PartCrafter minParts', () => {
+ const o = normalizeForgeOptions({ num_parts: 1 });
+ expect(o.numParts).toBeNull();
+ expect(o.errors[0].field).toBe('num_parts');
+ });
+
+ it('rejects a value above PartCrafter maxParts', () => {
+ const o = normalizeForgeOptions({ num_parts: 17 });
+ expect(o.numParts).toBeNull();
+ expect(o.errors[0].field).toBe('num_parts');
+ });
+
+ it('rejects a non-integer num_parts', () => {
+ expect(normalizeForgeOptions({ num_parts: 4.5 }).errors[0].field).toBe('num_parts');
+ });
+});
+
describe('summarizeForgeOptions', () => {
it('echoes the resolved options for the response', () => {
const o = normalizeForgeOptions({ seed: 9, output_format: 'glb-draco', texture_size: 1024 });
@@ -147,12 +170,18 @@ describe('summarizeForgeOptions', () => {
resolution: null,
view_labels: null,
fill_other_sides: false,
+ num_parts: null,
// Material completion is on unless the caller opts out, and the echo
// says so, so a client can tell why its delivered file carries maps.
derive_pbr: true,
});
});
+ it('echoes num_parts when supplied', () => {
+ const o = normalizeForgeOptions({ num_parts: 8 });
+ expect(summarizeForgeOptions(o).num_parts).toBe(8);
+ });
+
it('echoes view_labels and fill_other_sides when supplied', () => {
const o = normalizeForgeOptions({ view_labels: ['front', 'back'], fill_other_sides: true });
const s = summarizeForgeOptions(o);