Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Stop asserting real elapsed time in tests and wire the two unwired smokes

Nguyen Xuan An53f8141706b6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88b0a2f3..e6fd45b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- No test asserts real elapsed time any more (issue #179). The relation chain test counts bounds reads, the particle seek test checks a stateless seek in fixed buffers, the material graph test checks the rejection, and the bake and path tracer limit tests run on a fake clock. `smoke-agent-review-close` no longer asserts seconds, `smoke-film-physics` starts its own server instead of assuming port 5173, and both have npm scripts (`smoke:agent-review-close`, `smoke:film-physics`).
- Remove the AGPL-3.0 `@codepawlhq/orglet-ui` package, React and react-dom from the website (issue #176). The site now uses its own tokens and button in `src/site-tokens.css` and `src/site-controls.js`, and screenshots of the pages match before and after. The site JavaScript drops from 1,778,425 to 1,531,367 bytes. The published package was never affected.
- A renderer no longer draws its shadow map a second time on the first frame when the frame has no assembly; the constructor already drew it. On `mountain-valley` that removes 9.72 million shadow triangles from the first frame, with identical pictures (issue #171). `node bench/reference/profile-scene.mjs <scene>` prints where a scene's time goes, and `frame-time.mjs --plain` measures scenes that are too large for the light bake.
- Tell an agent when its scene is a closed room with no bake (issue #163). `scene_inspect` now returns a `closed-room-without-bake` diagnostic when 90 percent or more of 48 rays from the middle of the scene hit a front face, and names `bake`; measured against Cycles a closed room goes from 0.1430 and 0.1436 (`dark-shaft`, `temple-hall`) to 0.0609 and 0.0560 once baked. No frame cost and no schema change; agent scene entry grows 884 bytes gzip. `bakeSkyVisibility` in `light-bake` writes only the occlusion map (0.1021 and 0.0856 in under a second) and is not applied automatically. **A closed room without a bake now shows a warning in `scene_inspect`.**
diff --git a/package.json b/package.json
index 073db73f..03ef203f 100644
--- a/package.json
+++ b/package.json
@@ -119,6 +119,8 @@
"smoke:frame-encoder": "node scripts/smoke-frame-encoder.mjs",
"smoke:enhancements": "node scripts/smoke-enhancements.mjs",
"smoke:site": "node scripts/smoke-site.mjs",
+ "smoke:agent-review-close": "node scripts/smoke-agent-review-close.mjs",
+ "smoke:film-physics": "node scripts/smoke-film-physics.mjs",
"publish:ci": "node scripts/publish-ci.mjs",
"smoke:character": "node scripts/smoke-character.mjs",
"smoke:modeling": "node scripts/smoke-modeling.mjs",
diff --git a/scripts/smoke-agent-review-close.mjs b/scripts/smoke-agent-review-close.mjs
index dcab8964..5c1f8922 100644
--- a/scripts/smoke-agent-review-close.mjs
+++ b/scripts/smoke-agent-review-close.mjs
@@ -27,7 +27,8 @@ try {
const outcome = await pending;
assert.equal(outcome.completed, false);
assert.equal((await runtime.capabilities()).phase, 'closed');
- assert.ok(elapsedSeconds < 5, 'Closing an active review must release resources promptly');
+ // No assertion on elapsedSeconds: a loaded machine made it flaky. The report keeps it for reading only, and the
+ // checks above prove the review ended and the runtime is closed.
const report = { activePhaseObserved: phase, finalPhase: 'closed', outcome, elapsedSeconds };
await writeFile('artifacts/agent-review-close.json', JSON.stringify(report, null, 2));
console.log(JSON.stringify(report));
diff --git a/scripts/smoke-film-physics.mjs b/scripts/smoke-film-physics.mjs
index 44948a06..42c049fa 100644
--- a/scripts/smoke-film-physics.mjs
+++ b/scripts/smoke-film-physics.mjs
@@ -1,11 +1,26 @@
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { writeFile } from 'node:fs/promises';
+import { spawn } from 'node:child_process';
+import { existsSync } from 'node:fs';
import { constants, setPriority } from 'node:os';
import { chromium } from 'playwright';
setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
-const browser = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe', headless: true, args: ['--enable-webgl', '--ignore-gpu-blocklist'] });
+const PORT = 5192;
+const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', String(PORT), '--strictPort'], { windowsHide: true, stdio: 'pipe' });
+await new Promise((resolve, reject) => {
+ const timeout = setTimeout(() => reject(new Error('The film physics smoke server did not start.')), 30000);
+ server.stdout.on('data', bytes => {
+ if (bytes.toString().includes(`127.0.0.1:${PORT}`)) {
+ clearTimeout(timeout);
+ resolve();
+ }
+ });
+ server.on('error', reject);
+});
+const chrome = 'C:/Program Files/Google/Chrome/Application/chrome.exe';
+const browser = await chromium.launch({ ...(existsSync(chrome) ? { executablePath: chrome } : {}), headless: true, args: ['--enable-webgl', '--ignore-gpu-blocklist'] });
const report = {};
try {
for (const [name, width, height] of [['wide', 960, 540], ['portrait', 540, 960]]) {
@@ -14,7 +29,7 @@ try {
page.on('pageerror', error => errors.push(error.message));
await page.route('**/src/film.js', route => route.fulfill({ contentType: 'application/javascript', body: "export * from '/build/film.js';" }));
await page.route('**/src/renderer.js', route => route.fulfill({ contentType: 'application/javascript', body: "export { Renderer67 } from '/build/67.module.js';" }));
- await page.goto(`http://127.0.0.1:5173/film.html?export=1&width=${width}&height=${height}`);
+ await page.goto(`http://127.0.0.1:${PORT}/film.html?export=1&width=${width}&height=${height}`);
await page.waitForFunction(() => window.__filmReady);
const result = await page.evaluate(() => {
const scene = window.__film.scenes.apparatus;
@@ -79,4 +94,5 @@ try {
console.log(JSON.stringify(report, null, 2));
} finally {
await browser.close();
+ server.kill();
}
diff --git a/tests/agent-bake.test.js b/tests/agent-bake.test.js
index 2d2abfec..8915d676 100644
--- a/tests/agent-bake.test.js
+++ b/tests/agent-bake.test.js
@@ -61,7 +61,7 @@ test('a recipe bake lights the room with lightmaps and reports its time and skip
const scene = createAgentScene(closedRoom());
const bake = scene.inspect().bake;
assert.equal(bake.reused, false);
- assert.ok(bake.seconds > 0);
+ assert.ok(Number.isFinite(bake.seconds) && bake.seconds >= 0);
assert.ok(bake.texels > 0);
assert.deepEqual(bake.skipped, []);
const floor = scene.parts.find(part => part.name === 'floor');
@@ -198,7 +198,7 @@ test('a preset on a 56 part room shrinks to the path work budget, finishes, and
assert.ok(bake.used.texelsPerUnit < BAKE_PRESETS.standard.texelsPerUnit);
assert.equal(bake.used.bounces, BAKE_PRESETS.standard.bounces);
assert.ok(bake.texels * bake.used.samples * bake.used.bounces <= BAKE_PRESET_PATH_WORK);
- assert.ok(bake.seconds < BAKE_MAXIMUM_SECONDS);
+ assert.ok(Number.isFinite(bake.seconds) && bake.seconds >= 0, 'the report carries the time the bake took');
const again = createAgentScene(largeRoom({ preset: 'standard' }));
assert.deepEqual(again.inspect().bake.used, bake.used);
assert.deepEqual(lightmapBytesOf(again, 'floor'), lightmapBytesOf(scene, 'floor'));
diff --git a/tests/light-bake.test.js b/tests/light-bake.test.js
index c4ff8a6d..baa7df27 100644
--- a/tests/light-bake.test.js
+++ b/tests/light-bake.test.js
@@ -219,7 +219,18 @@ test('a light mapped part exports its second UV set as TEXCOORD_1 and its light
test('a bake that runs out of time throws instead of returning a partial result', () => {
const slow = { samples: 256, bounces: 4, texelsPerUnit: 8, maxResolution: 128, maxSeconds: 1 };
- assert.throws(() => bakeLightmaps(smallRoom(), lamp, slow), /maxSeconds/);
+ // Each clock read costs a second, so the limit is passed on any machine.
+ const realNow = performance.now;
+ let clockReads = 0;
+ performance.now = () => {
+ clockReads += 1;
+ return clockReads * 1000;
+ };
+ try {
+ assert.throws(() => bakeLightmaps(smallRoom(), lamp, slow), /maxSeconds/);
+ } finally {
+ performance.now = realNow;
+ }
});
// The mean light a baked part stores, in linear units: the texture is sRGB and is scaled back by the part's emission.
diff --git a/tests/material-graph.test.js b/tests/material-graph.test.js
index 71ffcf03..45fa9748 100644
--- a/tests/material-graph.test.js
+++ b/tests/material-graph.test.js
@@ -197,9 +197,11 @@ test('hostile sizes and costs are rejected before any work', () => {
const costly = { height: { voronoi: { scale: 8, at: { add: [{ uv: 'both' }, { mul: [{ vec: [{ noise: { octaves: 6 } }, { noise: { octaves: 6 } }, 0] }, 0.1] }] } } } };
let graph = costly.height;
for (let level = 0; level < 5; level++) graph = { add: [graph, { voronoi: { scale: 4, at: { vec: [graph, 0, 0] } } }] };
- const started = Date.now();
- assert.throws(() => normalizeMaterialPattern({ type: 'graph', graph: { height: graph }, resolution: 1024 }), /Material graph/);
- assert.ok(Date.now() - started < 1000);
+ // The limits reject the graph while it is normalized, before any pixel is evaluated, so no clock is involved.
+ assert.throws(
+ () => normalizeMaterialPattern({ type: 'graph', graph: { height: graph }, resolution: 1024 }),
+ error => /^Material graph: nesting deeper than/.test(error.message),
+ );
});
test('hostile strings never reach a texture, a recipe or a shader', () => {
diff --git a/tests/part-relations.test.js b/tests/part-relations.test.js
index afbf993d..e4b4668d 100644
--- a/tests/part-relations.test.js
+++ b/tests/part-relations.test.js
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createAgentScene } from '../src/agent-scene.js';
+import { normalizeRelations, solveRelations } from '../src/agent-relations.js';
function recipeWith(nodes, geometries = []) {
return {
@@ -204,14 +205,23 @@ test('relation nodes are bounded', () => {
rejects(nodes, /At most 256 nodes can carry relations/);
});
-test('a long chain of relations solves quickly', () => {
+test('a long chain of relations solves with work in proportion to its length', () => {
const nodes = [{ id: 'part0', scale: [0.1, 0.1, 0.1] }];
for (let index = 1; index < 200; index++) {
nodes.push({ id: `part${index}`, scale: [0.1, 0.1, 0.1], relations: [{ kind: 'attach', to: `part${index - 1}`, side: '+x' }] });
}
- const started = performance.now();
- const scene = createAgentScene(recipeWith(nodes.reverse()));
- assert.ok(performance.now() - started < 3000);
+ nodes.reverse();
+ // Counting bounds reads replaces a stopwatch: each related part reads its own bounds and its target's, once.
+ const solverNodes = normalizeRelations(nodes.map(node => ({
+ geometry: 'cube', parent: null, rotation: [0, 0, 0, 1], translation: [0, 0, 0], ...node,
+ })));
+ let boundsReads = 0;
+ solveRelations(solverNodes, (node, matrix) => {
+ boundsReads += 1;
+ return { min: [matrix[12] - 0.05, -0.05, -0.05], max: [matrix[12] + 0.05, 0.05, 0.05] };
+ });
+ assert.equal(boundsReads, 2 * 199);
+ const scene = createAgentScene(recipeWith(nodes));
near(worldBounds(scene, 'part199').min[0], worldBounds(scene, 'part198').max[0], 'end of the chain');
});
diff --git a/tests/particles.test.js b/tests/particles.test.js
index ddf23ffb..e56bc7e1 100644
--- a/tests/particles.test.js
+++ b/tests/particles.test.js
@@ -223,16 +223,25 @@ test('a particle node cannot carry motion or physics, or be a cloth sheet', () =
assert.throws(() => createAgentScene(child), /root node/);
});
-test('a large burst samples within a bounded time, and a huge time is only a dead system', () => {
+test('a large burst seeks statelessly in fixed buffers, and a huge time is only a dead system', () => {
const nodes = ['b'].map(id => ({ id, geometry: 'speck', material: 'glow' }));
const scene = createAgentScene(sparkRecipe({ wind: [2, 0, 0], systems: [
{ node: 'sparks', count: 2000, floor: 0, drag: 0.3, lifetime: [1, 3], speed: [1, 8], spread: 180 },
{ node: 'b', count: 2000, rate: 400, lifetime: 3, drag: 0.3, emitter: { shape: 'box' } },
] }, nodes));
- const started = performance.now();
- for (const time of [0.3, 1, 2, 3.7, 0.3]) scene.sampleMotion(time);
- const perSeek = (performance.now() - started) / 5;
- assert.ok(perSeek < 150, `a seek of 4000 particles took ${perSeek.toFixed(1)} ms`);
+ // A seek computes each particle from its launch and the time alone, so its work is the particle count and never
+ // grows with the seeks before it: the same time gives the same result after any history, in buffers of one size.
+ const bothSystems = () => [...particlePositions(scene), ...particlePositions(scene, 'b')];
+ scene.sampleMotion(0.3);
+ const firstSeek = bothSystems();
+ const bufferSizes = new Set();
+ for (const time of [1, 2, 3.7]) {
+ scene.sampleMotion(time);
+ bufferSizes.add(bothSystems().length);
+ }
+ scene.sampleMotion(0.3);
+ assert.deepEqual(bothSystems(), firstSeek);
+ assert.equal(bufferSizes.size, 1, 'the particle buffers keep one size across seeks');
scene.sampleMotion(3600);
assert.ok(particlePositions(scene).every(Number.isFinite));
assert.throws(() => scene.sampleMotion(3601), /Motion time/);
diff --git a/tests/path-tracer.test.js b/tests/path-tracer.test.js
index 2ec860ec..2a5370a3 100644
--- a/tests/path-tracer.test.js
+++ b/tests/path-tracer.test.js
@@ -128,10 +128,21 @@ test('a block between the sun and the floor leaves a shadow', async () => {
});
test('a render that runs out of time throws and returns nothing', async () => {
- await assert.rejects(
- renderPathTracedImage(checkerScene(), { width: 256, height: 256, samples: 1024, bounces: 4, maxSeconds: 1, threads: 1 }),
- /1 second limit/,
- );
+ // Each clock read costs a second, so the limit is passed on any machine.
+ const realNow = performance.now;
+ let clockReads = 0;
+ performance.now = () => {
+ clockReads += 1;
+ return clockReads * 1000;
+ };
+ try {
+ await assert.rejects(
+ renderPathTracedImage(checkerScene(), { width: 256, height: 256, samples: 1024, bounces: 4, maxSeconds: 1, threads: 1 }),
+ /1 second limit/,
+ );
+ } finally {
+ performance.now = realNow;
+ }
});
test('denoising keeps the mean of a noisy image and removes some of its noise', async () => {