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(golden): a package is judged on its own points, at the surface its project is authored for

esenginefb09a2848e21
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index 948b6df45..e774b46c7 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -548,6 +548,12 @@ export const GOLDEN = [
// Nothing in it responds to input: the scene is a placed model, and the
// chain it certifies is the import's — products, refs, prefab, package.
interactGap: 'a placed model has nothing to drive; the import chain is what this certifies',
+ // Both colours of the model's own texture: an import that lost the texture, or
+ // the model, leaves the clear colour here.
+ webPixels: [
+ { what: 'the model draws its texture', x: 0.19, y: 0.385, rgb: [212, 156, 75], tol: 24 },
+ { what: 'and the texture\'s second colour', x: 0.40, y: 0.385, rgb: [58, 46, 40], tol: 24 },
+ ],
},
{
id: 'lighting-3d',
@@ -586,9 +592,14 @@ export const GOLDEN = [
targets: ['web', 'desktop'],
tier: 'pr',
interactGap: 'the torch follows a pointer the runner does not have; what it certifies is that the pass survives the package',
- // No points: one light follows the pointer, so where a shadow falls is where the
- // runner's pointer happens to be. What a 2D shadow LOOKS like is nine render
- // criteria's answer; this asks only that the pass survives a package.
+ // The launcher moves no pointer, so the torch rests where the scene puts it.
+ // Two cells one distance from it, past a block and in the open, differ only by
+ // the shadow pass — whether it survives a package, not what a shadow looks like.
+ webPixels: [
+ { what: 'the torch lights the floor', x: 0.55, y: 0.42, rgb: [172, 165, 147], tol: 30 },
+ { what: 'the open side is lit at that distance', x: 0.65, y: 0.42, rgb: [63, 61, 56], tol: 24 },
+ { what: 'the block shadows its far side', x: 0.35, y: 0.42, rgb: [13, 14, 14], tol: 24 },
+ ],
},
{
id: 'physics-3d',
@@ -664,6 +675,11 @@ export const GOLDEN = [
// does (drift 0.041 against a driven 0.100), so a pixel A/B cannot say the
// key caused it. The keyboard is covered by platformer and input-actions.
interactGap: 'an autonomous enemy moves as much as the input does; the A/B cannot attribute it',
+ // Away from the patrol: the ground and the water are layers of their own.
+ webPixels: [
+ { what: 'the ground layer draws', x: 0.84, y: 0.93, rgb: [198, 124, 89], tol: 24 },
+ { what: 'the water layer draws', x: 0.43, y: 0.83, rgb: [54, 192, 245], tol: 24 },
+ ],
},
{
id: 'spine-demo',
@@ -835,6 +851,24 @@ export function atTier(tier) {
return GOLDEN.filter((g) => rank(g.tier) <= want);
}
+/**
+ * `projects` in `n` shares balanced by what each asks of a launch — the targets
+ * in `owned`, times what gets driven at them — rather than by count:
+ * celestial-heights alone is a third. A project stays whole, and each lands in
+ * exactly one share, so a shard left out is a project nobody launched.
+ */
+export function sharesOf(projects, n, owned) {
+ const weight = (g) => g.targets.filter((t) => owned.has(t)).length
+ * (1 + [interactFor(g), audioFor(g), safeAreaFor(g), atlasFor(g)].filter(Boolean).length + (suspendFor(g) ? 3 : 0));
+ const bins = Array.from({ length: n }, () => ({ projects: [], load: 0 }));
+ for (const g of [...projects].sort((a, b) => weight(b) - weight(a))) {
+ const bin = bins.reduce((least, b) => (b.load < least.load ? b : least));
+ bin.projects.push(g);
+ bin.load += weight(g);
+ }
+ return bins.map((b) => b.projects);
+}
+
/** Every (project, target) pair a tier must package and launch. */
export function matrixAtTier(tier) {
return atTier(tier).flatMap((g) => g.targets.map((target) => ({ id: g.id, target })));
diff --git a/tools/tests/golden-shares.test.ts b/tools/tests/golden-shares.test.ts
new file mode 100644
index 000000000..a469f9a34
--- /dev/null
+++ b/tools/tests/golden-shares.test.ts
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file golden-shares.test.ts
+ * @brief CI launches the golden corpus one shard per runner. A project the split
+ * drops is a project nothing launches, and every shard still passes.
+ */
+import { describe, it, expect } from 'vitest';
+import { atTier, sharesOf } from '../goldenProjects.mjs';
+
+const OWNED = new Set(['web', 'playable', 'wechat']);
+
+describe('golden shards', () => {
+ it.each(['pr', 'nightly', 'release'])('put every %s project in exactly one shard', (tier) => {
+ const all = atTier(tier).map((g) => g.id).sort();
+ for (let n = 1; n <= 6; n++) {
+ const shares = sharesOf(atTier(tier), n, OWNED);
+ expect(shares).toHaveLength(n);
+ expect(shares.flat().map((g) => g.id).sort()).toEqual(all);
+ }
+ });
+
+ it('keeps a shard index naming the same projects from run to run', () => {
+ const ids = () => sharesOf(atTier('pr'), 4, OWNED).map((s) => s.map((g) => g.id));
+ expect(ids()).toEqual(ids());
+ });
+});
diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjs
index d7dacc185..753e18caf 100644
--- a/tools/verify-golden.mjs
+++ b/tools/verify-golden.mjs
@@ -15,12 +15,13 @@
* node tools/verify-golden.mjs --tier pr
* node tools/verify-golden.mjs --tier nightly --only platformer,spine-demo
* node tools/verify-golden.mjs --tier pr --shots <dir>
+ * node tools/verify-golden.mjs --tier pr --shard 2/4
*/
import { spawn, spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { mkdirSync, rmSync, readFileSync, existsSync, writeFileSync } from 'node:fs';
import path from 'node:path';
-import { atTier, projectDir, parityFor, interactFor, audioFor, suspendFor, safeAreaFor, atlasFor, webPixels, launchTimeoutFor, ROOT } from './goldenProjects.mjs';
+import { atTier, sharesOf, projectDir, parityFor, interactFor, audioFor, suspendFor, safeAreaFor, atlasFor, webPixels, launchTimeoutFor, ROOT } from './goldenProjects.mjs';
import { frameDistance, frameCellMax, readPNG } from './frameCompare.mjs';
import { retryOnDeadGpu, deadGpuVerdict, launchNeverHappenedVerdict, failureLines } from './lib/deadGpu.mjs';
import { runElectron, ensureElectronBinary } from './lib/electronRun.mjs';
@@ -83,7 +84,20 @@ function exporterReason(out) {
}
const only = ONLY ? new Set(ONLY.split(',').map((s) => s.trim())) : null;
-const projects = atTier(TIER).filter((g) => !only || only.has(g.id));
+const tiered = atTier(TIER).filter((g) => !only || only.has(g.id));
+const shardArg = flag('shard', '');
+const shard = /^\d+\/\d+$/.test(shardArg)
+ ? { index: Number(shardArg.split('/')[0]) - 1, of: Number(shardArg.split('/')[1]) }
+ : null;
+if (argv.includes('--shard') && (!shard || shard.index < 0 || shard.index >= shard.of)) {
+ console.error('golden: --shard wants i/n with 1 <= i <= n, e.g. --shard 2/4');
+ process.exit(2);
+}
+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'}`
+ + ` of ${tiered.length} project(s)`);
+}
const pairs = projects.flatMap((g) => g.targets.filter((t) => OWNED.has(t)).map((t) => ({ id: g.id, target: t })));
const deferred = projects.flatMap((g) => g.targets.filter((t) => !OWNED.has(t)).map((t) => `${g.id}:${t}`));
@@ -94,25 +108,17 @@ console.log(`golden ${TIER}: ${projects.length} project(s), ${pairs.length} pair
/**
* `--jobs N`: the projects, N at a time, each worker this script over its share.
* The release tier's seventeen took 33 minutes in a row with three cores idle.
- * A project stays whole (a worker's `--only` is by id); shares are balanced by
- * what a project asks for, not by count — celestial-heights alone is a third.
*/
const JOBS = Math.max(1, Number(flag('jobs', '1')) || 1);
/** How many launches share this runner's rasterizer: a worker's, or one. */
const SHARE = argv.includes('--worker') ? JOBS : 1;
if (JOBS > 1 && !argv.includes('--worker') && projects.length > 1) {
ensureElectronBinary();
- const weight = (g) => g.targets.filter((t) => OWNED.has(t)).length
- * (1 + [interactFor(g), audioFor(g), safeAreaFor(g), atlasFor(g)].filter(Boolean).length + (suspendFor(g) ? 3 : 0));
- const bins = Array.from({ length: Math.min(JOBS, projects.length) }, () => ({ ids: [], load: 0 }));
- for (const g of [...projects].sort((a, b) => weight(b) - weight(a))) {
- const bin = bins.reduce((least, b) => (b.load < least.load ? b : least));
- bin.ids.push(g.id);
- bin.load += weight(g);
- }
+ const bins = sharesOf(projects, Math.min(JOBS, projects.length), OWNED).map((share) => ({ ids: share.map((g) => g.id) }));
// `--jobs` goes through: a worker does not fork again (`--worker`), and it
- // needs the count to know what it shares the rasterizer with — see SHARE.
- const own = new Set(['--only']);
+ // needs the count to know what it shares the rasterizer with — see SHARE. The
+ // shard does not: a worker's `--only` is already inside it.
+ const own = new Set(['--only', '--shard']);
const passthrough = argv.filter((a, i) => !own.has(a) && !own.has(argv[i - 1]));
const outcomes = await Promise.all(bins.map((bin, i) => new Promise((resolve) => {
const tag = `[${i + 1}/${bins.length}]`;
@@ -152,11 +158,19 @@ function manifestOf(id) {
}
}
-/** A package derives its orientation gate from this, so the comparison surface
- * has to agree with it. */
-function designAspect(id) {
+/**
+ * The surface a project is drawn on, in the aspect it is authored for. A package
+ * derives its orientation gate from that aspect, and a point is a fraction of the
+ * surface — so the editor's frame and the package's take this one size, whether or
+ * not the editor is opened at all.
+ */
+function surfaceOf(id) {
const r = manifestOf(id).designResolution;
- return r?.width > 0 && r?.height > 0 ? { w: r.width, h: r.height } : { w: 16, h: 9 };
+ const a = r?.width > 0 && r?.height > 0 ? { w: r.width, h: r.height } : { w: 16, h: 9 };
+ const major = 820;
+ return a.h >= a.w
+ ? { width: Math.round((major * a.w) / a.h), height: major }
+ : { width: major, height: Math.round((major * a.h) / a.w) };
}
/**
@@ -176,11 +190,7 @@ function keepAttempt(label, n, output) {
* letterbox — a difference of surface, not of game.
*/
function captureEditorFrame(id, out, timeoutMs) {
- const a = designAspect(id);
- const major = 820;
- const panel = a.h >= a.w
- ? { width: Math.round((major * a.w) / a.h), height: major }
- : { width: major, height: Math.round((major * a.h) / a.w) };
+ const panel = surfaceOf(id);
const attempt = () => {
// A partial file from the attempt before would be read as this attempt's frame.
rmSync(out, { force: true });
@@ -438,9 +448,10 @@ for (const { id, target } of pairs) {
}
const packagePng = SHOTS ? path.join(SHOTS, `${id}-${target}.png`) : path.join(WORK, `${id}-${target}.png`);
+ const surface = editor ? { width: editor.w, height: editor.h } : surfaceOf(id);
const launch = launchPackage(id, target, [
'--dir', out, '--out', packagePng,
- ...(editor ? ['--w', String(editor.w), '--h', String(editor.h)] : []),
+ '--w', String(surface.width), '--h', String(surface.height),
...(timeoutMs ? ['--timeout', String(timeoutMs)] : []),
]);