From 002279e63b23091d1af7b5ce0ba10b7d60591289 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 16 Jun 2026 20:30:31 -0400 Subject: [PATCH] test(artist-dir): deterministic sha256 in _seed_image (fix flaky uq collision) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_artist_directory_service._seed_image built sha256 from abs(hash(suffix)) % 10000 — PYTHONHASHSEED-randomized hash() over only 10k buckets, so two suffixes in one test could birthday-collide and violate uq_image_record_sha256. Flaky per process seed: passed on dev (run 1179), failed on main (run 1182) with identical code. Use hashlib.sha256(suffix).hexdigest() for a stable, collision-free digest. Co-Authored-By: Claude Opus 4.8 --- tests/test_artist_directory_service.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_artist_directory_service.py b/tests/test_artist_directory_service.py index fbfbf2f..56f490e 100644 --- a/tests/test_artist_directory_service.py +++ b/tests/test_artist_directory_service.py @@ -5,6 +5,8 @@ ordering by (name ASC, id ASC), substring q filter, platform EXISTS filter (with the row-duplication trap), pagination, image_count via LEFT JOIN, and the window-function preview helper. """ +import hashlib + import pytest from backend.app.models import Artist, ImageRecord, Source @@ -58,9 +60,13 @@ async def _seed_source(db, artist_id: int, platform: str, url: str): async def _seed_image(db, artist_id: int, suffix: str): + # Derive a stable, collision-free digest from the suffix. The old + # `abs(hash(suffix)) % 10000` used PYTHONHASHSEED-randomized hash() over only + # 10k buckets, so two suffixes in one test could birthday-collide and violate + # uq_image_record_sha256 — flaky per process seed (CI run 1182). db.add(ImageRecord( path=f"/images/{suffix}.jpg", - sha256=("0" * 60) + f"{abs(hash(suffix)) % 10000:04d}", + sha256=hashlib.sha256(suffix.encode()).hexdigest(), size_bytes=10, mime="image/jpeg", width=10, height=10, origin="downloaded", artist_id=artist_id, ))