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:
@@ -34,10 +34,26 @@ async def seed_artist_and_source(db, db_sync):
|
||||
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
|
||||
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(
|
||||
@@ -90,9 +106,11 @@ async def test_download_source_attaches_written_files(
|
||||
images_root = tmp_path / "images"
|
||||
f1 = images_root / "alice" / "patreon" / "post" / "a.jpg"
|
||||
f2 = images_root / "alice" / "patreon" / "post" / "b.jpg"
|
||||
# Distinct colors → distinct sha256 → both attach (not deduped).
|
||||
_make_jpg(f1, color=(200, 50, 50))
|
||||
_make_jpg(f2, color=(50, 50, 200))
|
||||
# Structured h/v split → distinct sha256 AND distinct phash;
|
||||
# also pin phash_threshold=0 so even tiny perceptual similarity
|
||||
# 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(
|
||||
success=True,
|
||||
@@ -104,6 +122,7 @@ async def test_download_source_attaches_written_files(
|
||||
sync_settings = db_sync.execute(
|
||||
select(ImportSettings).where(ImportSettings.id == 1)
|
||||
).scalar_one()
|
||||
sync_settings.phash_threshold = 0 # only exact phash collisions dedup
|
||||
|
||||
importer = Importer(
|
||||
session=db_sync, images_root=images_root,
|
||||
|
||||
Reference in New Issue
Block a user