test(h3d-carve-8): fix Toby r1 findings — _applyBloom extract + test 7 vacuity

F1 (MED — declared gap confirmed and widened):
  Extract _bloomEnsure's .then() body into named _applyBloom([EC, RP, UB, OP])
  at factory scope. _applyBloom added to return set and screen.js destructure.
  Test 9 calls _applyBloom directly with mock module objects (no import() needed).
  All 4 write-back mutations now RED:
    sever setBloomPass(bp)    → RED
    sever setBloomW(w)        → RED
    sever setBloomH(h)        → RED
    sever setComposer(comp)   → RED

F2 (MED — vacuous OR clause in test 7):
  Old:
       The  arm is always true (no living sparks) → NO-OP passes.
  Fix: replaced with independent AND assertions on BOTH needsUpdate flags.
  NO-OP mutation (return; at top of _sparkUpdate) now goes RED.

DI beyond-subst count +5: _applyBloom reads T/ren/scene/cam/highwayCanvas
from live-accessors (instead of inheriting _bloomEnsure's locals).
fx.js return set: 6 → 7 symbols (added _applyBloom).
Suite: 1267/1269 (2 pre-existing failures unchanged).

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 15:51:42 +02:00
co-authored by Claude Sonnet 4.6
parent 9b98d78cbe
commit d060c49238
3 changed files with 100 additions and 42 deletions
+1 -1
View File
@@ -6381,7 +6381,7 @@ import { createFx } from './src/fx.js'; // h3d-carve-8
/* ── h3d-carve-8: Q-helpers (lighting/FX) → src/fx.js ─────────── */
/* buildBoard deferred: see plans/highway3d-carve.md §3 row 16. */
const { _h3dHexOrDefault, _applyCinematic, _timingHex, _sparkBurst, _sparkUpdate, _bloomEnsure } = createFx({
const { _h3dHexOrDefault, _applyCinematic, _timingHex, _sparkBurst, _sparkUpdate, _applyBloom, _bloomEnsure } = createFx({
BG_DEFAULTS, K,
getT: () => T,
getAmbLight: () => ambLight, getDirLight: () => dirLight, getCinematic: () => _cinematic,
+30 -23
View File
@@ -99,44 +99,51 @@ export function createFx({
_sparkPts.geometry.attributes.color.needsUpdate = true;
_sparkPts.visible = any;
}
// #4 Bloom — .then() body extracted for test harness reach (Toby r1 F1).
// Called with [EC, RP, UB, OP] when all four postprocessing modules resolve.
// DI rewire: T/ren/scene/cam/highwayCanvas from live-accessors (per-call).
function _applyBloom([EC, RP, UB, OP]) {
// VERBATIM MOVE of the .then() handler body from _bloomEnsure.
// DI rewire: T/ren/scene/cam/highwayCanvas read from live-accessors.
try {
const T = getT(), highwayCanvas = getHighwayCanvas();
const ren = getRen(), scene = getScene(), cam = getCam();
const sz = canvasSize(highwayCanvas) || { w: 1280, h: 720 };
const w = Math.max(2, sz.w | 0), h = Math.max(2, sz.h | 0);
// Multisampled (WebGL2 MSAA) HalfFloat target so anti-aliasing
// survives the bloom path — EffectComposer's default target has no
// `samples`, which is why bloom-on looked jagged (worst on non-Retina
// DPR1 displays that have no supersampling cushion).
const _bloomRT = new T.WebGLRenderTarget(w, h, { type: T.HalfFloatType, samples: 4 });
const comp = new EC.EffectComposer(ren, _bloomRT);
comp.addPass(new RP.RenderPass(scene, cam));
const bp = new UB.UnrealBloomPass(new T.Vector2(w, h), 0.65, 0.5, 0.82); // strength, radius, threshold (high → only emissive blooms)
setBloomPass(bp);
comp.addPass(bp);
comp.addPass(new OP.OutputPass());
comp.setSize(w, h);
setBloomW(w); setBloomH(h); setComposer(comp);
} catch (e) { console.warn('[3D-Hwy] bloom init failed', e); setComposer(null); }
}
// #4 Bloom: lazy-load the vendored postprocessing addons and build an
// EffectComposer (RenderPass -> UnrealBloomPass -> OutputPass/ACES). Returns
// the composer once ready, or null (caller falls back to a direct render).
function _bloomEnsure() {
// VERBATIM MOVE. DI rewire: all factory-scope vars via get/set accessors.
// _composer, _bloomLoad, _bloomPass, _bloomW, _bloomH are REASSIGNED here
// so setters are required — these must NOT silently become locals.
// _composer, _bloomLoad, _bloomPass, _bloomW, _bloomH are REASSIGNED via
// _applyBloom — setters required; must NOT silently become locals.
if (getComposer()) return getComposer();
const ren = getRen(), scene = getScene(), cam = getCam();
if (getBloomLoad() || !ren || !scene || !cam) return null;
const T = getT(), highwayCanvas = getHighwayCanvas();
const A = '/static/vendor/three/addons/';
setBloomLoad(Promise.all([
import(A + 'postprocessing/EffectComposer.js'),
import(A + 'postprocessing/RenderPass.js'),
import(A + 'postprocessing/UnrealBloomPass.js'),
import(A + 'postprocessing/OutputPass.js'),
]).then(([EC, RP, UB, OP]) => {
try {
const sz = canvasSize(highwayCanvas) || { w: 1280, h: 720 };
const w = Math.max(2, sz.w | 0), h = Math.max(2, sz.h | 0);
// Multisampled (WebGL2 MSAA) HalfFloat target so anti-aliasing
// survives the bloom path — EffectComposer's default target has no
// `samples`, which is why bloom-on looked jagged (worst on non-Retina
// DPR1 displays that have no supersampling cushion).
const _bloomRT = new T.WebGLRenderTarget(w, h, { type: T.HalfFloatType, samples: 4 });
const comp = new EC.EffectComposer(ren, _bloomRT);
comp.addPass(new RP.RenderPass(scene, cam));
const bp = new UB.UnrealBloomPass(new T.Vector2(w, h), 0.65, 0.5, 0.82); // strength, radius, threshold (high → only emissive blooms)
setBloomPass(bp);
comp.addPass(bp);
comp.addPass(new OP.OutputPass());
comp.setSize(w, h);
setBloomW(w); setBloomH(h); setComposer(comp);
} catch (e) { console.warn('[3D-Hwy] bloom init failed', e); setComposer(null); }
}).catch((e) => console.warn('[3D-Hwy] bloom modules failed', e)));
]).then(_applyBloom).catch((e) => console.warn('[3D-Hwy] bloom modules failed', e)));
return null;
}
return { _h3dHexOrDefault, _applyCinematic, _timingHex, _sparkBurst, _sparkUpdate, _bloomEnsure };
return { _h3dHexOrDefault, _applyCinematic, _timingHex, _sparkBurst, _sparkUpdate, _applyBloom, _bloomEnsure };
}