From 7c0c16fd66830522a79e69a83b947a1fc94c2548 Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Mon, 8 Jun 2026 20:26:56 -0700 Subject: [PATCH] test(instantid): update composite assertion to survive color-match Last commit added `_color_match` which shifts the face crop's mean to the canvas mean -- the old test fed a uniform face (210) into a uniform cleaned canvas (90), so after color-match the face was uniform 90 and the composite was undetectable by value. Switched the fake pipeline to a gradient face so the color-match preserves variance, and the assertion now checks that the face region has non-zero std (composite injected gradient pixels) instead of a value threshold. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_instantid_restore.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_instantid_restore.py b/tests/test_instantid_restore.py index 95f1bd6..d150191 100644 --- a/tests/test_instantid_restore.py +++ b/tests/test_instantid_restore.py @@ -74,7 +74,12 @@ class TestRestoreFacesInstantidControlFlow: def __call__(self, **kwargs): # Save kwargs for assertion. _FakePipe.last_kwargs = kwargs - img = Image.fromarray(np.full((1024, 1024, 3), fill_value, dtype=np.uint8)) + # Gradient face so the color-match step shifts the mean but + # preserves contrast (the composite is then detectable as a + # variance change in the face region even with uniform canvas). + grad = np.linspace(0, fill_value, 1024, dtype=np.uint8) + arr = np.broadcast_to(grad[:, None, None], (1024, 1024, 3)).copy() + img = Image.fromarray(arr) return _FakePipeOutput([img]) return _FakePipe() @@ -116,10 +121,11 @@ class TestRestoreFacesInstantidControlFlow: out = instantid_restore.restore_faces_instantid( orig, cleaned, detect_faces_fn=lambda _b: [(150, 150, 100, 100)] ) - # The cleaned image should have shifted toward the fake-pipe fill (210) - # inside the face region. - assert out[200, 200, 0] > 150 - # Corner pixels far outside the feather stay close to the cleaned base. + # The composite must have written non-uniform values into the face + # region (gradient survives color-match as variance), and the canvas + # corner stays close to the cleaned base. + face_region = out[170:230, 170:230] + assert int(face_region.std()) > 0 assert int(out[0, 0, 0]) - int(cleaned[0, 0, 0]) <= 1 def test_insightface_misses_face_skips_gracefully(self, monkeypatch):