Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Give the vegetation pop test a free port instead of fixed 5187

Nguyen Xuan An13f4ea4a28a1
diff --git a/tests/vegetation-pop.test.js b/tests/vegetation-pop.test.js
index 9c864510..9cafc426 100644
--- a/tests/vegetation-pop.test.js
+++ b/tests/vegetation-pop.test.js
@@ -4,16 +4,29 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
+import { createServer } from 'node:net';
// A pop is a single-frame change of the mean RGB value (0 to 1) above this, or above this share of the change a hard switch
// makes in one frame. Measured 2026-11-04 on SwiftShader: the fade's largest step is 0.083, a hard switch is 0.30, and plain
// camera motion over the same dolly changes a frame by 0.006 on average and 0.010 at most.
const POP_THRESHOLD = 0.1;
const HARD_SWITCH_RATIO = 0.4;
-const PORT = 5187;
+
+// A fixed port collided with other test runs and dev servers on the same machine, so the server takes a port the system hands out.
+async function findFreePort() {
+ const probe = createServer();
+ await new Promise((resolve, reject) => {
+ probe.once('error', reject);
+ probe.listen(0, '127.0.0.1', resolve);
+ });
+ const { port } = probe.address();
+ await new Promise(resolve => probe.close(resolve));
+ return port;
+}
async function startServer() {
- const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', String(PORT), '--strictPort'], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
+ const port = await findFreePort();
+ const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', String(port), '--strictPort'], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error('The dev server did not start.')), 30000);
server.stdout.on('data', (data) => {
@@ -27,7 +40,7 @@ async function startServer() {
reject(new Error(`The dev server exited ${code}.`));
});
});
- return server;
+ return { server, port };
}
async function evaluateWithRetry(page, task, argument) {
@@ -91,7 +104,7 @@ test('a slow dolly across the impostor boundary shows no pop in a frame differen
context.skip('playwright is not installed');
return;
}
- const server = await startServer();
+ const { server, port } = await startServer();
let browser;
try {
try {
@@ -101,7 +114,7 @@ test('a slow dolly across the impostor boundary shows no pop in a frame differen
return;
}
const page = await browser.newPage({ viewport: { width: 320, height: 180 } });
- await page.goto(`http://127.0.0.1:${PORT}/`);
+ await page.goto(`http://127.0.0.1:${port}/`);
// One tree fills the view. With the switch distances scaled by 0.05 its card begins at 7.5 m, so the dolly from 6 to 9.5 m crosses the whole fade band.
const crossing = { start: 6, end: 9.5, steps: 40, fade: 0.06, distanceScale: 0.05 };
const withFade = await frameChanges(page, crossing);