miaoda-game-devkit 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/{gameplay-audit-BwAobjIX.d.mts → gameplay-audit-DmbBA0M_.d.mts} +7 -1
- package/dist/{gameplay-audit-BwAobjIX.d.ts → gameplay-audit-DmbBA0M_.d.ts} +7 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +165 -4
- package/dist/index.mjs +165 -4
- package/dist/lint/game-telemetry.contract.mjs +165 -4
- package/dist/lint/gameplay-contract.contract.mjs +165 -4
- package/dist/lint/phaser-headless.contract.mjs +281 -4
- package/dist/lint/vitest-config.contract.mjs +21 -3
- package/dist/vitest-config.d.mts +2 -2
- package/dist/vitest-config.d.ts +2 -2
- package/dist/vitest-config.js +7 -1
- package/dist/vitest-config.mjs +7 -1
- package/package.json +1 -1
|
@@ -5,6 +5,75 @@ import { afterEach, describe, expect, it } from "vitest";
|
|
|
5
5
|
// src/phaser-headless-host.ts
|
|
6
6
|
import * as Phaser3 from "phaser";
|
|
7
7
|
|
|
8
|
+
// src/phaser-engine-warnings.ts
|
|
9
|
+
var originalWarn;
|
|
10
|
+
var originalError;
|
|
11
|
+
var listener;
|
|
12
|
+
function formatWarningArgument(value) {
|
|
13
|
+
if (typeof value === "string") return value;
|
|
14
|
+
if (value === null || value === void 0 || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof Error) return value.message;
|
|
18
|
+
const constructorName = typeof value === "object" ? value.constructor?.name : void 0;
|
|
19
|
+
return constructorName ? `[${constructorName}]` : String(value);
|
|
20
|
+
}
|
|
21
|
+
function comesFromPhaser(stack) {
|
|
22
|
+
return /(?:^|[/\\])phaser(?:[/\\]|\.(?:js|mjs|cjs)(?::\d+)?)/m.test(stack);
|
|
23
|
+
}
|
|
24
|
+
function captureEngineDiagnostic(level, original, args) {
|
|
25
|
+
const stack = new Error(`Phaser engine ${level}`).stack ?? "";
|
|
26
|
+
if (!comesFromPhaser(stack)) {
|
|
27
|
+
original(...args);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
listener?.({
|
|
31
|
+
level,
|
|
32
|
+
message: args.map(formatWarningArgument).join(" "),
|
|
33
|
+
stack
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function installWarningMultiplexer(currentListener) {
|
|
37
|
+
if (listener) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Only one Phaser HEADLESS host may be active in the same Vitest worker. Destroy the current host before creating another one."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
listener = currentListener;
|
|
43
|
+
const passthroughWarn = console.warn;
|
|
44
|
+
const passthroughError = console.error;
|
|
45
|
+
originalWarn = passthroughWarn;
|
|
46
|
+
originalError = passthroughError;
|
|
47
|
+
console.warn = (...args) => {
|
|
48
|
+
captureEngineDiagnostic("warn", passthroughWarn, args);
|
|
49
|
+
};
|
|
50
|
+
console.error = (...args) => {
|
|
51
|
+
captureEngineDiagnostic("error", passthroughError, args);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function uninstallWarningMultiplexer() {
|
|
55
|
+
if (!listener) return;
|
|
56
|
+
if (originalWarn) console.warn = originalWarn;
|
|
57
|
+
if (originalError) console.error = originalError;
|
|
58
|
+
listener = void 0;
|
|
59
|
+
originalWarn = void 0;
|
|
60
|
+
originalError = void 0;
|
|
61
|
+
}
|
|
62
|
+
function observeEngineDiagnostics(currentListener) {
|
|
63
|
+
installWarningMultiplexer(currentListener);
|
|
64
|
+
let observing = true;
|
|
65
|
+
return () => {
|
|
66
|
+
if (!observing) return;
|
|
67
|
+
observing = false;
|
|
68
|
+
uninstallWarningMultiplexer();
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function matchesEngineWarning(message, matcher) {
|
|
72
|
+
if (typeof matcher === "string") return message.includes(matcher);
|
|
73
|
+
matcher.lastIndex = 0;
|
|
74
|
+
return matcher.test(message);
|
|
75
|
+
}
|
|
76
|
+
|
|
8
77
|
// src/phaser-text-assertions.ts
|
|
9
78
|
import * as Phaser from "phaser";
|
|
10
79
|
function describeText(label) {
|
|
@@ -14,12 +83,15 @@ function describeText(label) {
|
|
|
14
83
|
}
|
|
15
84
|
function isEffectivelyRenderable(label) {
|
|
16
85
|
let current = label;
|
|
86
|
+
const visited = /* @__PURE__ */ new Set();
|
|
17
87
|
while (current) {
|
|
88
|
+
if (visited.has(current)) return false;
|
|
89
|
+
visited.add(current);
|
|
18
90
|
const state = current;
|
|
19
91
|
if (state.visible === false || state.alpha === 0 || state.scaleX === 0 || state.scaleY === 0) {
|
|
20
92
|
return false;
|
|
21
93
|
}
|
|
22
|
-
current = state.parentContainer ?? null;
|
|
94
|
+
current = state.parentContainer ?? (state.displayList instanceof Phaser.GameObjects.Layer ? state.displayList : null);
|
|
23
95
|
}
|
|
24
96
|
return true;
|
|
25
97
|
}
|
|
@@ -195,12 +267,15 @@ function describeObject(object) {
|
|
|
195
267
|
}
|
|
196
268
|
function isEffectivelyVisible(object) {
|
|
197
269
|
let current = object;
|
|
270
|
+
const visited = /* @__PURE__ */ new Set();
|
|
198
271
|
while (current) {
|
|
272
|
+
if (visited.has(current)) return false;
|
|
273
|
+
visited.add(current);
|
|
199
274
|
const state = current;
|
|
200
275
|
if (state.visible === false || state.alpha === 0 || state.scaleX === 0 || state.scaleY === 0) {
|
|
201
276
|
return false;
|
|
202
277
|
}
|
|
203
|
-
current = state.parentContainer ?? null;
|
|
278
|
+
current = state.parentContainer ?? (state.displayList instanceof Phaser2.GameObjects.Layer ? state.displayList : null);
|
|
204
279
|
}
|
|
205
280
|
return true;
|
|
206
281
|
}
|
|
@@ -241,6 +316,12 @@ function collectGameObjectHealthProblems(scene) {
|
|
|
241
316
|
if (!checksObjectState(object)) continue;
|
|
242
317
|
const subject = describeObject(object);
|
|
243
318
|
const target = object;
|
|
319
|
+
const texture = target.texture;
|
|
320
|
+
if (isEffectivelyVisible(object) && texture && typeof texture === "object" && Reflect.get(texture, "key") === "__MISSING") {
|
|
321
|
+
problems.push(
|
|
322
|
+
`${subject} uses Phaser's __MISSING texture; verify the loaded texture key and asset path`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
244
325
|
if (typeof target.setPosition === "function") {
|
|
245
326
|
for (const property of transformProperties) {
|
|
246
327
|
requireFiniteProperty(problems, subject, object, property);
|
|
@@ -378,7 +459,13 @@ function assertSceneInteractiveHealth(scene) {
|
|
|
378
459
|
|
|
379
460
|
// src/phaser-headless-host.ts
|
|
380
461
|
async function createHeadlessGame(scene, options = {}) {
|
|
381
|
-
const {
|
|
462
|
+
const {
|
|
463
|
+
bootTimeoutMs = 2e3,
|
|
464
|
+
additionalScenes = [],
|
|
465
|
+
ignoreEngineWarnings = [],
|
|
466
|
+
allowIdleLoaderQueues = [],
|
|
467
|
+
...config
|
|
468
|
+
} = options;
|
|
382
469
|
let game;
|
|
383
470
|
let settled = false;
|
|
384
471
|
let runtimeError;
|
|
@@ -387,6 +474,16 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
387
474
|
};
|
|
388
475
|
let removeRuntimeListeners = () => {
|
|
389
476
|
};
|
|
477
|
+
const engineDiagnostics = [];
|
|
478
|
+
const loaderFailures = [];
|
|
479
|
+
const stopObservingEngineDiagnostics = observeEngineDiagnostics((diagnostic) => {
|
|
480
|
+
if (diagnostic.level === "warn" && ignoreEngineWarnings.some(
|
|
481
|
+
(matcher) => matchesEngineWarning(diagnostic.message, matcher)
|
|
482
|
+
)) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
engineDiagnostics.push(diagnostic);
|
|
486
|
+
});
|
|
390
487
|
const transitions = [];
|
|
391
488
|
const registeredScenes = [];
|
|
392
489
|
const visitedScenes = [];
|
|
@@ -472,6 +569,25 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
472
569
|
const guardScene = (currentScene) => {
|
|
473
570
|
if (guardedScenes.has(currentScene)) return;
|
|
474
571
|
guardedScenes.add(currentScene);
|
|
572
|
+
const onFileLoadError = (file) => {
|
|
573
|
+
const source = file.src || file.url || "unknown source";
|
|
574
|
+
loaderFailures.push({
|
|
575
|
+
scene: currentScene.sys.settings.key,
|
|
576
|
+
type: String(file.type),
|
|
577
|
+
key: String(file.key),
|
|
578
|
+
source: String(source)
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
currentScene.load.on(
|
|
582
|
+
Phaser3.Loader.Events.FILE_LOAD_ERROR,
|
|
583
|
+
onFileLoadError
|
|
584
|
+
);
|
|
585
|
+
restoreGuards.push(() => {
|
|
586
|
+
currentScene.load.off(
|
|
587
|
+
Phaser3.Loader.Events.FILE_LOAD_ERROR,
|
|
588
|
+
onFileLoadError
|
|
589
|
+
);
|
|
590
|
+
});
|
|
475
591
|
const scenePlugin = currentScene.scene;
|
|
476
592
|
for (const method of [
|
|
477
593
|
"start",
|
|
@@ -484,7 +600,12 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
484
600
|
if (typeof original !== "function") continue;
|
|
485
601
|
scenePlugin[method] = (key, ...args) => {
|
|
486
602
|
const target = key === void 0 ? currentScene : typeof key === "string" ? currentScene.scene.get(key) : key;
|
|
487
|
-
if (target)
|
|
603
|
+
if (!target) {
|
|
604
|
+
throw new Error(
|
|
605
|
+
`[SCENE_NOT_REGISTERED] Scene ${JSON.stringify(currentScene.sys.settings.key)} called ${method}(${JSON.stringify(key)}), but the target Scene is not registered. Add it to the production Scene registry and pass it through additionalScenes in focused HEADLESS tests.`
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
guardScene(target);
|
|
488
609
|
const from = currentScene.sys.settings.key;
|
|
489
610
|
const to = key === void 0 ? from : typeof key === "string" ? key : key.sys.settings.key;
|
|
490
611
|
if (from && to) transitions.push({ from, to, method });
|
|
@@ -612,6 +733,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
612
733
|
game.headlessStep(game.loop.lastTime, 0);
|
|
613
734
|
}
|
|
614
735
|
restoreHostGuards();
|
|
736
|
+
stopObservingEngineDiagnostics();
|
|
615
737
|
throw error;
|
|
616
738
|
}
|
|
617
739
|
const readyGame = game;
|
|
@@ -619,11 +741,39 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
619
741
|
if (hasRuntimeError) {
|
|
620
742
|
throw runtimeError instanceof Error ? runtimeError : new Error(`Unhandled Phaser runtime error: ${String(runtimeError)}`);
|
|
621
743
|
}
|
|
744
|
+
if (loaderFailures.length > 0) {
|
|
745
|
+
const imageTypes = /* @__PURE__ */ new Set(["image", "normalMap", "spritesheet"]);
|
|
746
|
+
const hasHeadlessImageFailure = loaderFailures.some(
|
|
747
|
+
(failure) => imageTypes.has(failure.type)
|
|
748
|
+
);
|
|
749
|
+
throw new Error(
|
|
750
|
+
[
|
|
751
|
+
"Phaser loader failed to load one or more files:",
|
|
752
|
+
...loaderFailures.map(
|
|
753
|
+
(failure) => `- ${failure.scene}: failed to load ${failure.type} ${JSON.stringify(failure.key)} from ${JSON.stringify(failure.source)}`
|
|
754
|
+
),
|
|
755
|
+
hasHeadlessImageFailure ? "HEADLESS image loading supports data:image/ URLs only; use a data URL or a deliberate loader stub in tests, and verify production asset paths in a browser." : "Verify the resource URL and data, or install a deliberate loader stub for network resources in HEADLESS tests."
|
|
756
|
+
].join("\n")
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
if (engineDiagnostics.length > 0) {
|
|
760
|
+
throw new Error(
|
|
761
|
+
[
|
|
762
|
+
"Phaser emitted an engine diagnostic:",
|
|
763
|
+
...engineDiagnostics.flatMap((diagnostic) => [
|
|
764
|
+
`- ${diagnostic.level}: ${diagnostic.message}`,
|
|
765
|
+
...diagnostic.stack.split("\n").slice(2, 8).map((frame) => ` ${frame.trim()}`)
|
|
766
|
+
]),
|
|
767
|
+
"Fix the invalid Phaser operation. Only known warnings (not errors) may be allowed with ignoreEngineWarnings."
|
|
768
|
+
].join("\n")
|
|
769
|
+
);
|
|
770
|
+
}
|
|
622
771
|
};
|
|
623
772
|
const canvas = readyGame.canvas;
|
|
624
773
|
if (!canvas) {
|
|
625
774
|
removeRuntimeListeners();
|
|
626
775
|
restoreHostGuards();
|
|
776
|
+
stopObservingEngineDiagnostics();
|
|
627
777
|
readyGame.destroy(true);
|
|
628
778
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
629
779
|
throw new Error("Phaser HEADLESS did not create an input canvas");
|
|
@@ -632,6 +782,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
632
782
|
if (!inputWindow) {
|
|
633
783
|
removeRuntimeListeners();
|
|
634
784
|
restoreHostGuards();
|
|
785
|
+
stopObservingEngineDiagnostics();
|
|
635
786
|
readyGame.destroy(true);
|
|
636
787
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
637
788
|
throw new Error(
|
|
@@ -687,6 +838,14 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
687
838
|
if (!currentScene.sys.isActive() && !currentScene.sys.isPaused())
|
|
688
839
|
continue;
|
|
689
840
|
appendUnique(visitedScenes, currentScene.sys.settings.key);
|
|
841
|
+
if (!allowIdleLoaderQueues.includes(currentScene.sys.settings.key) && !currentScene.load.isLoading() && currentScene.load.list.size > 0) {
|
|
842
|
+
const queuedFiles = [...currentScene.load.list].map(
|
|
843
|
+
(file) => `${file.type}:${String(file.key)}`
|
|
844
|
+
);
|
|
845
|
+
throw new Error(
|
|
846
|
+
`Phaser loader queue is not running in scene ${JSON.stringify(currentScene.sys.settings.key)}: ${queuedFiles.length} file(s) are queued (${queuedFiles.join(", ")}). Files added outside preload() require this.load.start().`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
690
849
|
assertSceneTextHealth(currentScene);
|
|
691
850
|
assertSceneInteractiveHealth(currentScene);
|
|
692
851
|
assertSceneRuntimeHealth(currentScene);
|
|
@@ -912,6 +1071,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
912
1071
|
} catch (error) {
|
|
913
1072
|
removeRuntimeListeners();
|
|
914
1073
|
restoreHostGuards();
|
|
1074
|
+
stopObservingEngineDiagnostics();
|
|
915
1075
|
readyGame.destroy(true);
|
|
916
1076
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
917
1077
|
throw error;
|
|
@@ -1043,6 +1203,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
1043
1203
|
} finally {
|
|
1044
1204
|
removeRuntimeListeners();
|
|
1045
1205
|
restoreHostGuards();
|
|
1206
|
+
stopObservingEngineDiagnostics();
|
|
1046
1207
|
}
|
|
1047
1208
|
}
|
|
1048
1209
|
};
|
|
@@ -5,6 +5,75 @@ import { describe, expect, it } from "vitest";
|
|
|
5
5
|
// src/phaser-headless-host.ts
|
|
6
6
|
import * as Phaser3 from "phaser";
|
|
7
7
|
|
|
8
|
+
// src/phaser-engine-warnings.ts
|
|
9
|
+
var originalWarn;
|
|
10
|
+
var originalError;
|
|
11
|
+
var listener;
|
|
12
|
+
function formatWarningArgument(value) {
|
|
13
|
+
if (typeof value === "string") return value;
|
|
14
|
+
if (value === null || value === void 0 || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof Error) return value.message;
|
|
18
|
+
const constructorName = typeof value === "object" ? value.constructor?.name : void 0;
|
|
19
|
+
return constructorName ? `[${constructorName}]` : String(value);
|
|
20
|
+
}
|
|
21
|
+
function comesFromPhaser(stack) {
|
|
22
|
+
return /(?:^|[/\\])phaser(?:[/\\]|\.(?:js|mjs|cjs)(?::\d+)?)/m.test(stack);
|
|
23
|
+
}
|
|
24
|
+
function captureEngineDiagnostic(level, original, args) {
|
|
25
|
+
const stack = new Error(`Phaser engine ${level}`).stack ?? "";
|
|
26
|
+
if (!comesFromPhaser(stack)) {
|
|
27
|
+
original(...args);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
listener?.({
|
|
31
|
+
level,
|
|
32
|
+
message: args.map(formatWarningArgument).join(" "),
|
|
33
|
+
stack
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function installWarningMultiplexer(currentListener) {
|
|
37
|
+
if (listener) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Only one Phaser HEADLESS host may be active in the same Vitest worker. Destroy the current host before creating another one."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
listener = currentListener;
|
|
43
|
+
const passthroughWarn = console.warn;
|
|
44
|
+
const passthroughError = console.error;
|
|
45
|
+
originalWarn = passthroughWarn;
|
|
46
|
+
originalError = passthroughError;
|
|
47
|
+
console.warn = (...args) => {
|
|
48
|
+
captureEngineDiagnostic("warn", passthroughWarn, args);
|
|
49
|
+
};
|
|
50
|
+
console.error = (...args) => {
|
|
51
|
+
captureEngineDiagnostic("error", passthroughError, args);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function uninstallWarningMultiplexer() {
|
|
55
|
+
if (!listener) return;
|
|
56
|
+
if (originalWarn) console.warn = originalWarn;
|
|
57
|
+
if (originalError) console.error = originalError;
|
|
58
|
+
listener = void 0;
|
|
59
|
+
originalWarn = void 0;
|
|
60
|
+
originalError = void 0;
|
|
61
|
+
}
|
|
62
|
+
function observeEngineDiagnostics(currentListener) {
|
|
63
|
+
installWarningMultiplexer(currentListener);
|
|
64
|
+
let observing = true;
|
|
65
|
+
return () => {
|
|
66
|
+
if (!observing) return;
|
|
67
|
+
observing = false;
|
|
68
|
+
uninstallWarningMultiplexer();
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function matchesEngineWarning(message, matcher) {
|
|
72
|
+
if (typeof matcher === "string") return message.includes(matcher);
|
|
73
|
+
matcher.lastIndex = 0;
|
|
74
|
+
return matcher.test(message);
|
|
75
|
+
}
|
|
76
|
+
|
|
8
77
|
// src/phaser-text-assertions.ts
|
|
9
78
|
import * as Phaser from "phaser";
|
|
10
79
|
function describeText(label) {
|
|
@@ -14,12 +83,15 @@ function describeText(label) {
|
|
|
14
83
|
}
|
|
15
84
|
function isEffectivelyRenderable(label) {
|
|
16
85
|
let current = label;
|
|
86
|
+
const visited = /* @__PURE__ */ new Set();
|
|
17
87
|
while (current) {
|
|
88
|
+
if (visited.has(current)) return false;
|
|
89
|
+
visited.add(current);
|
|
18
90
|
const state = current;
|
|
19
91
|
if (state.visible === false || state.alpha === 0 || state.scaleX === 0 || state.scaleY === 0) {
|
|
20
92
|
return false;
|
|
21
93
|
}
|
|
22
|
-
current = state.parentContainer ?? null;
|
|
94
|
+
current = state.parentContainer ?? (state.displayList instanceof Phaser.GameObjects.Layer ? state.displayList : null);
|
|
23
95
|
}
|
|
24
96
|
return true;
|
|
25
97
|
}
|
|
@@ -195,12 +267,15 @@ function describeObject(object) {
|
|
|
195
267
|
}
|
|
196
268
|
function isEffectivelyVisible(object) {
|
|
197
269
|
let current = object;
|
|
270
|
+
const visited = /* @__PURE__ */ new Set();
|
|
198
271
|
while (current) {
|
|
272
|
+
if (visited.has(current)) return false;
|
|
273
|
+
visited.add(current);
|
|
199
274
|
const state = current;
|
|
200
275
|
if (state.visible === false || state.alpha === 0 || state.scaleX === 0 || state.scaleY === 0) {
|
|
201
276
|
return false;
|
|
202
277
|
}
|
|
203
|
-
current = state.parentContainer ?? null;
|
|
278
|
+
current = state.parentContainer ?? (state.displayList instanceof Phaser2.GameObjects.Layer ? state.displayList : null);
|
|
204
279
|
}
|
|
205
280
|
return true;
|
|
206
281
|
}
|
|
@@ -241,6 +316,12 @@ function collectGameObjectHealthProblems(scene) {
|
|
|
241
316
|
if (!checksObjectState(object)) continue;
|
|
242
317
|
const subject = describeObject(object);
|
|
243
318
|
const target = object;
|
|
319
|
+
const texture = target.texture;
|
|
320
|
+
if (isEffectivelyVisible(object) && texture && typeof texture === "object" && Reflect.get(texture, "key") === "__MISSING") {
|
|
321
|
+
problems.push(
|
|
322
|
+
`${subject} uses Phaser's __MISSING texture; verify the loaded texture key and asset path`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
244
325
|
if (typeof target.setPosition === "function") {
|
|
245
326
|
for (const property of transformProperties) {
|
|
246
327
|
requireFiniteProperty(problems, subject, object, property);
|
|
@@ -378,7 +459,13 @@ function assertSceneInteractiveHealth(scene) {
|
|
|
378
459
|
|
|
379
460
|
// src/phaser-headless-host.ts
|
|
380
461
|
async function createHeadlessGame(scene, options = {}) {
|
|
381
|
-
const {
|
|
462
|
+
const {
|
|
463
|
+
bootTimeoutMs = 2e3,
|
|
464
|
+
additionalScenes = [],
|
|
465
|
+
ignoreEngineWarnings = [],
|
|
466
|
+
allowIdleLoaderQueues = [],
|
|
467
|
+
...config
|
|
468
|
+
} = options;
|
|
382
469
|
let game;
|
|
383
470
|
let settled = false;
|
|
384
471
|
let runtimeError;
|
|
@@ -387,6 +474,16 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
387
474
|
};
|
|
388
475
|
let removeRuntimeListeners = () => {
|
|
389
476
|
};
|
|
477
|
+
const engineDiagnostics = [];
|
|
478
|
+
const loaderFailures = [];
|
|
479
|
+
const stopObservingEngineDiagnostics = observeEngineDiagnostics((diagnostic) => {
|
|
480
|
+
if (diagnostic.level === "warn" && ignoreEngineWarnings.some(
|
|
481
|
+
(matcher) => matchesEngineWarning(diagnostic.message, matcher)
|
|
482
|
+
)) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
engineDiagnostics.push(diagnostic);
|
|
486
|
+
});
|
|
390
487
|
const transitions = [];
|
|
391
488
|
const registeredScenes = [];
|
|
392
489
|
const visitedScenes = [];
|
|
@@ -472,6 +569,25 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
472
569
|
const guardScene = (currentScene) => {
|
|
473
570
|
if (guardedScenes.has(currentScene)) return;
|
|
474
571
|
guardedScenes.add(currentScene);
|
|
572
|
+
const onFileLoadError = (file) => {
|
|
573
|
+
const source = file.src || file.url || "unknown source";
|
|
574
|
+
loaderFailures.push({
|
|
575
|
+
scene: currentScene.sys.settings.key,
|
|
576
|
+
type: String(file.type),
|
|
577
|
+
key: String(file.key),
|
|
578
|
+
source: String(source)
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
currentScene.load.on(
|
|
582
|
+
Phaser3.Loader.Events.FILE_LOAD_ERROR,
|
|
583
|
+
onFileLoadError
|
|
584
|
+
);
|
|
585
|
+
restoreGuards.push(() => {
|
|
586
|
+
currentScene.load.off(
|
|
587
|
+
Phaser3.Loader.Events.FILE_LOAD_ERROR,
|
|
588
|
+
onFileLoadError
|
|
589
|
+
);
|
|
590
|
+
});
|
|
475
591
|
const scenePlugin = currentScene.scene;
|
|
476
592
|
for (const method of [
|
|
477
593
|
"start",
|
|
@@ -484,7 +600,12 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
484
600
|
if (typeof original !== "function") continue;
|
|
485
601
|
scenePlugin[method] = (key, ...args) => {
|
|
486
602
|
const target = key === void 0 ? currentScene : typeof key === "string" ? currentScene.scene.get(key) : key;
|
|
487
|
-
if (target)
|
|
603
|
+
if (!target) {
|
|
604
|
+
throw new Error(
|
|
605
|
+
`[SCENE_NOT_REGISTERED] Scene ${JSON.stringify(currentScene.sys.settings.key)} called ${method}(${JSON.stringify(key)}), but the target Scene is not registered. Add it to the production Scene registry and pass it through additionalScenes in focused HEADLESS tests.`
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
guardScene(target);
|
|
488
609
|
const from = currentScene.sys.settings.key;
|
|
489
610
|
const to = key === void 0 ? from : typeof key === "string" ? key : key.sys.settings.key;
|
|
490
611
|
if (from && to) transitions.push({ from, to, method });
|
|
@@ -612,6 +733,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
612
733
|
game.headlessStep(game.loop.lastTime, 0);
|
|
613
734
|
}
|
|
614
735
|
restoreHostGuards();
|
|
736
|
+
stopObservingEngineDiagnostics();
|
|
615
737
|
throw error;
|
|
616
738
|
}
|
|
617
739
|
const readyGame = game;
|
|
@@ -619,11 +741,39 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
619
741
|
if (hasRuntimeError) {
|
|
620
742
|
throw runtimeError instanceof Error ? runtimeError : new Error(`Unhandled Phaser runtime error: ${String(runtimeError)}`);
|
|
621
743
|
}
|
|
744
|
+
if (loaderFailures.length > 0) {
|
|
745
|
+
const imageTypes = /* @__PURE__ */ new Set(["image", "normalMap", "spritesheet"]);
|
|
746
|
+
const hasHeadlessImageFailure = loaderFailures.some(
|
|
747
|
+
(failure) => imageTypes.has(failure.type)
|
|
748
|
+
);
|
|
749
|
+
throw new Error(
|
|
750
|
+
[
|
|
751
|
+
"Phaser loader failed to load one or more files:",
|
|
752
|
+
...loaderFailures.map(
|
|
753
|
+
(failure) => `- ${failure.scene}: failed to load ${failure.type} ${JSON.stringify(failure.key)} from ${JSON.stringify(failure.source)}`
|
|
754
|
+
),
|
|
755
|
+
hasHeadlessImageFailure ? "HEADLESS image loading supports data:image/ URLs only; use a data URL or a deliberate loader stub in tests, and verify production asset paths in a browser." : "Verify the resource URL and data, or install a deliberate loader stub for network resources in HEADLESS tests."
|
|
756
|
+
].join("\n")
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
if (engineDiagnostics.length > 0) {
|
|
760
|
+
throw new Error(
|
|
761
|
+
[
|
|
762
|
+
"Phaser emitted an engine diagnostic:",
|
|
763
|
+
...engineDiagnostics.flatMap((diagnostic) => [
|
|
764
|
+
`- ${diagnostic.level}: ${diagnostic.message}`,
|
|
765
|
+
...diagnostic.stack.split("\n").slice(2, 8).map((frame) => ` ${frame.trim()}`)
|
|
766
|
+
]),
|
|
767
|
+
"Fix the invalid Phaser operation. Only known warnings (not errors) may be allowed with ignoreEngineWarnings."
|
|
768
|
+
].join("\n")
|
|
769
|
+
);
|
|
770
|
+
}
|
|
622
771
|
};
|
|
623
772
|
const canvas = readyGame.canvas;
|
|
624
773
|
if (!canvas) {
|
|
625
774
|
removeRuntimeListeners();
|
|
626
775
|
restoreHostGuards();
|
|
776
|
+
stopObservingEngineDiagnostics();
|
|
627
777
|
readyGame.destroy(true);
|
|
628
778
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
629
779
|
throw new Error("Phaser HEADLESS did not create an input canvas");
|
|
@@ -632,6 +782,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
632
782
|
if (!inputWindow) {
|
|
633
783
|
removeRuntimeListeners();
|
|
634
784
|
restoreHostGuards();
|
|
785
|
+
stopObservingEngineDiagnostics();
|
|
635
786
|
readyGame.destroy(true);
|
|
636
787
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
637
788
|
throw new Error(
|
|
@@ -687,6 +838,14 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
687
838
|
if (!currentScene.sys.isActive() && !currentScene.sys.isPaused())
|
|
688
839
|
continue;
|
|
689
840
|
appendUnique(visitedScenes, currentScene.sys.settings.key);
|
|
841
|
+
if (!allowIdleLoaderQueues.includes(currentScene.sys.settings.key) && !currentScene.load.isLoading() && currentScene.load.list.size > 0) {
|
|
842
|
+
const queuedFiles = [...currentScene.load.list].map(
|
|
843
|
+
(file) => `${file.type}:${String(file.key)}`
|
|
844
|
+
);
|
|
845
|
+
throw new Error(
|
|
846
|
+
`Phaser loader queue is not running in scene ${JSON.stringify(currentScene.sys.settings.key)}: ${queuedFiles.length} file(s) are queued (${queuedFiles.join(", ")}). Files added outside preload() require this.load.start().`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
690
849
|
assertSceneTextHealth(currentScene);
|
|
691
850
|
assertSceneInteractiveHealth(currentScene);
|
|
692
851
|
assertSceneRuntimeHealth(currentScene);
|
|
@@ -912,6 +1071,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
912
1071
|
} catch (error) {
|
|
913
1072
|
removeRuntimeListeners();
|
|
914
1073
|
restoreHostGuards();
|
|
1074
|
+
stopObservingEngineDiagnostics();
|
|
915
1075
|
readyGame.destroy(true);
|
|
916
1076
|
readyGame.headlessStep(readyGame.loop.lastTime, 0);
|
|
917
1077
|
throw error;
|
|
@@ -1043,6 +1203,7 @@ async function createHeadlessGame(scene, options = {}) {
|
|
|
1043
1203
|
} finally {
|
|
1044
1204
|
removeRuntimeListeners();
|
|
1045
1205
|
restoreHostGuards();
|
|
1206
|
+
stopObservingEngineDiagnostics();
|
|
1046
1207
|
}
|
|
1047
1208
|
}
|
|
1048
1209
|
};
|