import { test, expect } from "@playwright/test"; import { bootDuck } from "./support/simulation.js"; import { arenaWalls } from "../src/platform/worlds/arena.js"; const boundary = { half_extent: 2.25, wall_height: 0.25, wall_thickness: 0.05 }; test("all three robots keep Microduck's arena-to-body proportions; visual and physical walls agree", async ({ page, }, info) => { await bootDuck(page); for (const [id, scale] of [ ["microduck-legs", 1], ["microban", 0.33 / 0.27], ["rp1", 1.32 / 0.27], ]) { if (id !== "microduck-legs") expect( await page.evaluate((id) => window.__gameApi.switchRobot(id), id), ).toBe(true); const fitted = Object.fromEntries( Object.entries(boundary).map(([k, v]) => [k, v * scale]), ); const state = await page.evaluate(() => { const r = window.rl; return { id: r.world.id, boundary: r.world.boundary, scale: r.world.scale, following: r.chaseCam, grid: r.scene.getObjectByName("arena-grid") ? { cell: r.scene.getObjectByName("arena-grid").material.uniforms .uCell.value, fade: r.scene.getObjectByName("arena-grid").material.uniforms .uFadeDist.value, } : null, walls: ["wall_px", "wall_nx", "wall_py", "wall_ny"].map((name) => { const g = r.model.geom(name).id; return { name, pos: Array.from(r.model.geom_pos.slice(g * 3, g * 3 + 3)), size: Array.from(r.model.geom_size.slice(g * 3, g * 3 + 3)), type: r.model.geom_type[g], body: r.model.geom_bodyid[g], }; }), visuals: [0, 1, 2, 3].map((i) => r.scene.getObjectByName(`arena-boundary-${i}`).position.toArray(), ), }; }); expect(state.id).toBe("arena"); expect(state.boundary).toEqual(fitted); expect(state.scale).toBe(scale); expect(state.following).toBe(true); expect(state.walls).toEqual( arenaWalls(fitted).map((w) => ({ ...w, type: 6, body: 0 })), ); expect(state.visuals).toEqual([ [fitted.half_extent, fitted.wall_height / 2, 0], [-fitted.half_extent, fitted.wall_height / 2, 0], [0, fitted.wall_height / 2, fitted.half_extent], [0, fitted.wall_height / 2, -fitted.half_extent], ]); if (state.grid) { expect(state.grid.cell).toBeCloseTo(0.1 * scale, 8); expect(state.grid.fade).toBeCloseTo(3 * scale, 8); } } // QA overview only; normal entry remains the rear chase framing above. await page.locator("canvas").click({ position: { x: 1000, y: 700 } }); await page.evaluate(() => { const r = window.rl; const scale = r.world.scale; r.controls.maxDistance = 8 * scale; r.camera.position.set(-3 * scale, 3 * scale, 3 * scale); r.controls.target.set(0, 0, 0); r.controls.update(); }); await page.screenshot({ path: info.outputPath("bounded-arena.png") }); }); test("a future Package with no world field automatically loads the bounded default", async ({ page, }) => { await page.route("**/robots/index.json*", async (route) => { const response = await route.fetch(), entries = await response.json(); entries.push({ id: "future-bot", family: "future-bot", name: "Future Robot", manifest: "microban/robot.json?future=1", }); await route.fulfill({ response, json: entries }); }); await page.route("**/robots/microban/robot.json?future=1", async (route) => { const response = await route.fetch(), config = await response.json(); config.id = config.family = "future-bot"; delete config.presentation.world; await route.fulfill({ response, json: config }); }); await bootDuck(page); expect( await page.evaluate(() => window.__gameApi.switchRobot("future-bot")), ).toBe(true); expect( await page.evaluate(() => ({ id: window.__store.getState().robotId, world: window.rl.world.id, bounds: window.rl.world.boundary, })), ).toEqual({ id: "future-bot", world: "arena", bounds: Object.fromEntries( Object.entries(boundary).map(([k, v]) => [k, v * (0.33 / 0.27)]), ), }); }); for (const robot of [ { id: "microban", forward: 0.15, pad: 0.2 }, { id: "rp1", forward: 0.4, pad: 0.35 }, ]) test(`${robot.id}: real scaled wall contacts block motion on all four sides without coordinate clamping`, async ({ page, }, info) => { await bootDuck(page); expect( await page.evaluate((id) => window.__gameApi.switchRobot(id), robot.id), ).toBe(true); const results = await page.evaluate(async (robot) => { const r = window.rl, report = [], half = r.world.boundary.half_extent; for (const [name, axis, sign, yaw] of [ ["wall_px", 0, 1, 0], ["wall_nx", 0, -1, Math.PI], ["wall_py", 1, 1, Math.PI / 2], ["wall_ny", 1, -1, -Math.PI / 2], ]) { await r.resetSim(); const id = r.model.geom(name).id; r.data.qpos[axis] = sign * (half - robot.pad); r.data.qpos[3] = Math.cos(yaw / 2); r.data.qpos[6] = Math.sin(yaw / 2); r.mujoco.mj_forward(r.model, r.data); r.command.set([robot.forward, 0, 0]); let contacts = 0, max = sign * r.data.qpos[axis]; for (let tick = 0; tick < 30; tick++) { await r.step(5); max = Math.max(max, sign * r.data.qpos[axis]); const list = r.data.contact; for (let i = 0; i < r.data.ncon; i++) { const c = list.get(i); if (c.geom1 === id || c.geom2 === id) contacts++; c.delete(); } list.delete(); } report.push({ name, contacts, max, half, time: r.data.time, fallen: r.fallen, finite: Array.from(r.data.qpos).every(Number.isFinite), }); } return report; }, robot); for (const r of results) { expect(r.contacts, JSON.stringify(r)).toBeGreaterThan(0); expect(r.max, JSON.stringify(r)).toBeLessThan(r.half); expect(r.time).toBeCloseTo(3, 6); expect(r.finite).toBe(true); } await info.attach("wall-contacts.json", { body: JSON.stringify(results, null, 2), contentType: "application/json", }); });