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(native): retain first launch evidence before retry

yhhfe739b8ec0d2
diff --git a/tools/lib/smokeEvidence.mjs b/tools/lib/smokeEvidence.mjs
new file mode 100644
index 000000000..0c09bd323
--- /dev/null
+++ b/tools/lib/smokeEvidence.mjs
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
+import path from 'node:path';
+
+/** Preserve a rejected launch before the next capture reuses its filenames. */
+export function retainFirstLaunch(result, directory, label) {
+ mkdirSync(directory, { recursive: true });
+ const prefix = path.join(directory, path.basename(label) + '.first');
+ const shot = result.shot && existsSync(result.shot) ? prefix + '.png' : undefined;
+ if (shot) copyFileSync(result.shot, shot);
+ const logFile = prefix + '.log';
+ const { log, ...metadata } = result;
+ writeFileSync(logFile, log ?? '');
+ const metadataFile = prefix + '.json';
+ writeFileSync(metadataFile, JSON.stringify({
+ ...metadata, shot: shot ? path.basename(shot) : null,
+ logFile: path.basename(logFile),
+ }, null, 2) + '\n');
+ return { ...result, shot, logFile, metadataFile };
+}
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 46dd025ff..c98ddda55 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 = {
+ 'test(native): retain first launch evidence before retry':
+ { internal: 'Native smoke retains the rejected launch screenshot, boot log and verdict before retry output reuses the normal filenames; startup verdicts and retry policy are unchanged.' },
'test(editor): preserve authored camera during projection changes':
{ note: 'Automation projection settings persist across editor state changes.' },
'fix(editor): retain programmatic projection across state updates':
diff --git a/tools/tests/smoke-evidence.test.ts b/tools/tests/smoke-evidence.test.ts
new file mode 100644
index 000000000..6a4017e0e
--- /dev/null
+++ b/tools/tests/smoke-evidence.test.ts
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { afterEach, expect, it } from 'vitest';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+// @ts-expect-error — .mjs verifier helper.
+import { retainFirstLaunch } from '../lib/smokeEvidence.mjs';
+
+const directories: string[] = [];
+const fixture = () => {
+ const directory = mkdtempSync(path.join(tmpdir(), 'estella-launch-evidence-'));
+ directories.push(directory);
+ return directory;
+};
+afterEach(() => {
+ for (const directory of directories.splice(0)) {
+ if (!directory.startsWith(path.join(tmpdir(), 'estella-launch-evidence-'))) {
+ throw new Error('Unexpected fixture cleanup path');
+ }
+ rmSync(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
+ }
+});
+
+it('keeps first-launch pixels, logs and verdict when the retry overwrites its files', () => {
+ const directory = fixture(), shot = path.join(directory, 'android-chat.png');
+ writeFileSync(shot, Buffer.from([1, 2, 3]));
+ const first = retainFirstLaunch({
+ ok: false, shot, log: 'first launch: 30 frames', frames: 30, colors: 1,
+ why: 'flat frame', metrics: { readyMs: 812 },
+ }, directory, 'android-chat');
+ writeFileSync(shot, Buffer.from([4, 5, 6]));
+ writeFileSync(path.join(directory, 'android-chat.log'), 'second launch');
+ expect(readFileSync(first.shot)).toEqual(Buffer.from([1, 2, 3]));
+ expect(readFileSync(first.logFile, 'utf8')).toBe('first launch: 30 frames');
+ expect(JSON.parse(readFileSync(first.metadataFile, 'utf8'))).toMatchObject({
+ ok: false, frames: 30, colors: 1, why: 'flat frame', metrics: { readyMs: 812 },
+ shot: 'android-chat.first.png', logFile: 'android-chat.first.log',
+ });
+ expect(readFileSync(shot)).toEqual(Buffer.from([4, 5, 6]));
+});
+
+it('retains a failed launch record even when it produced no screenshot', () => {
+ const directory = fixture();
+ const first = retainFirstLaunch({ ok: false, log: 'no frame', why: 'not ready' }, directory, 'ios-chat');
+ expect(first.shot).toBeUndefined();
+ expect(readFileSync(first.logFile, 'utf8')).toBe('no frame');
+ expect(JSON.parse(readFileSync(first.metadataFile, 'utf8')).shot).toBeNull();
+});
diff --git a/tools/verify-native-boot.mjs b/tools/verify-native-boot.mjs
index 4752e6df4..572273910 100644
--- a/tools/verify-native-boot.mjs
+++ b/tools/verify-native-boot.mjs
@@ -48,6 +48,7 @@ import { fileURLToPath } from 'node:url';
import { decodePng, distinctColors } from '../build-tools/utils/png.js';
import { GOLDEN, launchTimeoutFor } from './goldenProjects.mjs';
import { worthAnotherLaunch, exitCodeFor, unjudgedReason } from './lib/smokeRetry.mjs';
+import { retainFirstLaunch } from './lib/smokeEvidence.mjs';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
/** A prebuilt app's bundle id, unless `--app-id` names another; a packaged
@@ -865,7 +866,7 @@ for (const name of examples) {
APP_ID = appId;
r = await verifyApp(driver, app, name, opts, !FRAME_NOT_JUDGED[name]);
if (worthAnotherLaunch(r)) {
- const first = r;
+ const first = retainFirstLaunch(r, opts.out, `${driver.name}-${name}`);
r = await verifyApp(driver, app, name, opts, !FRAME_NOT_JUDGED[name], 2);
r.firstTry = first;
}