Files
VibemakerSandbox/app/e2e/shared-environment.spec.js
chenlin a8be5e0134 feat: release v0.5 with shared interactive arenas and textured RP1
Unify lighting and line-colour controls across robots, replace the football with a shared layout of draggable physical props, and import the supplied RP1 GLBs without changing trained physics or policies.

Include reproducible visual import/provenance, regression coverage and verification records. Verified 66 unit tests, 55 browser tests and production-build checks.
2026-10-30 14:14:03 +08:00

158 lines
5.9 KiB
JavaScript

import { test, expect } from "@playwright/test";
import { bootDuck } from "./support/simulation.js";
test("all robots share the same scaled random layout, lighting, line palette and global colour selection", async ({
page,
}) => {
const errors = await bootDuck(page);
let reference;
let expected = { name: "Sky", key: "blue", hex: "a9dbe8" };
for (const id of ["microduck-legs", "microban", "rp1", "microduck-legs"]) {
if ((await page.evaluate(() => window.__store.getState().robotId)) !== id)
await page.evaluate((id) => window.__gameApi.switchRobot(id), id);
await expect(
page.getByRole("group", { name: "Scene line colours" }),
).toBeVisible();
if (!reference)
await page.getByRole("button", { name: "Sky scene lines" }).click();
const state = await page.evaluate(() => {
const r = window.rl,
scale = r.world.boundary.half_extent / 2.25;
const lines = [];
r.scene.traverse((o) => {
if (o.material?.uniforms?.uSectionColor)
lines.push(o.material.uniforms.uSectionColor.value.getHexString());
});
return {
specs: r.interactiveProps.map((p) => ({
name: p.name,
type: p.type,
color: p.color,
pos: p.pos.map((v) => v / scale),
size: p.size.map((v) => v / scale),
})),
count: r.scene.getObjectByName("interactive-props").children.length,
lines,
lineColor: window.__store.getState().lineColor,
lights: r.scene.parent.children
.filter((o) => o.isLight)
.map((o) => [o.type, o.intensity, o.color.getHex()]),
environment: r.scene.parent.environmentIntensity,
drag: window.__store.getState().runtimeCapabilities.physicalDrag,
};
});
expect(state.count).toBeGreaterThanOrEqual(5);
expect(state.count).toBeLessThanOrEqual(7);
expect(state.lines).toEqual(Array(5).fill(expected.hex));
expect(state.lineColor).toBe(expected.key);
expect(state.drag).toBe(true);
if (!reference) reference = state;
state.specs.forEach((p, i) => {
expect(p.type).toBe(reference.specs[i].type);
expect(p.color).toBe(reference.specs[i].color);
p.pos.forEach((v, j) =>
expect(v).toBeCloseTo(reference.specs[i].pos[j], 12),
);
p.size.forEach((v, j) =>
expect(v).toBeCloseTo(reference.specs[i].size[j], 12),
);
});
expect(state.lights).toEqual(reference.lights);
expect(state.environment).toBe(reference.environment);
await expect(
page.getByRole("button", { name: `${expected.name} scene lines` }),
).toHaveAttribute("aria-pressed", "true");
await expect(
page.getByRole("button", { name: "Rollers", exact: true }),
).toHaveCount(id === "microduck-legs" ? 1 : 0);
// Also carry a choice made in another robot back to Microduck.
if (id === "rp1") {
await page.getByRole("button", { name: "Lavender scene lines" }).click();
expected = { name: "Lavender", key: "purple", hex: "bfa9cf" };
}
}
expect(errors).toEqual([]);
});
for (const id of ["microban", "rp1"]) {
test(`${id}: shared toys collide with walls, drag with real force and release on pause`, async ({
page,
}) => {
const errors = await bootDuck(page);
await page.evaluate((id) => window.__gameApi.switchRobot(id), id);
const wall = await page.evaluate(async () => {
const r = window.rl,
scale = r.world.boundary.half_extent / 2.25,
p = r.interactiveProps.find((s) => s.type === "sphere"),
half = r.world.boundary.half_extent;
r.data.qpos.set([half - 0.2 * scale, 0.9 * scale, p.pos[2]], p.qAdr);
r.data.qvel[p.dofAdr] = 1.5 * scale;
r.mujoco.mj_forward(r.model, r.data);
let max = -Infinity;
for (let i = 0; i < 15; i++) {
await r.step(1);
max = Math.max(max, r.data.qpos[p.qAdr]);
}
await r.resetSim();
return { max, limit: half - 0.025 * scale };
});
expect(wall.max).toBeLessThan(wall.limit);
await page.getByRole("button", { name: /Keyboard controls/ }).click();
await page.evaluate(() => {
const r = window.rl,
scale = r.world.scale ?? 1,
p = r.interactiveProps[0],
q = r.data.qpos;
q.set([0.25 * scale, -0.3 * scale, p.pos[2]], p.qAdr);
r.mujoco.mj_forward(r.model, r.data);
r.camera.position.set(q[0], q[2] + 0.6 * scale, 1.5 * scale);
r.controls.target.set(q[0], q[2], -q[1]);
r.controls.update();
window.__gameApi.resume();
});
await page.waitForTimeout(200);
const point = await page.evaluate(() => {
const r = window.rl,
p = r.interactiveProps[0],
q = r.data.qpos,
rect = document.querySelector("canvas").getBoundingClientRect();
const v = r.controls.target
.clone()
.set(q[p.qAdr], q[p.qAdr + 2], -q[p.qAdr + 1])
.project(r.camera);
return {
x: ((v.x + 1) * rect.width) / 2,
y: ((1 - v.y) * rect.height) / 2,
};
});
await page.mouse.move(point.x, point.y);
await page.mouse.down();
expect(await page.evaluate(() => window.rl.controls.enabled)).toBe(false);
await page.mouse.move(point.x + 70, point.y - 35, { steps: 5 });
await page.waitForTimeout(200);
expect(
await page.evaluate(() =>
Array.from(window.rl.data.xfrc_applied).some((v) => Math.abs(v) > 1e-5),
),
).toBe(true);
await page.evaluate(() => window.__gameApi.pause());
expect(await page.evaluate(() => window.rl.controls.enabled)).toBe(true);
expect(
await page.evaluate(() =>
Array.from(window.rl.data.xfrc_applied).every((v) => v === 0),
),
).toBe(true);
await page.mouse.up();
await page.evaluate(() => window.__gameApi.reset());
expect(
await page.evaluate(() => {
const r = window.rl;
return r.interactiveProps.every((p) =>
p.pos.every((v, i) => r.data.qpos[p.qAdr + i] === v),
);
}),
).toBe(true);
expect(errors).toEqual([]);
});
}