Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Make every test file pass on its own and check it in CI

Nguyen Xuan And0ab820a87e8
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index d576602c..c71bb99d 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -25,6 +25,7 @@ jobs:
- run: npm audit --audit-level=high
- run: npm run size
- run: npm test
+ - run: npm run test:isolated
- run: npm run prepare:release
- run: npm run smoke:package
- run: npm run smoke:mcp-package
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e7ad26c8..b008df5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- Make every test file pass on its own, and check it in CI (issue #172). `node --test tests/agent-bake.test.js` failed 16 of 19 because `npm test` preloaded every on-demand module into each test process, so 28 files only passed through that preload. The loading path agents use was fine (`tests/agent-scene-on-demand.test.js` runs it in clean processes). Each of those files now imports `tests/support/load-agent-scene-modules.mjs` itself, `npm test` no longer preloads, and `npm run test:isolated` (`scripts/test-each-file.mjs`) runs each file in its own process, 4 at a time at below-normal priority, rerunning a failure alone once so a busy machine does not count. It runs in the `Test` workflow.
- The GitHub repository is `anxuanng/67.js`, public since 2026-11-02. Links and `repository.url` point there, which npm provenance needs to match.
- Follow 3 bounces by default in a light bake, up from 2 (part of issue #159, which stays open). Baked rooms scored worse after the sky visibility change (`lit-interior` 0.1444 to 0.1915, `brick-room` 0.1515 to 0.2048 against Cycles) because the occlusion map removed the world light that had been filling the light a 2 bounce path cuts off. With 3 bounces they score 0.1341 and 0.1412, `dark-shaft` 0.0609 and `temple-hall` 0.0560. A bake takes about 1.3 to 1.9 times as long (`temple-hall` 39 to 75 s); pass `bounces: 2` for the old light and time. Recipe presets are unchanged.
- Remove the streaks in baked dark scenes and the speckle in the fog's glow (part of issue #159, which stays open). A bake unwrapped each shared geometry once at unit size, so a 2 x 32 x 180 m wall got texels 90 times longer than wide (carpet 2,867 times), which drew as streaks fanning from the vanishing point; it now unwraps each part at its world size and smooths the gathered light and sky visibility over neighbouring texels of the same surface. The glow reads the frame's mip chain instead of 24 jittered single pixels. `bench/reference/noise.py` measures what FLIP misses (high frequency energy in dark regions and around the door): `temple-hall` baked 0.448 to 0.182 and its glow ring 1.826 to 0.990 (Cycles 0.158 and 1.053), `dark-shaft` baked 0.318 to 0.150; whole frame scores against Cycles stay within 0.006 and `temple-hall` baked goes from 0.0716 to 0.0578. A baked part's report `skyVisibility` now weighs texels by area, and baked thin parts get more texels (`brick-room` 28,576 to 98,848). Core grows 92 bytes gzip and a frame with fog costs about 0.5 ms more on a shared machine. **Baked scenes with long or thin parts look smoother and lightmaps are larger.**
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index d48bde61..90c840f3 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -34,7 +34,7 @@ Run `npm run smoke` or the `smoke:*` script for the area that you changed, and l
A change to skinning, glTF loading, poses or IK also needs `npm run smoke:character`, which takes a real character through the MCP server. Run `npm run prepare:release` first.
Screenshots and other output go to `artifacts/`, which Git ignores.
-Every pull request runs `npm audit`, `npm run size`, `npm test`, `prepare:release`, `smoke:package` and `smoke:mcp-package` in the `Test` workflow. `smoke:mcp-package` draws through the MCP server on SwiftShader in Chrome. `bench/size/README.md` says what to do when a size budget fails.
+Every pull request runs `npm audit`, `npm run size`, `npm test`, `npm run test:isolated` (each test file in its own process), `prepare:release`, `smoke:package` and `smoke:mcp-package` in the `Test` workflow. `smoke:mcp-package` draws through the MCP server on SwiftShader in Chrome. `bench/size/README.md` says what to do when a size budget fails.
GitHub offers no branch protection on this private repository, so a red check can not block a merge by itself. Merge a pull request only when the `test` and `GitGuardian Security Checks` checks both pass. The person or agent who merges is responsible for this.
diff --git a/package.json b/package.json
index 507cbb83..70984b5e 100644
--- a/package.json
+++ b/package.json
@@ -92,7 +92,8 @@
"prepack": "npm run build:lib",
"deploy": "node scripts/deploy.mjs",
"preview": "vite preview --host 127.0.0.1",
- "test": "node --import ./tests/support/load-agent-scene-modules.mjs --test",
+ "test": "node --test",
+ "test:isolated": "node scripts/test-each-file.mjs",
"smoke": "node scripts/smoke.mjs",
"smoke:scenes": "node scripts/smoke-scenes.mjs",
"smoke:transport": "node scripts/smoke-film-transport.mjs",
diff --git a/scripts/test-each-file.mjs b/scripts/test-each-file.mjs
new file mode 100644
index 00000000..8403387f
--- /dev/null
+++ b/scripts/test-each-file.mjs
@@ -0,0 +1,70 @@
+// Runs every tests/*.test.js in its own node process, so a test that only passes because an earlier file loaded
+// something for it fails here. Up to four processes run at once, at below-normal priority.
+// Usage: node scripts/test-each-file.mjs [file-name-fragment]
+import { spawn } from 'node:child_process';
+import { readdirSync } from 'node:fs';
+import { availableParallelism, constants, setPriority } from 'node:os';
+import { join } from 'node:path';
+
+const MAX_PARALLEL_PROCESSES = Math.min(4, availableParallelism());
+const repositoryRoot = join(import.meta.dirname, '..');
+const testsDirectory = join(repositoryRoot, 'tests');
+const nameFragment = process.argv[2];
+
+const testFiles = readdirSync(testsDirectory)
+ .filter(name => name.endsWith('.test.js'))
+ .filter(name => !nameFragment || name.includes(nameFragment))
+ .sort();
+
+function runTestFile(name) {
+ return new Promise(resolve => {
+ const startedAt = Date.now();
+ const child = spawn(process.execPath, ['--test', join('tests', name)], {
+ cwd: repositoryRoot,
+ stdio: ['ignore', 'pipe', 'pipe'],
+ });
+ try {
+ setPriority(child.pid, constants.priority.PRIORITY_BELOW_NORMAL);
+ } catch {
+ // The process may already have exited or the platform may refuse; priority is a courtesy.
+ }
+ let output = '';
+ child.stdout.on('data', chunk => (output += chunk));
+ child.stderr.on('data', chunk => (output += chunk));
+ child.on('close', code => resolve({ name, code, output, seconds: (Date.now() - startedAt) / 1000 }));
+ });
+}
+
+const firstPassFailures = [];
+let nextIndex = 0;
+
+async function worker() {
+ while (nextIndex < testFiles.length) {
+ const name = testFiles[nextIndex++];
+ const result = await runTestFile(name);
+ if (result.code !== 0) firstPassFailures.push(result);
+ }
+}
+
+const startedAt = Date.now();
+await Promise.all(Array.from({ length: MAX_PARALLEL_PROCESSES }, worker));
+
+// Some tests keep a real time limit (the light bake stops at 20 s), which a busy machine can trip. A file that fails
+// beside other processes is run again alone: only a failure there counts, because order dependence fails alone too.
+const failures = [];
+for (const first of firstPassFailures) {
+ const second = await runTestFile(first.name);
+ if (second.code === 0) {
+ console.log(`WARN ${first.name} failed beside other processes and passed alone; the machine was busy`);
+ } else {
+ failures.push(second);
+ console.log(`FAIL ${first.name} (${second.seconds.toFixed(1)}s)`);
+ }
+}
+const totalSeconds = ((Date.now() - startedAt) / 1000).toFixed(1);
+
+for (const failure of failures) {
+ console.log(`\n--- ${failure.name} ---\n${failure.output.split('\n').slice(0, 60).join('\n')}`);
+}
+console.log(`${testFiles.length - failures.length} of ${testFiles.length} test files pass alone in ${totalSeconds}s`);
+process.exit(failures.length ? 1 : 0);
diff --git a/tests/agent-bake.test.js b/tests/agent-bake.test.js
index 2d2abfec..3fdde457 100644
--- a/tests/agent-bake.test.js
+++ b/tests/agent-bake.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { createAgentScene } from '../src/agent-scene.js';
diff --git a/tests/agent-motion-constraints.test.js b/tests/agent-motion-constraints.test.js
index 659f01c0..044ec8c1 100644
--- a/tests/agent-motion-constraints.test.js
+++ b/tests/agent-motion-constraints.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { mat4, quat, vec3 } from 'gl-matrix';
diff --git a/tests/agent-motion-ik.test.js b/tests/agent-motion-ik.test.js
index 021a7474..7bf89808 100644
--- a/tests/agent-motion-ik.test.js
+++ b/tests/agent-motion-ik.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { mat4, vec3 } from 'gl-matrix';
diff --git a/tests/agent-physics.test.js b/tests/agent-physics.test.js
index 30820746..783aaf66 100644
--- a/tests/agent-physics.test.js
+++ b/tests/agent-physics.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createAgentScene, loadPhysicsEngine, needsPhysics } from '../src/agent-scene.js';
diff --git a/tests/agent-preview.test.js b/tests/agent-preview.test.js
index 79741901..abb4bf11 100644
--- a/tests/agent-preview.test.js
+++ b/tests/agent-preview.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { skinnedStripAsset } from './fixtures/skinned-strip.js';
diff --git a/tests/agent-scene-motion.test.js b/tests/agent-scene-motion.test.js
index f95eae25..ad879269 100644
--- a/tests/agent-scene-motion.test.js
+++ b/tests/agent-scene-motion.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createAgentScene } from '../src/agent-scene.js';
diff --git a/tests/agent-scene.test.js b/tests/agent-scene.test.js
index d6347da3..0d68ff14 100644
--- a/tests/agent-scene.test.js
+++ b/tests/agent-scene.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { Matrix4, Quaternion, Vector3 } from 'three';
diff --git a/tests/blender-constraints.test.js b/tests/blender-constraints.test.js
index b9125245..45e76751 100644
--- a/tests/blender-constraints.test.js
+++ b/tests/blender-constraints.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
diff --git a/tests/cloth-blender.test.js b/tests/cloth-blender.test.js
index 77a1c849..552cecce 100644
--- a/tests/cloth-blender.test.js
+++ b/tests/cloth-blender.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
diff --git a/tests/cloth.test.js b/tests/cloth.test.js
index 1ed431b1..e8d8ccb1 100644
--- a/tests/cloth.test.js
+++ b/tests/cloth.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createAgentScene, agentSceneModulesNeeded } from '../src/agent-scene.js';
diff --git a/tests/curve-text.test.js b/tests/curve-text.test.js
index 82dff3b4..a31c678a 100644
--- a/tests/curve-text.test.js
+++ b/tests/curve-text.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { createAgentScene, agentSceneModulesNeeded, AGENT_SCENE_CAPABILITIES } from '../src/agent-scene.js';
diff --git a/tests/film-timeline.test.js b/tests/film-timeline.test.js
index 13a82c32..e6bb6ab5 100644
--- a/tests/film-timeline.test.js
+++ b/tests/film-timeline.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises';
diff --git a/tests/kernel-offload.test.js b/tests/kernel-offload.test.js
index 491e2b14..7723b3ef 100644
--- a/tests/kernel-offload.test.js
+++ b/tests/kernel-offload.test.js
@@ -5,6 +5,7 @@ import { createAgentScene } from '../src/agent-scene.js';
import { buildWithKernels, kernelKey, runKernel } from '../src/kernel-offload.js';
import { answerKernelRequest } from '../src/kernel-registry.js';
import { createInProcessWorker, kernelRoom, sceneDigest } from './support/kernel-offload-fixture.mjs';
+import './support/load-agent-scene-modules.mjs';
const BUILD_SCRIPT = new URL('./support/kernel-offload-build.mjs', import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1');
const LOADER = new URL('./support/load-agent-scene-modules.mjs', import.meta.url).href;
diff --git a/tests/material-graph.test.js b/tests/material-graph.test.js
index 71ffcf03..3200cc1d 100644
--- a/tests/material-graph.test.js
+++ b/tests/material-graph.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import test from 'node:test';
diff --git a/tests/material-layers.test.js b/tests/material-layers.test.js
index 9714d938..5eea850d 100644
--- a/tests/material-layers.test.js
+++ b/tests/material-layers.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { mat4 } from 'gl-matrix';
diff --git a/tests/material-patterns.test.js b/tests/material-patterns.test.js
index 658556ed..f77324b0 100644
--- a/tests/material-patterns.test.js
+++ b/tests/material-patterns.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { bakeMaterialPattern, cellularNoise, fractalNoise, gradientNoise, materialPatternTextures, normalizeMaterialPattern, PATTERN_DEFAULTS, ridgedNoise } from '../src/material-patterns.js';
diff --git a/tests/mcp-tools.test.js b/tests/mcp-tools.test.js
index b7df556b..0865900f 100644
--- a/tests/mcp-tools.test.js
+++ b/tests/mcp-tools.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
diff --git a/tests/mesh-bevel.test.js b/tests/mesh-bevel.test.js
index 9a904be8..f3299fc1 100644
--- a/tests/mesh-bevel.test.js
+++ b/tests/mesh-bevel.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import { GEOMETRY_PROBLEMS } from '../src/mesh-lint.js';
import assert from 'node:assert/strict';
import test from 'node:test';
diff --git a/tests/mesh-boolean.test.js b/tests/mesh-boolean.test.js
index 1eda1bb0..83a8c9da 100644
--- a/tests/mesh-boolean.test.js
+++ b/tests/mesh-boolean.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import { GEOMETRY_PROBLEMS } from '../src/mesh-lint.js';
import assert from 'node:assert/strict';
import test from 'node:test';
diff --git a/tests/mesh-edit.test.js b/tests/mesh-edit.test.js
index b1652b36..8681d11f 100644
--- a/tests/mesh-edit.test.js
+++ b/tests/mesh-edit.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { box, sphere, cylinder } from '../src/geometry.js';
diff --git a/tests/mesh-fields.test.js b/tests/mesh-fields.test.js
index 971ad0a7..f05df4c1 100644
--- a/tests/mesh-fields.test.js
+++ b/tests/mesh-fields.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
diff --git a/tests/mesh-loopcut.test.js b/tests/mesh-loopcut.test.js
index a688048e..2c6a6472 100644
--- a/tests/mesh-loopcut.test.js
+++ b/tests/mesh-loopcut.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { box, cylinder } from '../src/geometry.js';
diff --git a/tests/mesh-stack.test.js b/tests/mesh-stack.test.js
index a5ae222b..2839212b 100644
--- a/tests/mesh-stack.test.js
+++ b/tests/mesh-stack.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { box, sphere } from '../src/geometry.js';
diff --git a/tests/mesh-uv.test.js b/tests/mesh-uv.test.js
index fc5a2fdf..ce20e1ea 100644
--- a/tests/mesh-uv.test.js
+++ b/tests/mesh-uv.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { box, cylinder, sphere, torus } from '../src/geometry.js';
diff --git a/tests/part-relations.test.js b/tests/part-relations.test.js
index afbf993d..240689ff 100644
--- a/tests/part-relations.test.js
+++ b/tests/part-relations.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { createAgentScene } from '../src/agent-scene.js';
diff --git a/tests/particles.test.js b/tests/particles.test.js
index ddf23ffb..b017a964 100644
--- a/tests/particles.test.js
+++ b/tests/particles.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createAgentScene, agentSceneModulesNeeded } from '../src/agent-scene.js';
diff --git a/tests/rigging.test.js b/tests/rigging.test.js
index 4ff3e73b..98453aa8 100644
--- a/tests/rigging.test.js
+++ b/tests/rigging.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import assert from 'node:assert/strict';
import test from 'node:test';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
diff --git a/tests/skill-mesh-recipes.test.js b/tests/skill-mesh-recipes.test.js
index f8d8cff4..74336fd9 100644
--- a/tests/skill-mesh-recipes.test.js
+++ b/tests/skill-mesh-recipes.test.js
@@ -1,3 +1,4 @@
+import './support/load-agent-scene-modules.mjs';
import { GEOMETRY_PROBLEMS } from '../src/mesh-lint.js';
import assert from 'node:assert/strict';
import test from 'node:test';