Files
VibemakerSandbox/app/test/default-world.test.js
T
chenlin fa089d5f0c feat: release v0.2 multi-robot simulator
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control.

Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
2026-10-28 14:00:26 +08:00

108 lines
3.5 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs/promises";
import * as THREE from "three";
import {
DEFAULT_WORLD,
resolveWorldId,
arenaWalls,
} from "../src/platform/worlds/arena.js";
import {
validatePackage,
validateWorld,
} from "../src/platform/loader/SchemaValidator.js";
import { createArenaFloorPresentation } from "../src/game/worlds/arena/presentation.js";
const world = JSON.parse(
await fs.readFile(
new URL("../public/worlds/arena/world.json", import.meta.url),
),
);
test("all bundled and future Packages default to the same 50%-larger arena; explicit diagnostic overrides remain possible", async () => {
assert.equal(DEFAULT_WORLD, "arena");
validateWorld(world);
assert.equal(world.type, "flat");
assert.deepEqual(world.boundary, {
half_extent: 2.25,
wall_height: 0.25,
wall_thickness: 0.05,
});
assert.equal(world.boundary.half_extent / 1.5, 1.5);
for (const id of ["microduck-legs", "microduck-rollers", "microban"]) {
const config = JSON.parse(
await fs.readFile(
new URL(`../public/robots/${id}/robot.json`, import.meta.url),
),
);
validatePackage(config);
assert.equal(resolveWorldId(config), "arena");
if (id === "microban") {
config.id = "future-bot";
config.family = "future-bot";
delete config.presentation.world;
validatePackage(config);
assert.equal(resolveWorldId(config), "arena");
config.presentation.world = "flat";
assert.equal(resolveWorldId(config), "flat");
}
}
});
test("physical wall inner faces match 4.5m bounds and corners overlap", () => {
const walls = arenaWalls(world.boundary);
assert.equal(walls.length, 4);
assert.deepEqual(walls[0], {
name: "wall_px",
pos: [2.275, 0, 0.125],
size: [0.025, 2.3, 0.125],
});
assert.deepEqual(walls[2], {
name: "wall_py",
pos: [0, 2.275, 0.125],
size: [2.3, 0.025, 0.125],
});
for (const w of walls) {
assert.equal(w.size[2] * 2, 0.25);
assert.ok(w.size[0] === 0.025 || w.size[1] === 0.025);
}
});
test("visual walls stay at physical inner faces while the floor focus follows; all resources release once", () => {
const defs = [
"platform_floor",
...arenaWalls(world.boundary).map((w) => w.name),
],
meshes = defs.map(() => new THREE.Mesh());
const sim = { model: { geom: (name) => ({ id: defs.indexOf(name) }) } },
rig = { items: meshes.map((mesh, id) => ({ mesh, id })) };
const view = createArenaFloorPresentation({ sim, rig, world });
assert.equal(view.walls.length, 4);
assert.ok(meshes.every((m) => !m.visible));
const positions = view.walls.map((m) => m.position.toArray());
assert.deepEqual(positions[0], [2.25, 0.125, 0]);
assert.deepEqual(positions[2], [0, 0.125, 2.25]);
view.update(new THREE.Vector3(1, 0.2, -1));
assert.deepEqual(
view.walls.map((m) => m.position.toArray()),
positions,
);
let releases = 0;
for (const mesh of [view.grid, ...view.walls]) {
mesh.geometry.addEventListener("dispose", () => releases++);
mesh.material.addEventListener("dispose", () => releases++);
}
view.dispose();
view.dispose();
assert.equal(releases, 10);
assert.ok(meshes.every((m) => m.visible));
});
test("invalid physical boundaries are rejected", () => {
for (const bad of [
{ half_extent: 0 },
{ wall_height: -1 },
{ wall_thickness: 0 },
])
assert.throws(
() =>
validateWorld({ ...world, boundary: { ...world.boundary, ...bad } }),
/boundary/,
);
});