test(fx): source-scan BG_DEFAULTS.nutColor fixture (Creed r2)

test 11 now extracts the real nutColor from screen.js via regex and
pins it against a literal ('#f5f3f0').  Three-layer guard:
  1. guard: BG_DEFAULTS literal is present in screen.js
  2. guard: nutColor key is extractable
  3. literal-pin: extracted value == '#f5f3f0' → fail loudly if
     production drifts (verified: mutating screen.js to '#deadf5'
     makes the test fail on the pin assertion; revert confirmed clean)
Fixture and fallback assertion both use PROD_NUT_COLOR (the extracted
value), so they track production automatically.

panel_controls stub updated: added _applyBloom to the createFx stub
(Toby r1 added _applyBloom to the return set; stub was one short).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014uZ169yfoFYArXz962g7KW
This commit is contained in:
byrongamatos
2026-09-05 16:07:37 +02:00
co-authored by Claude Sonnet 4.6
parent 1f3bde73d1
commit 4a45ed8782
2 changed files with 27 additions and 9 deletions
+26 -9
View File
@@ -332,26 +332,43 @@ test('_applyCinematic sets light intensities per _cinematic flag (both paths)',
'cinematic=false: dirLight.intensity must be 0.8 (standard key)'); 'cinematic=false: dirLight.intensity must be 0.8 (standard key)');
}); });
// ── 11. _h3dHexOrDefault discriminating test (Creed gap fix) ───────────────── // ── 11. _h3dHexOrDefault — source-scan fixture + literal-pin (Creed r2 fix) ──
test('_h3dHexOrDefault parses valid hex and falls back to BG_DEFAULTS', () => { test('_h3dHexOrDefault parses valid hex and falls back to BG_DEFAULTS (source-scan fixture)', () => {
// Source-scan: extract the REAL BG_DEFAULTS.nutColor from screen.js so the
// fixture uses the production default, not an invented value.
//
// Guard assertions fail if BG_DEFAULTS is removed or restructured in screen.js —
// drift becomes loud, not silent.
const scr = screenSrc();
const bgDefMatch = scr.match(/const BG_DEFAULTS\s*=\s*\{[^}]+\}/);
assert.ok(bgDefMatch, 'BG_DEFAULTS object literal must be present in screen.js');
const nutColorMatch = bgDefMatch[0].match(/nutColor:\s*'([^']+)'/);
assert.ok(nutColorMatch, 'BG_DEFAULTS.nutColor key must be extractable from screen.js source');
const PROD_NUT_COLOR = nutColorMatch[1];
// Literal-pin: if production nutColor drifts this assertion fails loudly.
// To update intentionally: change the pinned value below to match the new production value.
assert.equal(PROD_NUT_COLOR, '#f5f3f0',
'BG_DEFAULTS.nutColor in screen.js has changed — update this pin if the change is intentional');
// Build fixture using the real production nutColor (not an invented '#cccccc').
// Mutation that goes RED: return BG_DEFAULTS.nutColor unconditionally // Mutation that goes RED: return BG_DEFAULTS.nutColor unconditionally
// → valid-hex assertion fails (returns fallback instead of parsed value) → RED. // → valid-hex assertion returns fallback instead of parsed value → RED.
const di = makeDi(); // BG_DEFAULTS.nutColor = '#cccccc' const di = makeDi({ BG_DEFAULTS: { nutColor: PROD_NUT_COLOR } });
const { _h3dHexOrDefault } = loadFxModule(di); const { _h3dHexOrDefault } = loadFxModule(di);
// Valid 6-digit hex with # → parsed integer. // Valid 6-digit hex with # → parsed integer.
assert.equal(_h3dHexOrDefault('#a1b2c3', null), 0xa1b2c3, assert.equal(_h3dHexOrDefault('#a1b2c3', null), 0xa1b2c3,
'valid hex string must be parsed to its integer value'); 'valid hex string must be parsed to its integer value');
// Hex without # → regex requires #, so falls back to BG_DEFAULTS.nutColor. // Hex without # → regex requires #, falls back to BG_DEFAULTS.nutColor.
assert.equal(_h3dHexOrDefault('a1b2c3', null), parseInt('cccccc', 16), assert.equal(_h3dHexOrDefault('a1b2c3', null), parseInt(PROD_NUT_COLOR.slice(1), 16),
'hex without # must fall back to BG_DEFAULTS.nutColor (regex requires leading #)'); 'hex without # must fall back to BG_DEFAULTS.nutColor (regex requires leading #)');
// Gibberish string → BG_DEFAULTS fallback. // Gibberish → BG_DEFAULTS fallback.
assert.equal(_h3dHexOrDefault('not-a-color', null), parseInt('cccccc', 16), assert.equal(_h3dHexOrDefault('not-a-color', null), parseInt(PROD_NUT_COLOR.slice(1), 16),
'invalid string must fall back to BG_DEFAULTS.nutColor'); 'invalid string must fall back to BG_DEFAULTS.nutColor');
// Explicit defHex overrides BG_DEFAULTS when provided. // Explicit defHex overrides BG_DEFAULTS.
assert.equal(_h3dHexOrDefault('not-a-color', '#ffffff'), 0xffffff, assert.equal(_h3dHexOrDefault('not-a-color', '#ffffff'), 0xffffff,
'invalid string with explicit defHex must use defHex, not BG_DEFAULTS'); 'invalid string with explicit defHex must use defHex, not BG_DEFAULTS');
}); });
@@ -127,6 +127,7 @@ function loadHighway3dStatics() {
_timingHex() { return 0x22ff88; }, _timingHex() { return 0x22ff88; },
_sparkBurst() {}, _sparkBurst() {},
_sparkUpdate() {}, _sparkUpdate() {},
_applyBloom() {},
_bloomEnsure() { return null; }, _bloomEnsure() { return null; },
}), }),
}; };