3D engine that AI agents drive
Share one free-port helper between the dev-server tests
Nguyen Xuan An173a60ffc817
diff --cc tests/helpers/free-port.jsindex 00000000,00000000..0387157anew file mode 100644--- /dev/null+++ b/tests/helpers/free-port.js@@@ -1,0 -1,0 +1,13 @@@++import { createServer } from 'node:net';++++// A fixed port collides with other test runs and dev servers on the same machine, so tests ask the system for a free one.++export function freePort() {++ return new Promise((resolve, reject) => {++ const probe = createServer();++ probe.once('error', reject);++ probe.listen(0, '127.0.0.1', () => {++ const { port } = probe.address();++ probe.close(() => resolve(port));++ });++ });++}diff --cc tests/light-bake-backends.test.jsindex e74ba22f,e74ba22f..43555cde--- a/tests/light-bake-backends.test.js+++ b/tests/light-bake-backends.test.js@@@ -5,6 -5,6 +5,7 @@@import test from 'node:test';import assert from 'node:assert/strict';import { spawn } from 'node:child_process';++import { freePort } from './helpers/free-port.js';// Measured 2026-11-04 on an RTX 3060, a closed 8 m room with one lamp, 512 samples, 3 bounces: diffuse-only surfaces (ior 1)// gave a GPU to CPU light ratio of 1.0034 on the floor, 1.0014 on the ceiling and 1.008 to 1.011 on the walls (0.6 percent over@@@ -12,10 -12,10 +13,8 @@@// This test's smaller room on SwiftShader (256 samples) gave 1.0046 for diffuse surfaces and 1.0766 for a glossy dielectric.const DIFFUSE_AGREEMENT = 0.01;const SPECULAR_GAP_AT_LEAST = 0.015;--const PORT = 5188;----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'] });++async function startServer(port) {++ 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) => {@@@ -80,7 -80,7 +79,8 @@@ async function withPage(context, run)context.skip('playwright is not installed');return;}-- const server = await startServer();++ const port = await freePort();++ const server = await startServer(port);let browser;try {try {@@@ -91,7 -91,7 +91,7 @@@}const page = await browser.newPage({ viewport: { width: 320, height: 180 } });page.setDefaultTimeout(0);-- await page.goto(`http://127.0.0.1:${PORT}/`);++ await page.goto(`http://127.0.0.1:${port}/`);await run(material => page.evaluate(bakeRoomOnBothBackends, material));} finally {await browser?.close();diff --cc tests/vegetation-pop.test.jsindex 9cafc426,caf36365..0a608f8f--- a/tests/vegetation-pop.test.js+++ b/tests/vegetation-pop.test.js@@@ -4,7 -4,7 +4,7 @@@import test from 'node:test';import assert from 'node:assert/strict';import { spawn } from 'node:child_process';--import { createServer } from 'node:net';++import { freePort } from './helpers/free-port.js';// 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@@@ -12,20 -12,19 +12,7 @@@const POP_THRESHOLD = 0.1;const HARD_SWITCH_RATIO = 0.4;- // 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) => {-// A fixed port collided when several checkouts ran the suite at once, so ask the system for a free one.-function freePort() {- return new Promise((resolve, reject) => {- const probe = createServer();-- probe.once('error', reject);- probe.listen(0, '127.0.0.1', resolve);- probe.listen(0, '127.0.0.1', () => {- const { port } = probe.address();- probe.close(() => resolve(port));- });-- });- const { port } = probe.address();- await new Promise(resolve => probe.close(resolve));- return port;--}--- async function startServer() {- const port = await findFreePort();+ async function startServer(port) {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);