|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/05/2026 |
| 5 | +DevConsoleDebugOverlay.test.mjs |
| 6 | +*/ |
| 7 | +import assert from "node:assert/strict"; |
| 8 | +import { |
| 9 | + DEV_CONSOLE_ENGINE_MAPPINGS, |
| 10 | + createCommandRegistry, |
| 11 | + createDevConsoleDebugOverlayRuntime, |
| 12 | + createDiagnosticsCollector, |
| 13 | + createOverlayPanelRegistry, |
| 14 | + getDeterministicRenderOrder, |
| 15 | + summarizeDevConsoleDebugOverlay |
| 16 | +} from "../../tools/shared/devConsoleDebugOverlay.js"; |
| 17 | + |
| 18 | +export async function run() { |
| 19 | + assert.equal(typeof DEV_CONSOLE_ENGINE_MAPPINGS.runtime, "string"); |
| 20 | + assert.equal(typeof DEV_CONSOLE_ENGINE_MAPPINGS.hotReload, "string"); |
| 21 | + |
| 22 | + const diagnosticsCollector = createDiagnosticsCollector({ |
| 23 | + nowProvider: () => 123, |
| 24 | + adapters: { |
| 25 | + runtime: () => ({ sceneId: "scene.dev", status: "ready" }), |
| 26 | + render: () => ({ fps: 60, stages: ["parallax", "tilemap", "entities", "sprite-effects", "vector-overlay"] }), |
| 27 | + hotReload: () => ({ enabled: true, pending: false }), |
| 28 | + validation: () => ({ errorCount: 0, warningCount: 1 }), |
| 29 | + input: () => { |
| 30 | + throw new Error("input adapter unavailable"); |
| 31 | + } |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + const diagnostics = diagnosticsCollector.collect(); |
| 36 | + assert.equal(diagnostics.status, "ready"); |
| 37 | + assert.equal(diagnostics.diagnostics.contractVersion, "1.0.0"); |
| 38 | + assert.equal(diagnostics.diagnostics.timestamp, 123); |
| 39 | + assert.equal(diagnostics.diagnostics.errors.length, 1); |
| 40 | + assert.equal(diagnostics.reports[0].code, "DIAGNOSTICS_ADAPTER_UNAVAILABLE"); |
| 41 | + |
| 42 | + const commandRegistry = createCommandRegistry({ includeCoreCommands: true }); |
| 43 | + assert.equal(commandRegistry.getCount() >= 17, true); |
| 44 | + const duplicateExtension = commandRegistry.registerCommand( |
| 45 | + { |
| 46 | + name: "status", |
| 47 | + category: "core", |
| 48 | + description: "conflict", |
| 49 | + usage: "status", |
| 50 | + execute: () => ({ lines: ["conflict"] }) |
| 51 | + }, |
| 52 | + "extension" |
| 53 | + ); |
| 54 | + assert.equal(duplicateExtension.status, "rejected"); |
| 55 | + assert.equal(duplicateExtension.report.code, "COMMAND_EXTENSION_CONFLICT"); |
| 56 | + |
| 57 | + const commandResult = commandRegistry.execute("status", { |
| 58 | + runtime: { sceneId: "scene.dev", status: "ready" }, |
| 59 | + hotReload: { enabled: true }, |
| 60 | + validation: { errorCount: 0, warningCount: 0 } |
| 61 | + }); |
| 62 | + assert.equal(commandResult.status, "ready"); |
| 63 | + |
| 64 | + const missingResult = commandRegistry.execute("unknown.command", {}); |
| 65 | + assert.equal(missingResult.status, "failed"); |
| 66 | + assert.equal(missingResult.reports[0].code, "COMMAND_NOT_FOUND"); |
| 67 | + |
| 68 | + const panelRegistry = createOverlayPanelRegistry({ includeCorePanels: true }); |
| 69 | + const panelConflict = panelRegistry.registerPanel( |
| 70 | + { |
| 71 | + id: "runtime-summary", |
| 72 | + title: "Conflict", |
| 73 | + enabled: true, |
| 74 | + priority: 100, |
| 75 | + source: "runtime", |
| 76 | + renderMode: "text-block" |
| 77 | + }, |
| 78 | + "extension" |
| 79 | + ); |
| 80 | + assert.equal(panelConflict.status, "rejected"); |
| 81 | + assert.equal(panelConflict.report.code, "PANEL_EXTENSION_CONFLICT"); |
| 82 | + |
| 83 | + const failingPanelRegister = panelRegistry.registerPanel( |
| 84 | + { |
| 85 | + id: "failing-panel", |
| 86 | + title: "Failing", |
| 87 | + enabled: true, |
| 88 | + priority: 150, |
| 89 | + source: "runtime", |
| 90 | + renderMode: "text-block", |
| 91 | + render: () => { |
| 92 | + throw new Error("panel exploded"); |
| 93 | + } |
| 94 | + }, |
| 95 | + "extension" |
| 96 | + ); |
| 97 | + assert.equal(failingPanelRegister.status, "registered"); |
| 98 | + |
| 99 | + const panelRender = panelRegistry.render(diagnostics.diagnostics); |
| 100 | + assert.equal(panelRender.status, "ready"); |
| 101 | + assert.equal(panelRender.sections.length >= 1, true); |
| 102 | + assert.equal(panelRender.reports.some((report) => report.code === "PANEL_RENDER_FAILED"), true); |
| 103 | + |
| 104 | + const order = getDeterministicRenderOrder(["entities", "parallax", "tilemap", "vector", "sprite"]); |
| 105 | + assert.deepEqual(order.slice(-2), ["debug-overlay", "dev-console-surface"]); |
| 106 | + assert.deepEqual(order.slice(0, 5), ["parallax", "tilemap", "entities", "sprite-effects", "vector-overlay"]); |
| 107 | + |
| 108 | + const runtime = createDevConsoleDebugOverlayRuntime({ |
| 109 | + diagnosticsCollector, |
| 110 | + commandRegistry, |
| 111 | + panelRegistry |
| 112 | + }); |
| 113 | + |
| 114 | + runtime.showConsole(); |
| 115 | + runtime.showOverlay(); |
| 116 | + |
| 117 | + const help = runtime.executeConsoleInput("help", { |
| 118 | + runtime: { sceneId: "scene.dev", status: "ready" }, |
| 119 | + hotReload: { enabled: true }, |
| 120 | + validation: { errorCount: 0, warningCount: 1 } |
| 121 | + }); |
| 122 | + assert.equal(help.status, "ready"); |
| 123 | + assert.equal(help.output.lines.length > 0, true); |
| 124 | + |
| 125 | + runtime.executeConsoleInput("overlay.toggle runtime-summary", { |
| 126 | + runtime: { sceneId: "scene.dev", status: "ready" }, |
| 127 | + hotReload: { enabled: true }, |
| 128 | + validation: { errorCount: 0, warningCount: 1 } |
| 129 | + }); |
| 130 | + |
| 131 | + const beforeReload = runtime.getState(); |
| 132 | + assert.equal(beforeReload.commandHistory.length >= 2, true); |
| 133 | + assert.equal(beforeReload.commandCount, commandRegistry.getCount()); |
| 134 | + assert.equal(beforeReload.panelCount, panelRegistry.getCount()); |
| 135 | + |
| 136 | + const reloadReady = runtime.applyHotReload({ |
| 137 | + status: "ready", |
| 138 | + mode: "targeted", |
| 139 | + runtimeState: { |
| 140 | + sceneId: "scene.dev", |
| 141 | + revision: "r1" |
| 142 | + } |
| 143 | + }); |
| 144 | + assert.equal(reloadReady.status, "ready"); |
| 145 | + assert.equal(reloadReady.reloadGeneration, 1); |
| 146 | + |
| 147 | + for (let index = 0; index < 3; index += 1) { |
| 148 | + const repeated = runtime.applyHotReload({ |
| 149 | + status: "ready", |
| 150 | + mode: "targeted", |
| 151 | + runtimeState: { |
| 152 | + sceneId: "scene.dev", |
| 153 | + revision: `r${index + 2}` |
| 154 | + } |
| 155 | + }); |
| 156 | + assert.equal(repeated.status, "ready"); |
| 157 | + assert.equal(runtime.getState().commandCount, beforeReload.commandCount); |
| 158 | + assert.equal(runtime.getState().panelCount, beforeReload.panelCount); |
| 159 | + } |
| 160 | + |
| 161 | + const reloadFailed = runtime.applyHotReload({ |
| 162 | + status: "failed", |
| 163 | + mode: "targeted", |
| 164 | + reason: "contract-invalid" |
| 165 | + }); |
| 166 | + assert.equal(reloadFailed.status, "failed"); |
| 167 | + assert.equal(reloadFailed.reports[0].code, "RELOAD_REJECTED_KEEP_LAST_GOOD"); |
| 168 | + assert.equal(runtime.getState().lastKnownGoodRuntime.revision, "r4"); |
| 169 | + |
| 170 | + runtime.hideOverlay(); |
| 171 | + const hiddenOverlay = runtime.renderOverlay(diagnostics.diagnostics); |
| 172 | + assert.equal(hiddenOverlay.status, "hidden"); |
| 173 | + |
| 174 | + runtime.showOverlay(); |
| 175 | + const visibleOverlay = runtime.renderOverlay(diagnostics.diagnostics); |
| 176 | + assert.equal(visibleOverlay.status, "ready"); |
| 177 | + |
| 178 | + const disposeResult = runtime.dispose(); |
| 179 | + assert.equal(disposeResult.status, "ready"); |
| 180 | + assert.equal(runtime.getState().disposed, true); |
| 181 | + |
| 182 | + const summary = summarizeDevConsoleDebugOverlay({ |
| 183 | + status: "ready", |
| 184 | + console: { commandCount: runtime.getState().commandCount }, |
| 185 | + overlay: { panelCount: runtime.getState().panelCount } |
| 186 | + }); |
| 187 | + assert.equal(summary.startsWith("Dev console/debug overlay ready"), true); |
| 188 | +} |
0 commit comments