Skip to content

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.

fix(verify): reunite the cooked and hot-update checks with their fixtures

esenginecd7902c92f9b
diff --git a/.gitignore b/.gitignore
index 1e11e7671..1ff2a3a20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,10 +60,10 @@ compile_commands.json
*.exe
# Cooked-build render-verify artifacts (regenerated by verify:render:cooked)
-desktop/.cooked-verify/
-desktop/.cooked-src/
+pipeline/.cooked-verify/
+pipeline/.cooked-src/
# Hot-update render-verify artifacts (regenerated by verify:render:hotupdate)
-desktop/.hotupdate-verify/
+pipeline/.hotupdate-verify/
# Emscripten output
*.wasm
diff --git a/desktop b/desktop
index dc4c8e208..42824edd5 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit dc4c8e20815b894755fa6b4dac8006b761fed93f
+Subproject commit 42824edd59cb93fb3ca9010fd6c030b7fad20506
diff --git a/package.json b/package.json
index fffc5cccd..50008620e 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,9 @@
"gate": "node tools/check-release-gate.mjs --report",
"render-host": "node tools/render-host/build.mjs",
"verify:render": "node tools/verify-render.mjs",
- "test": "vitest run --config vitest.engine.config.ts"
+ "test": "vitest run --config vitest.engine.config.ts",
+ "verify:cooked": "ESTELLA_COOK_FIXTURE=1 pnpm --filter @estella/pipeline exec vitest run tests/cooked-verify-fixture.test.ts && pnpm exec electron tools/launchers/headless-cooked-verify.mjs",
+ "verify:hotupdate": "ESTELLA_HOTUPDATE_FIXTURE=1 pnpm --filter @estella/pipeline exec vitest run tests/hotupdate-verify-fixture.test.ts && pnpm exec electron tools/launchers/headless-hotupdate-verify.mjs"
},
"dependencies": {
"chalk": "^5.3.0",
diff --git a/pipeline/tests/cooked-verify-fixture.test.ts b/pipeline/tests/cooked-verify-fixture.test.ts
index fa5794a23..ddfc1c8a6 100644
--- a/pipeline/tests/cooked-verify-fixture.test.ts
+++ b/pipeline/tests/cooked-verify-fixture.test.ts
@@ -47,7 +47,7 @@ describe.skipIf(!process.env.ESTELLA_COOK_FIXTURE)('cooked-verify fixture', () =
rmSync(OUT, { recursive: true, force: true });
mkdirSync(path.join(SRC, 'assets'), { recursive: true });
- copyFileSync(path.resolve(HERE, '..', 'public', 'scenes', 'ktx2-test', 'green.ktx2'),
+ copyFileSync(path.resolve(HERE, '..', '..', 'fixtures', 'scenes', 'ktx2-test', 'green.ktx2'),
path.join(SRC, 'assets', 'green.ktx2'));
writeFileSync(path.join(SRC, 'assets', 'green.ktx2.meta'), meta(TEX, 'texture'));
writeFileSync(path.join(SRC, 'assets', 'tint.esshader'), TINT_SHADER);
diff --git a/tools/launchers/headless-cooked-verify.mjs b/tools/launchers/headless-cooked-verify.mjs
new file mode 100644
index 000000000..e59c64b22
--- /dev/null
+++ b/tools/launchers/headless-cooked-verify.mjs
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Render-verifies a COOKED game build (the shipped runtime path), unlike
+ * headless-verify.mjs which drives the editor host. Static-serves the
+ * cooked build in .cooked-verify/ (produced by the cooked-verify fixture
+ * test), opens it in a show:false window with ?headless, waits for the
+ * gameHost capture hook, and asserts the content-addressed KTX2 sprite
+ * rendered green — proving runtimeLoader transcodes + uploads + draws KTX2
+ * and resolves content-addressed asset paths.
+ */
+import { app, BrowserWindow } from 'electron';
+import http from 'node:http';
+import { readFile } from 'node:fs/promises';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { onRendererConsole } from '../lib/rendererConsole.mjs';
+
+const COOKED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'pipeline', '.cooked-verify');
+const W = 256, H = 256;
+
+app.commandLine.appendSwitch('enable-unsafe-swiftshader');
+process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
+
+const MIME = {
+ '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
+ '.css': 'text/css', '.json': 'application/json', '.esscene': 'application/json',
+ '.wasm': 'application/wasm', '.ktx2': 'application/octet-stream', '.png': 'image/png',
+};
+
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+
+function serve(dir) {
+ const server = http.createServer(async (req, res) => {
+ try {
+ const rel = decodeURIComponent(new URL(req.url, 'http://x').pathname).replace(/^\/+/, '') || 'index.html';
+ const abs = path.join(dir, rel);
+ if (!abs.startsWith(dir)) { res.writeHead(403).end(); return; }
+ const bytes = await readFile(abs);
+ res.writeHead(200, { 'content-type': MIME[path.extname(abs).toLowerCase()] ?? 'application/octet-stream' });
+ res.end(bytes);
+ } catch { res.writeHead(404).end('not found'); }
+ });
+ return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)));
+}
+
+app.whenReady().then(async () => {
+ let server;
+ let failed = true;
+ const diag = [];
+ try {
+ server = await serve(COOKED);
+ const url = `http://127.0.0.1:${server.address().port}/index.html?headless=1`;
+ const win = new BrowserWindow({ show: false, width: W, height: H, webPreferences: { offscreen: false } });
+ onRendererConsole(win.webContents, (m) => {
+ if (/error|fail|unwind|exception|webgl|basis|ktx/i.test(m)) diag.push(m.slice(0, 200));
+ });
+ await win.loadURL(url);
+
+ const exec = (code) => win.webContents.executeJavaScript(code, true);
+ // Boot is async (wasm + scene load); poll for the capture hook, then let it render.
+ let ready = false;
+ for (let i = 0; i < 150 && !ready; i++) { ready = await exec('!!window.__estellaCooked').catch(() => false); if (!ready) await sleep(100); }
+ if (!ready) throw new Error('gameHost capture hook never appeared (boot failed?)');
+ await sleep(1000);
+
+ const cap = await exec(`(() => {
+ const c = window.__estellaCooked.capture();
+ const { width: w, height: h, rgba } = c;
+ const at = (x, y) => { const X = Math.round(x*(w-1)); const Y = (h-1)-Math.round(y*(h-1)); const i=(Y*w+X)*4; return [rgba[i], rgba[i+1], rgba[i+2]]; };
+ return { w, h, left: at(0.3, 0.5), right: at(0.7, 0.5), corner: at(0.04, 0.04) };
+ })()`);
+
+ // Left quad = the KTX2 texture (green); right quad = the PATH-referenced
+ // material chain (its shader paints u_tint red) — proving the cooked
+ // logical→staged resolution end to end, not just uuid refs.
+ const [lr, lg, lb] = cap.left;
+ const greenOk = Math.abs(lg - 180) <= 70 && lr <= 70 && lb <= 70;
+ const [rr, rg, rb] = cap.right;
+ const redOk = rr >= 180 && rg <= 70 && rb <= 70;
+ const cornerBlack = cap.corner[0] <= 40 && cap.corner[1] <= 40 && cap.corner[2] <= 40;
+ const ok = greenOk && redOk && cornerBlack;
+ console.log(`\n[verify:render:cooked] ${ok ? 'PASS' : 'FAIL'}`);
+ console.log('DRIVE_RESULT ' + JSON.stringify({ ...cap, greenOk, redOk, cornerBlack, diag: diag.slice(0, 6) }));
+ failed = !ok;
+ } catch (e) {
+ console.log('\n[verify:render:cooked] FAIL — ' + (e?.message ?? e));
+ console.log('DRIVE_RESULT ' + JSON.stringify({ error: String(e?.message ?? e), diag: diag.slice(0, 6) }));
+ failed = true;
+ } finally {
+ try { server?.close(); } catch { /* ignore */ }
+ // app.exit, not process.exitCode + app.quit: Electron quits with status 0
+ // whatever exitCode says, so a FAIL would be reported to the caller as a pass.
+ app.exit(failed ? 1 : 0);
+ }
+});
diff --git a/tools/launchers/headless-hotupdate-verify.mjs b/tools/launchers/headless-hotupdate-verify.mjs
new file mode 100644
index 000000000..e53ec3d69
--- /dev/null
+++ b/tools/launchers/headless-hotupdate-verify.mjs
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Render-verifies a HOT UPDATE end-to-end against the shipped runtime.
+ * One loopback origin serves the shipped `build/` at `/` and the `cdn/`
+ * update under `/cdn/` (same origin, so the cooked build's CSP allows the
+ * update fetch — a different port would be a different origin and blocked).
+ * Boots the shipped game headless, asserts it renders GREEN (fetched from
+ * the `remote` group), drives `__estellaCooked.applyRemoteUpdate(...)`, and
+ * asserts the SAME running game now renders RED — proving a changed
+ * `remote` asset reaches the client from the CDN with no re-ship.
+ * Then drives two updates that MUST be refused whole (a manifest whose
+ * hash the bytes do not match, and one naming an asset that is not
+ * there) and asserts the game is still red — an update either lands or
+ * leaves the player where they were.
+ */
+import { app, BrowserWindow } from 'electron';
+import http from 'node:http';
+import { readFile } from 'node:fs/promises';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { onRendererConsole } from '../lib/rendererConsole.mjs';
+
+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'pipeline', '.hotupdate-verify');
+const BUILD = path.join(ROOT, 'build');
+const CDN = path.join(ROOT, 'cdn');
+const W = 256, H = 256;
+
+app.commandLine.appendSwitch('enable-unsafe-swiftshader');
+process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
+
+const MIME = {
+ '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',
+ '.css': 'text/css', '.json': 'application/json', '.esscene': 'application/json',
+ '.wasm': 'application/wasm', '.ktx2': 'application/octet-stream', '.png': 'image/png',
+};
+
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+
+/** A hash no file has, so a manifest carrying it is lying about its bytes. */
+const BOGUS_HASH = 'ffffffffffffffff';
+
+/**
+ * The two manifests a good client must refuse, built from the SHIPPED one so the
+ * asset they point at is the GREEN art: an update that half-applies is then
+ * visible as the game going back to green, which a red-to-red comparison could
+ * never show. Keyed by the url prefix each is served under.
+ */
+function brokenManifests(buildManifestJson) {
+ const artOf = (m) => {
+ const assets = m.groups?.cdn?.assets ?? {};
+ const key = Object.keys(assets)[0];
+ if (!key) throw new Error('the shipped manifest has no cdn group to break');
+ return assets[key];
+ };
+ const tampered = JSON.parse(buildManifestJson);
+ artOf(tampered).contentHash = BOGUS_HASH;
+
+ const gone = JSON.parse(buildManifestJson);
+ const missing = artOf(gone);
+ missing.contentHash = BOGUS_HASH;
+ missing.path = `remote/cdn/assets/${BOGUS_HASH}.png`;
+
+ return { tampered: JSON.stringify(tampered), gone: JSON.stringify(gone) };
+}
+
+/** One origin: `/cdn/...` serves the update build, `/tampered/` and `/gone/` the
+ * ship build under a manifest that lies, everything else the ship build. */
+function serve(buildDir, cdnDir, broken) {
+ const server = http.createServer(async (req, res) => {
+ try {
+ let rel = decodeURIComponent(new URL(req.url, 'http://x').pathname).replace(/^\/+/, '');
+ let dir = buildDir;
+ for (const [name, root] of [['cdn', cdnDir], ['tampered', buildDir], ['gone', buildDir]]) {
+ if (rel !== name && !rel.startsWith(`${name}/`)) continue;
+ dir = root;
+ rel = rel.slice(name.length + 1);
+ if (broken[name] && rel === 'asset-manifest.json') {
+ res.writeHead(200, { 'content-type': 'application/json' }).end(broken[name]);
+ return;
+ }
+ break;
+ }
+ rel = rel || 'index.html';
+ const abs = path.join(dir, rel);
+ if (!abs.startsWith(dir)) { res.writeHead(403).end(); return; }
+ const bytes = await readFile(abs);
+ res.writeHead(200, { 'content-type': MIME[path.extname(abs).toLowerCase()] ?? 'application/octet-stream' });
+ res.end(bytes);
+ } catch { res.writeHead(404).end('not found'); }
+ });
+ return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)));
+}
+
+app.whenReady().then(async () => {
+ let server;
+ const diag = [];
+ let before = null, after = null, changed = 0;
+ let failed = true;
+ const refused = [];
+ try {
+ const broken = brokenManifests(await readFile(path.join(BUILD, 'asset-manifest.json'), 'utf8'));
+ server = await serve(BUILD, CDN, broken);
+ const base = `http://127.0.0.1:${server.address().port}`;
+
+ const win = new BrowserWindow({ show: false, width: W, height: H, webPreferences: { offscreen: false } });
+ onRendererConsole(win.webContents, (m) => {
+ if (/error|fail|unwind|exception|webgl|update|group|manifest/i.test(m)) diag.push(m.slice(0, 200));
+ });
+ await win.loadURL(`${base}/index.html?headless=1`);
+
+ const exec = (code) => win.webContents.executeJavaScript(code, true);
+ let ready = false;
+ for (let i = 0; i < 150 && !ready; i++) { ready = await exec('!!window.__estellaCooked').catch(() => false); if (!ready) await sleep(100); }
+ if (!ready) throw new Error('gameHost capture hook never appeared (boot failed?)');
+ await sleep(1800); // demo system fetches the cdn group + stamps the texture
+
+ const center = `(() => { const c = window.__estellaCooked.capture(); const { width: w, height: h, rgba } = c; const i = (((h >> 1) * w) + (w >> 1)) * 4; return [rgba[i], rgba[i + 1], rgba[i + 2]]; })()`;
+ before = await exec(center);
+
+ const upd = await exec(`window.__estellaCooked.applyRemoteUpdate(${JSON.stringify(`${base}/cdn/asset-manifest.json`)}, ${JSON.stringify(`${base}/cdn`)})`);
+ changed = upd && typeof upd.changed === 'number' ? upd.changed : 0;
+ await sleep(1800);
+ after = await exec(center);
+
+ const isGreen = ([r, g, b]) => g >= 130 && r <= 110 && b <= 120;
+ const isRed = ([r, g, b]) => r >= 150 && g <= 100 && b <= 100;
+
+ // A broken update must leave the player exactly where they were. Both of
+ // these are SEEN as an update (changed >= 1) and point at the green art, so
+ // "nothing happened because nothing was offered" cannot pass for a rollback.
+ for (const name of ['tampered', 'gone']) {
+ const r = await exec(`window.__estellaCooked.applyRemoteUpdate(`
+ + `${JSON.stringify(`${base}/${name}/asset-manifest.json`)}, ${JSON.stringify(`${base}/${name}`)})`);
+ await sleep(1200);
+ const pixel = await exec(center);
+ refused.push({
+ name,
+ offered: r?.changed ?? 0,
+ applied: !!r?.applied,
+ failed: r?.failed ?? 0,
+ pixel,
+ ok: (r?.changed ?? 0) >= 1 && !r?.applied && (r?.failed ?? 0) >= 1 && isRed(pixel),
+ });
+ }
+
+ const ok = isGreen(before) && isRed(after) && changed >= 1 && refused.every((r) => r.ok);
+
+ console.log(`\n[verify:render:hotupdate] ${ok ? 'PASS' : 'FAIL'}`);
+ console.log('DRIVE_RESULT ' + JSON.stringify({ before, after, changed, greenBefore: isGreen(before), redAfter: isRed(after), refused, diag: diag.slice(0, 8) }));
+ failed = !ok;
+ } catch (e) {
+ console.log('\n[verify:render:hotupdate] FAIL — ' + (e?.message ?? e));
+ console.log('DRIVE_RESULT ' + JSON.stringify({ error: String(e?.message ?? e), before, after, changed, refused, diag: diag.slice(0, 8) }));
+ failed = true;
+ } finally {
+ try { server?.close(); } catch { /* ignore */ }
+ // app.exit, not process.exitCode + app.quit: Electron quits with status 0
+ // whatever exitCode says, so a FAIL would be reported to the caller as a pass.
+ app.exit(failed ? 1 : 0);
+ }
+});
diff --git a/tools/releaseGate.mjs b/tools/releaseGate.mjs
index 158916b63..c59ea137d 100644
--- a/tools/releaseGate.mjs
+++ b/tools/releaseGate.mjs
@@ -85,7 +85,7 @@ export const CRITERIA = [
// manifests that lie, and reads the pixel after each.
answeredBy: 'pnpm --filter @estella/editor run verify:render:hotupdate',
needs: [
- 'desktop/scripts/headless-hotupdate-verify.mjs',
+ 'tools/launchers/headless-hotupdate-verify.mjs',
'pipeline/tests/hotupdate-verify-fixture.test.ts',
],
},