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(test): present golden browser packages on a shared display
yhhc8b0b906553c
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 2241de7bd..ed166ac28 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(test): present golden browser packages on a shared display':+ { internal: 'CI presents ordinary Web and playable packages without taking focus and owns one virtual display for the controller and workers, preventing hidden-page frame throttling while preserving settle deadlines, per-worker timeout shares, minigame launch paths and failure verdicts.' },'perf(ecs): bind live change matchers before entity iteration':{ note: 'Dense change queries bind their live sequence index once.' },'fix(ecs): track system change queries across same-frame writes':diff --git a/tools/tests/golden-presentation.test.ts b/tools/tests/golden-presentation.test.tsnew file mode 100644index 000000000..2c6125fe9--- /dev/null+++ b/tools/tests/golden-presentation.test.ts@@ -0,0 +1,74 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { expect, it } from 'vitest';+import { build } from 'esbuild';+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { spawnSync } from 'node:child_process';+import os from 'node:os';+import path from 'node:path';++it.each(['ci', 'local', 'worker', 'display', 'timeout'])('golden package presentation respects %s ownership', async mode => {+ const temp = mkdtempSync(path.join(os.tmpdir(), 'estella-golden-presentation-'));+ const log = path.join(temp, 'launches.log');+ try {+ const entry = path.join(temp, 'golden.mjs');+ const compiled = await build({ entryPoints: ['tools/verify-golden.mjs'], outfile: entry,+ bundle: true, platform: 'node', format: 'esm', metafile: true, plugins: [{+ name: 'isolated-package-contract', setup(builder) {+ builder.onResolve({ filter: /electronRun\.mjs$/ }, () => ({ path: 'electron', namespace: 'fixture' }));+ builder.onResolve({ filter: /goldenProjects\.mjs$/ }, () => ({ path: 'registry', namespace: 'fixture' }));+ builder.onResolve({ filter: /engineBuild\.mjs$/ }, () => ({ path: 'engine', namespace: 'fixture' }));+ builder.onResolve({ filter: /^node:child_process$/ }, () => ({ path: 'process', namespace: 'fixture' }));+ builder.onLoad({ filter: /.*/, namespace: 'fixture' }, args => {+ const record = `import {appendFileSync} from 'node:fs';+ const record=value=>appendFileSync(${JSON.stringify(log)},JSON.stringify(value)+'\\n');`;+ if (args.path === 'electron') return { contents: `${record}+ export const NEEDS_XVFB=${mode === 'display'};+ export function runWithElectronDisplay(args,options){record({kind:'display',args,options});return {status:17};}+ export function ensureElectronBinary(){record({kind:'ensure'});}+ export function runElectron(args){record({kind:'launch',args});return {+ status:${mode === 'timeout' ? 1 : 0},+ stdout:${JSON.stringify(mode === 'timeout' ? '✗ fixture — painted=false live=true errors=0\n29 of 30 settled frames within 30000ms (phase: settle)\n' : '✓ fixture — painted=true live=true errors=0\n')},stderr:''};}+ `, loader: 'js' };+ if (args.path === 'engine') return { contents: 'export function requireCurrentEngine(){}', loader: 'js' };+ if (args.path === 'process') return { contents: `${record}+ export function spawn(){throw Error('Unexpected worker spawn');}+ export function spawnSync(_command,args){record({kind:'export',args});return {status:0,stdout:'',stderr:''};}+ `, loader: 'js' };+ return { contents: `export const ROOT=${JSON.stringify(process.cwd())};+ export const atTier=()=>[{id:'fixture',targets:['web','playable','wechat','douyin']}];+ export const sharesOf=(projects)=>[projects];+ export const projectDir=()=>${JSON.stringify(path.join(temp, 'project'))};+ export const launchTimeoutFor=()=>30000;+ export const parityFor=()=>null, interactFor=()=>null, audioFor=()=>null,+ suspendFor=()=>null, safeAreaFor=()=>null, atlasFor=()=>null,+ subpackageFor=()=>null, firstScreenFor=()=>null, packagePixels=()=>null;+ `, loader: 'js' };+ });+ },+ }] });+ expect(Object.keys(compiled.metafile!.inputs).some(file => file.endsWith('/lib/electronRun.mjs'))).toBe(false);+ const args = [entry, '--no-parity', '--work', path.join(temp, 'work'),+ ...(mode === 'worker' ? ['--worker', '--jobs', '3'] : [])];+ const run = spawnSync(process.execPath, args, { encoding: 'utf8',+ env: { ...process.env, CI: mode === 'local' ? '' : 'true', ESTELLA_GOLDEN_SHARD: '' } });+ expect(run.status, run.stderr || run.stdout).toBe(mode === 'display' ? 17 : mode === 'timeout' ? 1 : 0);+ const records = readFileSync(log, 'utf8').trim().split('\n').map(line => JSON.parse(line));+ if (mode === 'display') {+ expect(records).toHaveLength(1);+ expect(records[0]).toMatchObject({ kind: 'display', args, options: { cwd: process.cwd(), stdio: 'inherit' } });+ } else {+ const launches = records.filter(record => record.kind === 'launch');+ expect(launches).toHaveLength(4);+ for (let i = 0; i < launches.length; i++) {+ const launch = launches[i].args;+ expect(launch.includes('--present')).toBe(mode !== 'local' && i < 2);+ expect(launch[launch.indexOf('--timeout') + 1]).toBe(mode === 'worker' ? '90000' : '30000');+ expect(launch[0]).toContain(i < 2 ? 'launch-export.mjs' : 'launch-minigame.mjs');+ }+ }+ } finally {+ if (path.dirname(temp) !== path.resolve(os.tmpdir()) || !path.basename(temp).startsWith('estella-golden-presentation-')) throw Error('Unexpected fixture path');+ rmSync(temp, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+ }+});diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjsindex 8c2f27733..4dce00e63 100644--- a/tools/verify-golden.mjs+++ b/tools/verify-golden.mjs@@ -29,7 +29,7 @@ import { atTier, sharesOf, projectDir, parityFor, interactFor, audioFor, suspendimport { frameDistance, frameCellMax, readPNG } from './frameCompare.mjs';import { suspendDrive } from './lib/suspendDrive.mjs';import { retryOnDeadGpu, deadGpuVerdict, launchNeverHappenedVerdict, failureLines } from './lib/deadGpu.mjs';-import { runElectron, ensureElectronBinary } from './lib/electronRun.mjs';+import { NEEDS_XVFB, runWithElectronDisplay, runElectron, ensureElectronBinary } from './lib/electronRun.mjs';import { requireCurrentEngine } from './lib/engineBuild.mjs';const argv = process.argv.slice(2);@@ -104,6 +104,11 @@ if (shardArg && (!shard || shard.index < 0 || shard.index >= shard.of)) {console.error(`golden: a shard is i/n with 1 <= i <= n, e.g. 2/4 — got "${shardArg}"`);process.exit(2);}+if (NEEDS_XVFB) {+ const run = runWithElectronDisplay([fileURLToPath(import.meta.url), ...argv], { cwd: ROOT, stdio: 'inherit' });+ if (run.error) throw run.error;+ process.exit(run.status ?? 1);+}const projects = shard ? sharesOf(tiered, shard.of, OWNED)[shard.index] : tiered;if (shard) {console.log(`golden ${TIER}: shard ${shard.index + 1}/${shard.of} — ${projects.map((g) => g.id).join(', ') || 'nothing'}`@@ -310,7 +315,11 @@ function launchPackage(id, target, args) {() => {// Opening a PACKAGE needs no editor — the launchers are engine-side, so a// checkout without one can still judge what it shipped.- const r = runElectron([LAUNCHER(target), ...patient], { encoding: 'utf8', cwd: ROOT });+ const launchArgs = [LAUNCHER(target), ...patient];+ // Present CI's browser packages on the owned virtual display so Chromium+ // does not throttle their requestAnimationFrame callbacks as hidden pages.+ if (process.env.CI && !MINIGAME.has(target) && !launchArgs.includes('--present')) launchArgs.push('--present');+ const r = runElectron(launchArgs, { encoding: 'utf8', cwd: ROOT });// The launcher prints a ✓/✗ line once it has looked at the frame; that// line existing is what says a measurement happened.const verdictLine = (r.stdout || '').split('\n').find((l) => l.startsWith('✓') || l.startsWith('✗'));