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, ))