Skip to content

3D engine that AI agents drive

Start the smoke scripts without colour codes from Vite (#2255)

Nguyen Xuan An86ae809d633b
diff --git a/scripts/smoke-film-physics.mjs b/scripts/smoke-film-physics.mjs
index be270f59..6d2b97d9 100644
--- a/scripts/smoke-film-physics.mjs
+++ b/scripts/smoke-film-physics.mjs
@@ -5,14 +5,15 @@ import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
import { constants, setPriority } from 'node:os';
import { chromium } from 'playwright';
+import { viteChildEnvironment, viteOutputMentionsAddress } from './vite-output.mjs';
setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
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' });
+const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', String(PORT), '--strictPort'], { windowsHide: true, stdio: 'pipe', env: viteChildEnvironment() });
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}`)) {
+ if (viteOutputMentionsAddress(bytes, `127.0.0.1:${PORT}`)) {
clearTimeout(timeout);
resolve();
}
diff --git a/scripts/smoke-film-transport.mjs b/scripts/smoke-film-transport.mjs
index b94b0219..03719304 100644
--- a/scripts/smoke-film-transport.mjs
+++ b/scripts/smoke-film-transport.mjs
@@ -3,15 +3,16 @@ import { chromium } from 'playwright';
import { spawn } from 'node:child_process';
import { setPriority, constants } from 'node:os';
import { existsSync } from 'node:fs';
+import { viteChildEnvironment, viteOutputMentionsAddress } from './vite-output.mjs';
setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);
-const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5191', '--strictPort'], { windowsHide:true, stdio:'pipe' });
+const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5191', '--strictPort'], { windowsHide:true, stdio:'pipe', env: viteChildEnvironment() });
let browser;
try {
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error('Transport test server did not start.')), 15000);
server.stdout.on('data', bytes => {
- if (bytes.toString().includes('127.0.0.1:5191')) { clearTimeout(timeout); resolve(); }
+ if (viteOutputMentionsAddress(bytes, '127.0.0.1:5191')) { clearTimeout(timeout); resolve(); }
});
server.on('error', reject);
});
diff --git a/scripts/smoke-scenes.mjs b/scripts/smoke-scenes.mjs
index 02dca8dd..dbb4de00 100644
--- a/scripts/smoke-scenes.mjs
+++ b/scripts/smoke-scenes.mjs
@@ -3,14 +3,15 @@ import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import assert from 'node:assert/strict';
+import { viteChildEnvironment, viteOutputMentionsAddress } from './vite-output.mjs';
-const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5179', '--strictPort'], { windowsHide: true, stdio: 'pipe' });
+const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5179', '--strictPort'], { windowsHide: true, stdio: 'pipe', env: viteChildEnvironment() });
let browser;
try {
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error('Scene smoke server did not start.')), 15000);
server.stdout.on('data', (data) => {
- if (data.toString().includes('127.0.0.1:5179')) { clearTimeout(timeout); resolve(); }
+ if (viteOutputMentionsAddress(data, '127.0.0.1:5179')) { clearTimeout(timeout); resolve(); }
});
server.on('error', reject);
server.on('exit', (code) => { clearTimeout(timeout); reject(new Error(`Scene server exited ${code}.`)); });
diff --git a/scripts/smoke.mjs b/scripts/smoke.mjs
index 9ddd6067..28582e3b 100644
--- a/scripts/smoke.mjs
+++ b/scripts/smoke.mjs
@@ -4,16 +4,17 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
+import { viteChildEnvironment, viteOutputMentionsAddress } from './vite-output.mjs';
const artifactDirectory = new URL('../artifacts/', import.meta.url);
await mkdir(artifactDirectory, { recursive: true });
-const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5178', '--strictPort'], { cwd: new URL('..', import.meta.url), windowsHide: true, stdio: 'pipe' });
+const server = spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1', '--port', '5178', '--strictPort'], { cwd: new URL('..', import.meta.url), windowsHide: true, stdio: 'pipe', env: viteChildEnvironment() });
let browser;
try {
await new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error('Vite did not start.')), 15000);
server.stdout.on('data', (data) => {
- if (data.toString().includes('127.0.0.1:5178')) { clearTimeout(timeout); resolve(); }
+ if (viteOutputMentionsAddress(data, '127.0.0.1:5178')) { clearTimeout(timeout); resolve(); }
});
server.on('error', reject);
server.on('exit', (code) => { clearTimeout(timeout); reject(new Error(`Vite exited ${code}`)); });
diff --git a/scripts/vite-output.mjs b/scripts/vite-output.mjs
new file mode 100644
index 00000000..ccdcd214
--- /dev/null
+++ b/scripts/vite-output.mjs
@@ -0,0 +1,14 @@
+// Helpers for smoke scripts that start Vite as a child process and wait for its "Local: http://127.0.0.1:<port>" line.
+// Vite bolds the port number when colour is forced, which breaks a plain substring match.
+
+const ansiColourCodes = /\u001b\[[0-9;]*m/g;
+
+// Environment for the Vite child: no colour codes, whatever the parent terminal or CI sets.
+export function viteChildEnvironment(baseEnvironment = process.env) {
+ return { ...baseEnvironment, FORCE_COLOR: '0', NO_COLOR: '1' };
+}
+
+// True when a chunk of Vite output names the local server address, with or without colour codes.
+export function viteOutputMentionsAddress(chunk, address) {
+ return chunk.toString().replace(ansiColourCodes, '').includes(address);
+}