fc5ee4f2c6
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.
85 lines
3.1 KiB
JavaScript
85 lines
3.1 KiB
JavaScript
import { test, expect } from "@playwright/test";
|
|
// All twenty transitions run in one page and one shared WASM instance.
|
|
test("20 robot transitions release old WASM objects and plateau scene/GPU/listeners", async ({
|
|
page,
|
|
}, info) => {
|
|
test.setTimeout(180_000);
|
|
await page.addInitScript(() => {
|
|
const add = EventTarget.prototype.addEventListener,
|
|
remove = EventTarget.prototype.removeEventListener,
|
|
targets = new Map();
|
|
const key = (type, options) =>
|
|
`${type}:${typeof options === "boolean" ? options : !!options?.capture}`;
|
|
EventTarget.prototype.addEventListener = function (type, cb, options) {
|
|
if (this === window || this instanceof HTMLCanvasElement) {
|
|
let entries = targets.get(this);
|
|
if (!entries) {
|
|
entries = new Map();
|
|
targets.set(this, entries);
|
|
}
|
|
const k = key(type, options);
|
|
if (!entries.has(k)) entries.set(k, new Set());
|
|
entries.get(k).add(cb);
|
|
}
|
|
return add.call(this, type, cb, options);
|
|
};
|
|
EventTarget.prototype.removeEventListener = function (type, cb, options) {
|
|
targets.get(this)?.get(key(type, options))?.delete(cb);
|
|
return remove.call(this, type, cb, options);
|
|
};
|
|
window.listenerCount = () =>
|
|
[...targets.values()].reduce(
|
|
(n, entries) =>
|
|
n + [...entries.values()].reduce((a, set) => a + set.size, 0),
|
|
0,
|
|
);
|
|
});
|
|
await page.goto("/");
|
|
await expect(
|
|
page.getByRole("button", { name: "Pause", exact: true }),
|
|
).toBeEnabled();
|
|
await page.evaluate(() => window.__gameApi.pause());
|
|
const measurements = [];
|
|
for (let i = 0; i < 20; i++) {
|
|
const id = i % 2 === 0 ? "microban" : "microduck-legs";
|
|
console.log(`Ownership transition ${i + 1}/20: ${id}`);
|
|
const sample = await page.evaluate(async (id) => {
|
|
const model = window.rl.model,
|
|
data = window.rl.data;
|
|
const success = await window.__gameApi.switchRobot(id);
|
|
await new Promise((r) =>
|
|
requestAnimationFrame(() => requestAnimationFrame(r)),
|
|
);
|
|
return {
|
|
id,
|
|
success,
|
|
modelDeleted: model.isDeleted(),
|
|
dataDeleted: data.isDeleted(),
|
|
...window.__gameApi.diagnostics(),
|
|
listeners: window.listenerCount(),
|
|
};
|
|
}, id);
|
|
expect(sample.success).toBe(true);
|
|
expect(sample.modelDeleted).toBe(true);
|
|
expect(sample.dataDeleted).toBe(true);
|
|
measurements.push(sample);
|
|
}
|
|
const duck = measurements.filter((s) => s.id === "microduck-legs"),
|
|
ban = measurements.filter((s) => s.id === "microban");
|
|
for (const samples of [duck, ban]) {
|
|
expect(samples.at(-1).listeners).toBe(samples[0].listeners);
|
|
expect(samples.at(-1).sceneChildren).toBe(samples[0].sceneChildren);
|
|
expect(samples.at(-1).memory.geometries).toBeLessThanOrEqual(
|
|
samples[1].memory.geometries + 1,
|
|
);
|
|
expect(samples.at(-1).memory.textures).toBeLessThanOrEqual(
|
|
samples[1].memory.textures + 1,
|
|
);
|
|
}
|
|
await info.attach("runtime-ownership.json", {
|
|
body: JSON.stringify(measurements, null, 2),
|
|
contentType: "application/json",
|
|
});
|
|
console.log(JSON.stringify(measurements));
|
|
});
|