"""Checks that wall lighting can actually be switched off. The floor's lighting runs behind a three-way cascade of flags. Walls bypassed it entirely: `builder._compute_wall_lighting` submitted `build_luminance_lighting_maps` for every wall component unconditionally, and `build_wall_segment` computed the same maps inline whenever none were handed to it. So with every lighting flag off, walls were still lit -- 0.63s of a 5.67s conversion on the GPU box, and no way to stop it. Note the second half: gating only the pre-compute would have moved the work into the packaging phase rather than removing it, and serially at that. The switch has to reach `build_wall_segment` itself, which is what these pin. """ import unittest import numpy as np from services.pipeline.bundle_assembly import build_wall_segment HEIGHT, WIDTH = 200, 260 MODELS = {"segmentation": {"name": "test-segmenter"}} def _lit_room() -> np.ndarray: """A textured image, so luminance lighting has something to find. A flat image can yield a degenerate shade map, which would make the "lighting on" guard below pass for the wrong reason. """ rows, cols = np.mgrid[0:HEIGHT, 0:WIDTH].astype(np.float32) gradient = 40 + 170 * (cols / WIDTH) * (0.4 + 0.6 * (rows / HEIGHT)) image = np.stack([gradient, gradient * 0.9, gradient * 0.8], axis=2) return np.clip(image, 0, 255).astype(np.uint8) def _wall_mask() -> np.ndarray: mask = np.zeros((HEIGHT, WIDTH), dtype=np.uint8) mask[20:180, 20:WIDTH - 20] = 1 return mask def _geometry() -> dict: """Enough for the plane fit to be attempted and decline harmlessly.""" return {"points": None, "validMask": None, "normals": None, "intrinsics": None} def _build(**overrides): kwargs = { "wall_index": 0, "component_mask": _wall_mask(), "wall_protected_mask": np.zeros((HEIGHT, WIDTH), dtype=np.uint8), "geometry": _geometry(), "img_np": _lit_room(), "wall_components": [None], "models": MODELS, "precomputed_lighting": None, } kwargs.update(overrides) return build_wall_segment(**kwargs) class WallLightingGateTest(unittest.TestCase): def test_lighting_is_computed_inline_when_enabled(self): """Guard: proves the assertion below can tell the two apart.""" segment = _build(lighting_enabled=True) self.assertIsNotNone(segment) self.assertIsNotNone(segment["shadeMap"]) self.assertTrue(segment["metadata"]["shadingEnabled"]) def test_no_lighting_maps_are_produced_when_disabled(self): segment = _build(lighting_enabled=False) self.assertIsNotNone(segment) self.assertIsNone(segment["shadeMap"]) self.assertIsNone(segment["showroomShadeMap"]) self.assertIsNone(segment["reflectionMap"]) self.assertFalse(segment["metadata"]["shadingEnabled"]) def test_disabling_beats_precomputed_maps(self): """The flag must win, so a stale pre-compute cannot leak lighting back.""" segment = _build( lighting_enabled=False, precomputed_lighting={"shadeMap": np.ones((HEIGHT, WIDTH), dtype=np.uint8)}, ) self.assertIsNotNone(segment) self.assertIsNone(segment["shadeMap"]) def test_lighting_defaults_to_on(self): """Omitting the flag must not silently darken production.""" segment = _build() self.assertIsNotNone(segment) self.assertIsNotNone(segment["shadeMap"]) if __name__ == "__main__": unittest.main()