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): replay settings transactions after confirmed GPU loss
yhh5564d3e4b346
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 0cec7bd18..fa56173d9 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): replay settings transactions after confirmed GPU loss':+ { internal: 'Settings acceptance applies the shared bounded GPU failure policy to whole fresh-profile transactions, preserving each failed attempt and screenshot while refusing retries for ordinary process or settings failures.' },'test(nav): yield fixed-step capture work to the compositor':{ internal: 'Headless workshop acceptance yields between fixed simulation batches so software rendering can drain before screenshots, and persists sampled facts before capture failures.' },'test(settings): retain restart diagnostics and focused CI evidence':diff --git a/tools/tests/settings-verifier.test.ts b/tools/tests/settings-verifier.test.tsindex 1797be048..c367f9004 100644--- a/tools/tests/settings-verifier.test.ts+++ b/tools/tests/settings-verifier.test.ts@@ -6,7 +6,7 @@ import {spawnSync} from 'node:child_process';import os from 'node:os';import path from 'node:path';-it.each(['pass', 'killed', 'wrong-label'])('settings restart diagnostics preserve %s evidence', async mode => {+it.each(['pass', 'killed', 'wrong-label', 'gpu-once', 'gpu-then-wrong-label'])('settings restart diagnostics preserve %s evidence', async mode => {const temp=mkdtempSync(path.join(os.tmpdir(),'estella-settings-contract-'));try {const entry=path.join(temp,'settings.mjs'), log=path.join(temp,'logs','restarts.log');@@ -15,12 +15,15 @@ it.each(['pass', 'killed', 'wrong-label'])('settings restart diagnostics preservname:'fixture-only-launcher',setup(builder){builder.onResolve({filter:/electronRun\.mjs$/},()=>({path:'run',namespace:'fixture'}));builder.onLoad({filter:/.*/,namespace:'fixture'},()=>({contents:`- let launch=0;+ let launch=0; const profiles=new Map();export function runElectron(args) {- const step=launch++, mode=${JSON.stringify(mode)};+ const globalStep=launch++, mode=${JSON.stringify(mode)};+ const profile=args.find(arg=>arg.startsWith('--user-data-dir='));+ const step=profiles.get(profile)??0;profiles.set(profile,step+1);if(mode==='killed')return {status:null,signal:'SIGKILL',stdout:'boot trace before termination',stderr:'renderer diagnostic'};const labels=['Master 66%','Master 33%','Master 0%','Master 0%'];- const at={MasterLabel:{text:mode==='wrong-label'?'Master 100%':labels[step]},Bar0:{h:step<2?40:6}};+ const at={MasterLabel:{text:(mode==='wrong-label'||mode==='gpu-then-wrong-label'&&globalStep>0)?'Master 100%':labels[step]},Bar0:{h:step<2?40:6}};+ if(mode.startsWith('gpu-')&&globalStep===0)return {status:1,signal:null,stdout:'probe: '+JSON.stringify({at})+'\\n[ERROR] GPU device lost: context-lost\\n',stderr:''};return {status:0,signal:null,stdout:'probe: '+JSON.stringify({at})+'\\n',stderr:'',args};}`,loader:'js'}));@@ -30,20 +33,27 @@ it.each(['pass', 'killed', 'wrong-label'])('settings restart diagnostics preservconst spec={control:{x:.2,y:.5},unlock:{x:.01,y:.01},label:'MasterLabel',expected:['Master 66%','Master 33%','Master 0%'],bars:['Bar0'],floor:6,w:800,h:600};const run=spawnSync(process.execPath,[entry,'--dir',temp,'--spec',JSON.stringify(spec),'--log',log],{encoding:'utf8'});- expect(run.status).toBe(mode==='pass'?0:1);+ expect(run.status).toBe(mode==='pass'||mode==='gpu-once'?0:1);const records=readFileSync(log,'utf8').trim().split('\n').map(line=>JSON.parse(line));const launches=records.filter(record=>record.kind==='launch');- expect(launches).toHaveLength(mode==='pass'?4:1);+ expect(launches).toHaveLength(mode==='gpu-once'?5:mode==='gpu-then-wrong-label'?2:mode==='pass'?4:1);expect(launches[0].step).toBe(0);if(mode==='killed'){expect(launches[0]).toMatchObject({status:null,signal:'SIGKILL',stdout:'boot trace before termination',stderr:'renderer diagnostic'});expect(run.stderr).toContain('settings restart 0 failed: status=none signal=SIGKILL');- } else if(mode==='wrong-label'){+ } else if(mode==='wrong-label'||mode==='gpu-then-wrong-label'){expect(run.stderr).toContain('settings label was Master 100%, expected Master 66%');- expect(launches[0].stdout).toContain('Master 100%');+ expect(launches.at(-1).stdout).toContain('Master 100%');} else {expect(records.at(-1).kind).toBe('complete');- expect(launches.map(record=>record.restart)).toEqual([false,false,false,true]);+ expect(launches.filter(record=>record.status===0).map(record=>record.restart)).toEqual([false,false,false,true]);+ }+ if(mode.startsWith('gpu-')){+ const attempts=records.filter(record=>record.kind==='attempt');+ expect(attempts).toHaveLength(2);+ expect(new Set(attempts.map(record=>record.profile)).size).toBe(2);+ expect(launches[0].screenshot).not.toBe(launches[1].screenshot);+ expect(launches[0].status).toBe(1);}} finally {if(path.dirname(temp)!==path.resolve(os.tmpdir())||!path.basename(temp).startsWith('estella-settings-contract-'))throw Error('Unexpected fixture path');diff --git a/tools/verify-settings.mjs b/tools/verify-settings.mjsindex 507a1d399..713d78ff4 100644--- a/tools/verify-settings.mjs+++ b/tools/verify-settings.mjs@@ -5,6 +5,7 @@ import net from 'node:net';import { appendFileSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';import os from 'node:os';import { runElectron } from './lib/electronRun.mjs';+import { gpuFailed, retryOnDeadGpu } from './lib/deadGpu.mjs';import { fileURLToPath } from 'node:url';const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');@@ -23,43 +24,61 @@ const server = net.createServer();await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve); });const port = server.address().port;await new Promise(resolve => server.close(resolve));-// One new profile and one stable origin, reused across independent processes.-const profile = mkdtempSync(path.join(os.tmpdir(), 'estella-settings-'));const names = [spec.label, ...spec.bars];-try {- record({kind: 'session', startedAt: new Date().toISOString(), dir: path.resolve(dir)});- for (let i = 0; i <= spec.expected.length; i++) {- const restart = i === spec.expected.length;- const pointer = restart ? spec.unlock : spec.control;- const screenshot = log ? path.resolve(`${log}.launch-${i}.png`) : null;- const run = runElectron(['--user-data-dir=' + profile, path.join(root, 'tools/launchers/launch-export.mjs'),- '--dir', path.resolve(dir), '--port', String(port), '--w', String(spec.w), '--h', String(spec.h),- '--input', JSON.stringify({ pointer, frames: spec.frames ?? 60 }), '--probe', names.join(','),- ...(screenshot ? ['--out', screenshot] : [])], { cwd: root, encoding: 'utf8' });- record({kind: 'launch', step: i, restart, screenshot, expected: spec.expected[restart ? i - 1 : i],- status: run.status, signal: run.signal ?? null, timedOut: !!run.timedOut,- error: run.error?.message, stdout: run.stdout ?? '', stderr: run.stderr ?? ''});- if (run.status !== 0) throw new Error('settings restart ' + i + ' failed: status='- + (run.status ?? 'none') + ' signal=' + (run.signal ?? 'none') + ' timedOut=' + !!run.timedOut- + '\n' + (run.stdout || '') + (run.stderr || ''));- const match = /probe: (\{.*\})/.exec(run.stdout || '');- if (!match) throw new Error('settings launch produced no probe');- const at = JSON.parse(match[1]).at;- const expected = spec.expected[restart ? i - 1 : i];- if (at?.[spec.label]?.text !== expected) throw new Error(`settings label was ${at?.[spec.label]?.text}, expected ${expected}`);- const heights = spec.bars.map(name => at?.[name]?.h);- if (!heights.length || heights.some(h => typeof h !== 'number' || !Number.isFinite(h))) throw new Error('settings spectrum probe was incomplete');- const peak = Math.max(...heights);- if (i >= spec.expected.length - 1 && peak !== spec.floor) throw new Error(`restored mute still produced output: ${peak}`);- if (i === 0 && peak <= spec.floor) throw new Error('settings test began with no audible output');- console.log(`settings restart ${i}: ${expected}, spectrum peak ${peak}`);+let attempts = 0;+// Each attempt shares one origin/profile across restarts. A failed mutating+// attempt must restart with fresh storage, rather than clicking the same control twice.+function runAttempt() {+ const attempt = attempts++;+ const profile = mkdtempSync(path.join(os.tmpdir(), 'estella-settings-'));+ try {+ record({kind: 'attempt', attempt, profile});+ for (let i = 0; i <= spec.expected.length; i++) {+ const restart = i === spec.expected.length;+ const pointer = restart ? spec.unlock : spec.control;+ const screenshot = log ? path.resolve(`${log}.attempt-${attempt}.launch-${i}.png`) : null;+ const run = runElectron(['--user-data-dir=' + profile, path.join(root, 'tools/launchers/launch-export.mjs'),+ '--dir', path.resolve(dir), '--port', String(port), '--w', String(spec.w), '--h', String(spec.h),+ '--input', JSON.stringify({ pointer, frames: spec.frames ?? 60 }), '--probe', names.join(','),+ ...(screenshot ? ['--out', screenshot] : [])], { cwd: root, encoding: 'utf8' });+ record({kind: 'launch', attempt, step: i, restart, screenshot, expected: spec.expected[restart ? i - 1 : i],+ status: run.status, signal: run.signal ?? null, timedOut: !!run.timedOut,+ error: run.error?.message, stdout: run.stdout ?? '', stderr: run.stderr ?? ''});+ if (run.status !== 0) {+ const output = (run.stdout || '') + (run.stderr || '');+ const error = new Error('settings restart ' + i + ' failed: status='+ + (run.status ?? 'none') + ' signal=' + (run.signal ?? 'none') + ' timedOut=' + !!run.timedOut+ + '\n' + output);+ if (gpuFailed(output)) return {ok: false, output, error, measured: false};+ throw error;+ }+ const match = /probe: (\{.*\})/.exec(run.stdout || '');+ if (!match) throw new Error('settings launch produced no probe');+ const at = JSON.parse(match[1]).at;+ const expected = spec.expected[restart ? i - 1 : i];+ if (at?.[spec.label]?.text !== expected) throw new Error(`settings label was ${at?.[spec.label]?.text}, expected ${expected}`);+ const heights = spec.bars.map(name => at?.[name]?.h);+ if (!heights.length || heights.some(h => typeof h !== 'number' || !Number.isFinite(h))) throw new Error('settings spectrum probe was incomplete');+ const peak = Math.max(...heights);+ if (i >= spec.expected.length - 1 && peak !== spec.floor) throw new Error(`restored mute still produced output: ${peak}`);+ if (i === 0 && peak <= spec.floor) throw new Error('settings test began with no audible output');+ console.log(`settings restart ${i}: ${expected}, spectrum peak ${peak}`);+ }+ return {ok: true};+ } finally {+ const resolved = path.resolve(profile);+ if (path.dirname(resolved) !== path.resolve(os.tmpdir()) || !path.basename(resolved).startsWith('estella-settings-')) {+ throw new Error('unexpected settings profile path');+ }+ rmSync(resolved, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });}- record({kind: 'complete', launches: spec.expected.length + 1});- console.log('✓ settings survived process restart and restored mute affects output');-} finally {- const resolved = path.resolve(profile);- if (path.dirname(resolved) !== path.resolve(os.tmpdir()) || !path.basename(resolved).startsWith('estella-settings-')) {- throw new Error('unexpected settings profile path');- }- rmSync(resolved, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });}++record({kind: 'session', startedAt: new Date().toISOString(), dir: path.resolve(dir)});+const result = retryOnDeadGpu(runAttempt, (_noVerdict, last) => {+ record({kind: 'retry', attempt: attempts - 1, reason: 'confirmed GPU failure', output: last.output});+ console.log('↻ settings GPU attempt failed; replaying the full sequence with fresh storage');+});+if (!result.ok) throw result.error;+record({kind: 'complete', attempts, launches: spec.expected.length + 1});+console.log('✓ settings survived process restart and restored mute affects output');