test(artist-dir): deterministic sha256 in _seed_image (fix flaky uq collision)
CI / lint (push) Successful in 2s
CI / frontend-build (push) Successful in 22s
CI / backend-lint-and-test (push) Successful in 31s
CI / integration (push) Successful in 3m18s

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 <noreply@anthropic.com>
This commit is contained in:
2026-06-16 20:30:31 -04:00
parent 51201b459e
commit 002279e63b
+7 -1
View File
@@ -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,
))