Files
VibemakerSandbox/app/e2e/runtime-leaks.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

95 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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) => {
// Twenty cold transitions now also decode RP1's ~93 MB textured GLBs.
// Keep allocation/listener assertions unchanged; allow load-time headroom.
test.setTimeout(240_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 = ["microban", "microduck-legs", "rp1"][i % 3];
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(),
toyGeometries:
window.rl.scene.getObjectByName("interactive-props")?.children
.length ?? 0,
};
}, 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"),
rp1 = measurements.filter((s) => s.id === "rp1");
for (const samples of [duck, ban, rp1]) {
expect(samples.at(-1).listeners).toBe(samples[0].listeners);
expect(samples.at(-1).sceneChildren).toBe(samples[0].sceneChildren);
// Each runtime owns 5–7 independent toy geometries. Compare the fixed
// scene allocation after removing this intentionally variable count.
expect(
samples.at(-1).memory.geometries - samples.at(-1).toyGeometries,
).toBeLessThanOrEqual(
samples[1].memory.geometries - samples[1].toyGeometries + 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));
});