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.
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { ControlScheduler } from "../src/platform/runtime/ControlScheduler.js";
|
|
|
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
test("pause waits for an in-flight tick and never overlaps manual steps", async () => {
|
|
let ticks = 0,
|
|
active = 0,
|
|
max = 0;
|
|
const scheduler = new ControlScheduler(
|
|
async () => {
|
|
active++;
|
|
max = Math.max(max, active);
|
|
await delay(2);
|
|
ticks++;
|
|
active--;
|
|
},
|
|
{ dt: 0.001 },
|
|
);
|
|
scheduler.start();
|
|
await delay(12);
|
|
await scheduler.pause();
|
|
const paused = ticks;
|
|
await delay(8);
|
|
assert.equal(ticks, paused);
|
|
await scheduler.step(4);
|
|
assert.equal(ticks, paused + 4);
|
|
assert.equal(max, 1);
|
|
await scheduler.dispose();
|
|
assert.throws(() => scheduler.start(), /disposed/);
|
|
});
|
|
test("manual steps require pause, serialize, and reject invalid counts", async () => {
|
|
let ticks = 0;
|
|
const scheduler = new ControlScheduler(async () => {
|
|
await delay(1);
|
|
ticks++;
|
|
});
|
|
await Promise.all([scheduler.step(2), scheduler.step(3)]);
|
|
assert.equal(ticks, 5);
|
|
await assert.rejects(scheduler.step(-1), /count/);
|
|
scheduler.start();
|
|
await assert.rejects(scheduler.step(), /pause/);
|
|
await scheduler.dispose();
|
|
});
|
|
test("tick errors pause scheduling and report once", async () => {
|
|
const errors = [];
|
|
const scheduler = new ControlScheduler(
|
|
async () => {
|
|
throw new Error("inference");
|
|
},
|
|
{ onError: (e) => errors.push(e.message) },
|
|
);
|
|
scheduler.start();
|
|
await delay(10);
|
|
assert.equal(scheduler.running, false);
|
|
assert.deepEqual(errors, ["inference"]);
|
|
await scheduler.dispose();
|
|
});
|