fix(fc3c): structured JPEGs + phash_threshold=0 so both fixtures attach

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-20 22:45:55 -04:00
parent c212691771
commit 1fe259fa14
+24 -5
View File
@@ -34,10 +34,26 @@ async def seed_artist_and_source(db, db_sync):
return artist, source return artist, source
def _make_jpg(path: Path, color=(100, 100, 100)): def _make_jpg(path: Path, split: str = "h"):
"""Write a structured JPEG so phash isn't degenerate.
Solid-color images all phash-collapse (DCT of a flat image is zero).
Use `split='h'` (top/bottom halves) or `split='v'` (left/right) to
give each fixture file a distinct phash.
"""
from PIL import Image from PIL import Image
path.parent.mkdir(parents=True, exist_ok=True) path.parent.mkdir(parents=True, exist_ok=True)
Image.new("RGB", (32, 32), color).save(path, "JPEG") im = Image.new("RGB", (64, 64), (255, 255, 255))
px = im.load()
if split == "h":
for y in range(32):
for x in range(64):
px[x, y] = (0, 0, 0)
else: # 'v'
for y in range(64):
for x in range(32):
px[x, y] = (0, 0, 0)
im.save(path, "JPEG")
def _make_fake_dl_result( def _make_fake_dl_result(
@@ -90,9 +106,11 @@ async def test_download_source_attaches_written_files(
images_root = tmp_path / "images" images_root = tmp_path / "images"
f1 = images_root / "alice" / "patreon" / "post" / "a.jpg" f1 = images_root / "alice" / "patreon" / "post" / "a.jpg"
f2 = images_root / "alice" / "patreon" / "post" / "b.jpg" f2 = images_root / "alice" / "patreon" / "post" / "b.jpg"
# Distinct colors → distinct sha256 → both attach (not deduped). # Structured h/v split → distinct sha256 AND distinct phash;
_make_jpg(f1, color=(200, 50, 50)) # also pin phash_threshold=0 so even tiny perceptual similarity
_make_jpg(f2, color=(50, 50, 200)) # between the two doesn't trigger duplicate_phash.
_make_jpg(f1, split="h")
_make_jpg(f2, split="v")
fake_gdl = _fake_gdl_with_result(_make_fake_dl_result( fake_gdl = _fake_gdl_with_result(_make_fake_dl_result(
success=True, success=True,
@@ -104,6 +122,7 @@ async def test_download_source_attaches_written_files(
sync_settings = db_sync.execute( sync_settings = db_sync.execute(
select(ImportSettings).where(ImportSettings.id == 1) select(ImportSettings).where(ImportSettings.id == 1)
).scalar_one() ).scalar_one()
sync_settings.phash_threshold = 0 # only exact phash collisions dedup
importer = Importer( importer = Importer(
session=db_sync, images_root=images_root, session=db_sync, images_root=images_root,