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.

test(assets): render-verify a cooked build — shipped runtime resolves content-addressed KTX2

yhh65791bc03bdb
diff --git a/.gitignore b/.gitignore
index a050df9e8..7271ffe34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,10 @@ compile_commands.json
*.dylib
*.exe
+# Cooked-build render-verify artifacts (regenerated by verify:render:cooked)
+desktop/.cooked-verify/
+desktop/.cooked-src/
+
# Emscripten output
*.wasm
*.js.mem
diff --git a/desktop/package.json b/desktop/package.json
index d1c92019f..28216b463 100644
--- a/desktop/package.json
+++ b/desktop/package.json
@@ -26,6 +26,7 @@
"verify:render:tilemap:transform": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-transform.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-transform.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.40,\\\"y\\\":0.36,\\\"rgb\\\":[255,255,0]},{\\\"x\\\":0.60,\\\"y\\\":0.36,\\\"rgb\\\":[0,255,0]},{\\\"x\\\":0.40,\\\"y\\\":0.58,\\\"rgb\\\":[0,0,255]},{\\\"x\\\":0.60,\\\"y\\\":0.58,\\\"rgb\\\":[255,0,0]}]\" electron scripts/headless-verify.mjs",
"verify:render:material": "vite build && ESTELLA_VERIFY_SCENE=/scenes/mat-tint.esscene ESTELLA_VERIFY_MANIFEST=/scenes/mat-tint.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs",
"verify:render:ktx2": "vite build && ESTELLA_VERIFY_SCENE=/scenes/ktx2-sprite.esscene ESTELLA_VERIFY_MANIFEST=/scenes/ktx2-sprite.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,180,0],\\\"tol\\\":50}]\" electron scripts/headless-verify.mjs",
+ "verify:render:cooked": "vite build && ESTELLA_COOK_FIXTURE=1 vitest run tests/cooked-verify-fixture.test.ts && electron scripts/headless-cooked-verify.mjs",
"verify:render:material:instance": "vite build && ESTELLA_VERIFY_SCENE=/scenes/mat-instance.esscene ESTELLA_VERIFY_MANIFEST=/scenes/mat-instance.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,255,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs",
"verify:render:material:texture": "vite build && ESTELLA_VERIFY_SCENE=/scenes/mat-tex.esscene ESTELLA_VERIFY_MANIFEST=/scenes/mat-tex.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,255,0],\\\"tol\\\":50}]\" electron scripts/headless-verify.mjs",
"verify:render:material:switch": "vite build && ESTELLA_VERIFY_SCENE=/scenes/mat-sw.esscene ESTELLA_VERIFY_MANIFEST=/scenes/mat-sw.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.25,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":50},{\\\"x\\\":0.75,\\\"y\\\":0.5,\\\"rgb\\\":[0,255,0],\\\"tol\\\":50}]\" electron scripts/headless-verify.mjs",
diff --git a/desktop/scripts/headless-cooked-verify.mjs b/desktop/scripts/headless-cooked-verify.mjs
new file mode 100644
index 000000000..b59bdda98
--- /dev/null
+++ b/desktop/scripts/headless-cooked-verify.mjs
@@ -0,0 +1,88 @@
+// 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';
+
+const COOKED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '.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;
+ 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 } });
+ win.webContents.on('console-message', (...a) => {
+ const m = a.map((x) => (x && typeof x === 'object' ? x.message ?? '' : String(x))).join(' ');
+ 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, center: at(0.5, 0.5), corner: at(0.04, 0.04) };
+ })()`);
+
+ const [cr, cg, cb] = cap.center;
+ const greenOk = Math.abs(cg - 180) <= 70 && cr <= 70 && cb <= 70;
+ const cornerBlack = cap.corner[0] <= 40 && cap.corner[1] <= 40 && cap.corner[2] <= 40;
+ const ok = greenOk && cornerBlack;
+ console.log(`\n[verify:render:cooked] ${ok ? 'PASS' : 'FAIL'}`);
+ console.log('DRIVE_RESULT ' + JSON.stringify({ ...cap, greenOk, cornerBlack, diag: diag.slice(0, 6) }));
+ process.exitCode = ok ? 0 : 1;
+ } 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) }));
+ process.exitCode = 1;
+ } finally {
+ try { server?.close(); } catch { /* ignore */ }
+ app.quit();
+ }
+});
diff --git a/desktop/src/gameHost.ts b/desktop/src/gameHost.ts
index 9156fd268..d1be47327 100644
--- a/desktop/src/gameHost.ts
+++ b/desktop/src/gameHost.ts
@@ -23,6 +23,11 @@ interface CookedManifest {
async function boot(): Promise<void> {
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
+ // Render-verification hook: with ?headless the cooked build keeps its drawing
+ // buffer + exposes a framebuffer readback, so a driver can prove the SHIPPED
+ // runtime actually rendered the cooked scene (the editor host can't — it uses a
+ // different asset path).
+ const headless = new URLSearchParams(location.search).has('headless');
const resize = () => {
const dpr = window.devicePixelRatio || 1;
canvas.width = Math.max(1, Math.floor(window.innerWidth * dpr));
@@ -62,6 +67,7 @@ async function boot(): Promise<void> {
depth: true,
stencil: true,
premultipliedAlpha: false,
+ preserveDrawingBuffer: headless,
}) as WebGL2RenderingContext | null;
if (!gl) throw new Error('WebGL2 is not available.');
const glHandle = module.GL.registerContext(gl, { majorVersion: 2, minorVersion: 0, enableExtensionsByDefault: true });
@@ -73,6 +79,16 @@ async function boot(): Promise<void> {
});
setEditorMode(false);
setPlayMode(true);
+ if (headless) {
+ (window as unknown as { __estellaCooked?: unknown }).__estellaCooked = {
+ capture(): { width: number; height: number; rgba: Uint8Array } {
+ const w = canvas.width, h = canvas.height;
+ const rgba = new Uint8Array(w * h * 4);
+ gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, rgba);
+ return { width: w, height: h, rgba };
+ },
+ };
+ }
// physics.wasm sits next to esengine.wasm; the runtime loads it when the scene
// uses physics. (Runtime-spawned bodies still need a build-time enable flag —
// a follow-up that cooks features.physics into game.config.json.)
diff --git a/desktop/tests/cooked-verify-fixture.test.ts b/desktop/tests/cooked-verify-fixture.test.ts
new file mode 100644
index 000000000..7c3e56860
--- /dev/null
+++ b/desktop/tests/cooked-verify-fixture.test.ts
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Produces the cooked build that headless-cooked-verify.mjs renders — a
+ * content-addressed web export of a green-KTX2 sprite scene, built with the
+ * real SDK dist + engine/basis wasm. Guarded by ESTELLA_COOK_FIXTURE so it's
+ * not part of the normal unit suite; the verify:render:cooked script sets it.
+ */
+import { describe, it, expect } from 'vitest';
+import { mkdirSync, writeFileSync, copyFileSync, rmSync } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { exportGame } from '../electron/exportGame';
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const OUT = path.resolve(HERE, '..', '.cooked-verify');
+const SRC = path.resolve(HERE, '..', '.cooked-src');
+const TEX = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
+const SCN = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';
+const meta = (uuid: string, type: string) => JSON.stringify({ uuid, version: '2.0', type, importer: {} });
+
+describe.skipIf(!process.env.ESTELLA_COOK_FIXTURE)('cooked-verify fixture', () => {
+ it('cooks a content-addressed build of a green KTX2 sprite', async () => {
+ rmSync(SRC, { recursive: true, force: true });
+ rmSync(OUT, { recursive: true, force: true });
+
+ mkdirSync(path.join(SRC, 'assets'), { recursive: true });
+ copyFileSync(path.resolve(HERE, '..', 'public', 'scenes', 'ktx2-test', 'green.ktx2'),
+ path.join(SRC, 'assets', 'green.ktx2'));
+ writeFileSync(path.join(SRC, 'assets', 'green.ktx2.meta'), meta(TEX, 'texture'));
+
+ mkdirSync(path.join(SRC, 'scenes'), { recursive: true });
+ writeFileSync(path.join(SRC, 'scenes', 'main.esscene'), JSON.stringify({
+ version: '1.0', name: 'Main', entities: [
+ { id: 0, name: 'Camera', parent: null, children: [], visible: true, components: [
+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 10 } } },
+ { type: 'Camera', data: { projectionType: 1, orthoSize: 300, isActive: true, priority: 0 } },
+ ] },
+ { id: 1, name: 'Quad', parent: null, children: [], visible: true, components: [
+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } },
+ { type: 'Sprite', data: { size: { x: 200, y: 200 }, color: { r: 1, g: 1, b: 1, a: 1 }, texture: `@uuid:${TEX}` } },
+ ] },
+ ],
+ }));
+ writeFileSync(path.join(SRC, 'scenes', 'main.esscene.meta'), meta(SCN, 'scene'));
+
+ mkdirSync(path.join(SRC, 'src'), { recursive: true });
+ writeFileSync(path.join(SRC, 'src', 'main.ts'), 'export {};\n');
+
+ const res = await exportGame({
+ root: SRC,
+ entryScene: 'scenes/main.esscene',
+ gameHostEntry: path.resolve(HERE, '..', 'src', 'gameHost.ts'),
+ scriptsEntry: 'src/main.ts',
+ sdkDistDir: path.resolve(HERE, '..', '..', 'sdk', 'dist'),
+ wasmDir: path.resolve(HERE, '..', '..', 'build', 'wasm', 'web'),
+ outDir: OUT,
+ title: 'Cooked Verify',
+ contentAddressed: true,
+ });
+ expect(res.ok, res.errors.join('; ')).toBe(true);
+ }, 120_000);
+});