A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(gates): three verdicts about the machine, delivered as verdicts about the code
yhhfb25188240d1
diff --git a/pipeline/tests/asset-symlink-escape.test.ts b/pipeline/tests/asset-symlink-escape.test.tsindex fc85f32f8..b594cc343 100644--- a/pipeline/tests/asset-symlink-escape.test.ts+++ b/pipeline/tests/asset-symlink-escape.test.ts@@ -28,6 +28,29 @@ function linkDir(target: string, at: string): void {symlinkSync(target, at, process.platform === 'win32' ? 'junction' : 'dir');}+/** Can this machine make a plain file symlink at all? Probed rather than read off+ * `process.platform`: Windows refuses one without Developer Mode or elevation, and+ * the same Windows with Developer Mode on can make it. */+function canSymlinkFiles(): boolean {+ const dir = mkdtempSync(path.join(tmpdir(), 'estella-linkprobe-'));+ try {+ const target = path.join(dir, 'target');+ writeFileSync(target, 'probe');+ symlinkSync(target, path.join(dir, 'link'));+ return true;+ } catch {+ return false;+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+}++/** The three cases below need a file symlink to EXIST before they can assert it is+ * refused; without the privilege they redden on the fixture, saying nothing about+ * the cook. Skipping is not passing, so CI runs them whatever the probe says — a+ * runner that quietly loses the privilege goes red, not green. */+const RUN_FILE_LINK_TESTS = Boolean(process.env.CI) || canSymlinkFiles();+interface Fixture { base: string; root: string; outsideFile: string }function makeProject(): Fixture {@@ -63,7 +86,7 @@ function writeScene(root: string, texUuid: string): string {}describe('a link out of the project reaches neither the index nor the build', () => {- it('a linked content file is not indexed, with or without a sidecar', async () => {+ it.skipIf(!RUN_FILE_LINK_TESTS)('a linked content file is not indexed, with or without a sidecar', async () => {const { base, root, outsideFile } = makeProject();try {symlinkSync(outsideFile, path.join(root, 'assets', 'textures', 'adopted.png'));@@ -95,7 +118,7 @@ describe('a link out of the project reaches neither the index nor the build', ()}});- it('a scene referencing a linked texture ships without its bytes', async () => {+ it.skipIf(!RUN_FILE_LINK_TESTS)('a scene referencing a linked texture ships without its bytes', async () => {const { base, root, outsideFile } = makeProject();try {const leak = path.join(root, 'assets', 'textures', 'leak.png');@@ -117,7 +140,7 @@ describe('a link out of the project reaches neither the index nor the build', ()}});- it('a link that stays inside the project still works', async () => {+ it.skipIf(!RUN_FILE_LINK_TESTS)('a link that stays inside the project still works', async () => {const { base, root } = makeProject();try {const real = path.join(root, 'assets', 'textures', 'real.png');diff --git a/tools/check-native-build.mjs b/tools/check-native-build.mjsindex 698e612f0..72fd41a34 100644--- a/tools/check-native-build.mjs+++ b/tools/check-native-build.mjs@@ -19,7 +19,7 @@* A machine that has never built native gets a note, not a green light.*/import { spawnSync } from 'node:child_process';-import { existsSync } from 'node:fs';+import { existsSync, readFileSync } from 'node:fs';import path from 'node:path';import { fileURLToPath } from 'node:url';import { DESKTOP_BUILD_DIR } from '../build-tools/tasks/native.js';@@ -40,6 +40,14 @@ if (!existsSync(path.join(buildDir, 'CMakeCache.txt'))) {skip(`no configured native tree (run \`node build-tools/cli.js native --target ${HOST}\` once)`);}+// An MSVC tree builds only from a shell that has run vcvars. Without it CMake+// cannot enable the language and cl cannot find `<cstdint>`, which reads exactly+// like the engine failing to compile off emscripten and is not that.+if (process.platform === 'win32' && !process.env.INCLUDE+ && /^CMAKE_CXX_COMPILER:FILEPATH=.*cl\.exe$/im.test(readFileSync(path.join(buildDir, 'CMakeCache.txt'), 'utf8'))) {+ skip('this shell has no MSVC environment (build from a Developer Command Prompt, or run vcvarsall first)');+}+const run = spawnSync('cmake', ['--build', buildDir, '--target', 'esengine'], { encoding: 'utf8' });const out = `${run.stdout ?? ''}${run.stderr ?? ''}`;if (run.status === 0) {diff --git a/tools/check-physics2d.mjs b/tools/check-physics2d.mjsindex 9518f45b6..04b5f7d9b 100644--- a/tools/check-physics2d.mjs+++ b/tools/check-physics2d.mjs@@ -15,9 +15,10 @@* node tools/check-physics2d.mjs*/import { spawnSync } from 'node:child_process';-import { existsSync, readdirSync, readFileSync } from 'node:fs';+import { readdirSync, readFileSync } from 'node:fs';import path from 'node:path';import { fileURLToPath } from 'node:url';+import { requireCurrentModule } from './moduleBinary.mjs';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');const TESTS = path.join(ROOT, 'sdk', 'tests');@@ -43,19 +44,16 @@ if (orphans.length > 0) {process.exit(1);}-// An unbuilt module is not a failed behaviour. The job that HAS the binary sets-// ESTELLA_REQUIRE_WASM, so a build that stops arriving there fails rather than-// skipping quietly.-if (!existsSync(WASM)) {- if (process.env.ESTELLA_REQUIRE_WASM) {- console.error('check-physics2d: ESTELLA_REQUIRE_WASM is set but build/wasm/web/physics.wasm is absent.\n');- console.error(' node build-tools/cli.js build -t physics');- process.exit(1);- }- console.log('check-physics2d: build/wasm/web/physics.wasm is not built — skipped'- + ' (build it with `node build-tools/cli.js build -t physics`; CI sets ESTELLA_REQUIRE_WASM).');- process.exit(0);-}+// An unbuilt module is not a failed behaviour, and neither is one built before the+// behaviour existed. Both mean no binary answers for this code — see moduleBinary.+requireCurrentModule({+ gate: 'check-physics2d',+ wasm: WASM,+ rel: 'build/wasm/web/physics.wasm',+ sources: [path.join(ROOT, 'src', 'esengine', 'bindings', 'modules', 'physics'),+ ...SMOKES.map((s) => path.join(TESTS, s))],+ build: 'node build-tools/cli.js build -t physics',+});let total = 0;for (const smoke of SMOKES) {diff --git a/tools/check-physics3d.mjs b/tools/check-physics3d.mjsindex ebb144319..537739e3e 100644--- a/tools/check-physics3d.mjs+++ b/tools/check-physics3d.mjs@@ -17,27 +17,23 @@* node tools/check-physics3d.mjs*/import { spawnSync } from 'node:child_process';-import { existsSync } from 'node:fs';import path from 'node:path';import { fileURLToPath } from 'node:url';+import { requireCurrentModule } from './moduleBinary.mjs';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');const SMOKE = path.join(ROOT, 'sdk', 'tests', 'physics3d-smoke.mjs');const WASM = path.join(ROOT, 'build', 'wasm', 'web', 'physics3d.wasm');-// An unbuilt module is not a failed behaviour. The job that HAS the binary sets-// ESTELLA_REQUIRE_WASM, so a build that stops arriving there fails rather than-// skipping quietly.-if (!existsSync(WASM)) {- if (process.env.ESTELLA_REQUIRE_WASM) {- console.error('check-physics3d: ESTELLA_REQUIRE_WASM is set but build/wasm/web/physics3d.wasm is absent.\n');- console.error(' node build-tools/cli.js build -t physics3d');- process.exit(1);- }- console.log('check-physics3d: build/wasm/web/physics3d.wasm is not built — skipped'- + ' (build it with `node build-tools/cli.js build -t physics3d`; CI sets ESTELLA_REQUIRE_WASM).');- process.exit(0);-}+// An unbuilt module is not a failed behaviour, and neither is one built before the+// behaviour existed. Both mean no binary answers for this code — see moduleBinary.+requireCurrentModule({+ gate: 'check-physics3d',+ wasm: WASM,+ rel: 'build/wasm/web/physics3d.wasm',+ sources: [path.join(ROOT, 'src', 'esengine', 'bindings', 'modules', 'physics3d'), SMOKE],+ build: 'node build-tools/cli.js build -t physics3d',+});const run = spawnSync(process.execPath, [SMOKE], { cwd: ROOT, encoding: 'utf8' });if (run.status !== 0) {diff --git a/tools/moduleBinary.mjs b/tools/moduleBinary.mjsnew file mode 100644index 000000000..1195e0fc2--- /dev/null+++ b/tools/moduleBinary.mjs@@ -0,0 +1,60 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file moduleBinary.mjs — is there a binary that answers for THIS code?+ *+ * A side module is built by hand and read by a gate, so the gate can be handed a+ * binary that predates the behaviour it asserts. That happened: `physics3d.wasm`+ * was five days old and the two character-controller cases added with the fix+ * reported the 3D world misbehaving, which was a true statement about a stale+ * binary and a false one about the engine.+ *+ * Missing and stale are the same condition — no binary answers for this code — so+ * they get one policy. Locally: a note and a skip, because building it is a+ * choice. Under ESTELLA_REQUIRE_WASM (the job that HAS the binary): fail, because+ * there a stale answer is worse than none.+ */+import { existsSync, statSync, readdirSync } from 'node:fs';+import path from 'node:path';++/** Newest mtime under a file or directory tree, 0 for a path that is not there. */+function newestMtime(target) {+ if (!existsSync(target)) return 0;+ const st = statSync(target);+ if (!st.isDirectory()) return st.mtimeMs;+ return readdirSync(target, { withFileTypes: true })+ .reduce((newest, e) => Math.max(newest, newestMtime(path.join(target, e.name))), 0);+}++/**+ * Exits the calling gate when no current binary exists; returns otherwise.+ *+ * @param {object} o+ * @param {string} o.gate the gate's own name, for the message+ * @param {string} o.wasm absolute path to the module binary+ * @param {string} o.rel how to spell that path to a reader+ * @param {string[]} o.sources files/dirs it is built from, plus what asserts about it+ * @param {string} o.build the command that rebuilds it+ */+export function requireCurrentModule({ gate, wasm, rel, sources, build }) {+ const required = Boolean(process.env.ESTELLA_REQUIRE_WASM);+ const verdict = (problem) => {+ if (required) {+ console.error(`${gate}: ESTELLA_REQUIRE_WASM is set but ${rel} ${problem}.\n`);+ console.error(` ${build}`);+ process.exit(1);+ }+ console.log(`${gate}: ${rel} ${problem} — skipped (rebuild with \`${build}\`;`+ + ' CI sets ESTELLA_REQUIRE_WASM).');+ process.exit(0);+ };++ if (!existsSync(wasm)) verdict('is not built');++ const built = statSync(wasm).mtimeMs;+ const newest = sources.reduce((n, s) => Math.max(n, newestMtime(s)), 0);+ if (newest > built) {+ const days = Math.round((newest - built) / 86_400_000);+ verdict(`is older than the code it answers for (by ${days > 0 ? `${days}d` : 'under a day'})`);+ }+}