test(artist-dir): deterministic sha256 in _seed_image (fix flaky uq collision)
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:
@@ -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
|
filter (with the row-duplication trap), pagination, image_count via
|
||||||
LEFT JOIN, and the window-function preview helper.
|
LEFT JOIN, and the window-function preview helper.
|
||||||
"""
|
"""
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from backend.app.models import Artist, ImageRecord, Source
|
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):
|
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(
|
db.add(ImageRecord(
|
||||||
path=f"/images/{suffix}.jpg",
|
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,
|
size_bytes=10, mime="image/jpeg", width=10, height=10,
|
||||||
origin="downloaded", artist_id=artist_id,
|
origin="downloaded", artist_id=artist_id,
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user