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(gates): an Electron download the host refuses is retried, and third-person says when no game ran

esengine92b1e1cdeec0
diff --git a/tools/lib/electronRun.mjs b/tools/lib/electronRun.mjs
index 561efa6ac..3d87f8f48 100644
--- a/tools/lib/electronRun.mjs
+++ b/tools/lib/electronRun.mjs
@@ -24,13 +24,26 @@ import { runTool } from './runTool.mjs';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
+let binaryResolved = false;
+
/**
- * Resolve Electron's binary once, before anything launches it in parallel. A binary
- * the install left out is downloaded on first launch, and two first launches at
- * once had one executing the file while the other still wrote it: spawn ETXTBSY.
+ * Resolve Electron's binary once, before anything launches it. A binary the install
+ * left out is downloaded on first launch: two first launches at once raced into
+ * spawn ETXTBSY, and a download the host refused once (HTTP 500) failed every
+ * verifier after it with no reading at all.
*/
-export function ensureElectronBinary() {
- createRequire(path.join(ROOT, 'package.json'))('electron');
+export function ensureElectronBinary({ attempts = 4, backoffMs = 10_000 } = {}) {
+ for (let attempt = 1; !binaryResolved; attempt++) {
+ try {
+ createRequire(path.join(ROOT, 'package.json'))('electron');
+ binaryResolved = true;
+ } catch (err) {
+ if (attempt >= attempts) throw err;
+ const wait = backoffMs * attempt;
+ console.error(`electron binary: attempt ${attempt} failed — retrying in ${wait / 1000}s`);
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, wait);
+ }
+ }
}
/** xvfb-run's own default is 1280x1024x8, which is smaller than the windows
@@ -49,6 +62,7 @@ export const NEEDS_XVFB = process.platform === 'linux'
* nested package has its own. `env` merges over what this adds, never replacing.
*/
export function runElectron(args, { via = 'pnpm', env, ...options } = {}) {
+ ensureElectronBinary();
const electron = via === 'npx' ? ['npx', 'electron'] : ['pnpm', 'exec', 'electron'];
const [cmd, ...rest] = NEEDS_XVFB
? ['xvfb-run', '-a', '--server-args', SCREEN, ...electron]
diff --git a/tools/verify-third-person.mjs b/tools/verify-third-person.mjs
index 101cb5330..486232520 100644
--- a/tools/verify-third-person.mjs
+++ b/tools/verify-third-person.mjs
@@ -63,6 +63,23 @@ function reading(stdout, label) {
}
}
+/**
+ * One launch of the package, answering its stdout. A launch that printed no `label`
+ * reading ran no game, and judging it anyway turned one reason into a page of
+ * `undefined` — so it stops here and says what the launcher did print.
+ */
+function launch(args, label) {
+ const r = runElectron([LAUNCHER, ...args], { encoding: 'utf8', cwd: ROOT });
+ if (!reading(r.stdout, label)) {
+ console.error(`✗ third-person: a launch printed no ${label} reading, so no game ran to judge`);
+ for (const l of `${r.stderr ?? ''}${r.stdout ?? ''}`.trim().split('\n').slice(-12)) {
+ console.error(` ${l}`);
+ }
+ process.exit(1);
+ }
+ return r.stdout;
+}
+
/**
* Drive the package with one gesture and read what the character became.
*
@@ -71,24 +88,21 @@ function reading(stdout, label) {
* standing somewhere answers another's question — a solid one already did.
*/
function run(dir, input, scene = 'gym') {
- const r = runElectron([
- LAUNCHER, '--dir', dir, '--w', String(W), '--h', String(H),
+ const stdout = launch([
+ '--dir', dir, '--w', String(W), '--h', String(H),
'--settle', '30', '--timeout', '60000', '--scene', scene,
'--input', JSON.stringify(input), '--gameplay', 'Player,Camera',
'--particles', 'FootDust,HitSpark',
'--combat', 'Player:DummyA,DummyB,Player,Enemy',
'--ai', 'Enemy',
'--out', path.join(WORK, 'frame.png'),
- ], { encoding: 'utf8', cwd: ROOT });
- const seen = reading(r.stdout, 'gameplay');
- if (!seen) {
- return { error: `no reading — ${(r.stdout || r.stderr || '').trim().slice(-200)}` };
- }
+ ], 'gameplay');
+ const seen = reading(stdout, 'gameplay');
// The far end of the effect chain, beside what the character became: the
// reading is one launch, so asking twice would be two different games.
- seen.particles = reading(r.stdout, 'particles') ?? {};
- seen.combat = reading(r.stdout, 'combat') ?? { attack: null, targets: {} };
- seen.ai = reading(r.stdout, 'ai') ?? { found: false };
+ seen.particles = reading(stdout, 'particles') ?? {};
+ seen.combat = reading(stdout, 'combat') ?? { attack: null, targets: {} };
+ seen.ai = reading(stdout, 'ai') ?? { found: false };
return seen;
}
@@ -476,12 +490,11 @@ const START = { y: 60, z: 120 };
// claim is about the MECHANISM reaching the package and not about the layout:
// what a receding field must do is spend more than one level on it.
{
- const r = runElectron([
- LAUNCHER, '--dir', dir, '--w', String(W), '--h', String(H),
+ const counters = reading(launch([
+ '--dir', dir, '--w', String(W), '--h', String(H),
'--settle', '40', '--timeout', '60000', '--scene', 'main', '--render',
'--out', path.join(WORK, 'field.png'),
- ], { encoding: 'utf8', cwd: ROOT });
- const counters = reading(r.stdout, 'render') ?? {};
+ ], 'render'), 'render');
const level = (n) => counters[`render.lod.level${n}`] ?? 0;
const selected = counters['render.lod.groups'] ?? 0;
const spread = [level(0), level(1), level(2), counters['render.lod.culled'] ?? 0]
@@ -499,18 +512,18 @@ function excursion({ out, frames, swings = 0, back = 0 }) {
const holds = out > 0 ? [{ key: 'KeyS', from: 0, to: out }] : [];
for (let i = 0; i < swings; i++) holds.push({ key: 'KeyJ', from: 225 + i * 20, to: 228 + i * 20 });
if (back > 0) holds.push({ key: 'KeyW', from: out + 10, to: out + 10 + back });
- const r = runElectron([
- LAUNCHER, '--dir', dir, '--w', String(W), '--h', String(H),
+ const stdout = launch([
+ '--dir', dir, '--w', String(W), '--h', String(H),
'--settle', '30', '--timeout', '120000', '--scene', 'main', '--streaming',
'--gameplay', 'Player,Camera', '--combat', 'Player:Sentry,Beacon,Player',
'--ai', 'Sentry', '--render', '--input', JSON.stringify({ holds, frames }),
- ], { encoding: 'utf8', cwd: ROOT });
+ ], 'gameplay');
return {
- at: reading(r.stdout, 'gameplay'),
- world: reading(r.stdout, 'streaming'),
- counters: reading(r.stdout, 'render') ?? {},
- combat: reading(r.stdout, 'combat') ?? { targets: {} },
- ai: reading(r.stdout, 'ai') ?? { found: false },
+ at: reading(stdout, 'gameplay'),
+ world: reading(stdout, 'streaming'),
+ counters: reading(stdout, 'render') ?? {},
+ combat: reading(stdout, 'combat') ?? { targets: {} },
+ ai: reading(stdout, 'ai') ?? { found: false },
};
}