fix(test): archive members need structured imgs+threshold0; provenance payload gained attachments key

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-19 11:22:17 -04:00
parent cba662a900
commit 7dea165fae
2 changed files with 23 additions and 3 deletions
+20 -2
View File
@@ -48,13 +48,31 @@ def _jpeg_bytes(color):
return buf.getvalue()
def _split_bytes(orient):
"""Structured half/half image — solid colors phash-collapse (distance
0); orthogonal splits are distinct only at phash_threshold=0 (see
reference-phash-test-images)."""
im = Image.new("L", (256, 256), 0)
px = im.load()
for y in range(256):
for x in range(256):
if (x / 256 if orient == "v" else y / 256) >= 0.5:
px[x, y] = 255
buf = io.BytesIO()
im.convert("RGB").save(buf, "JPEG")
return buf.getvalue()
def test_archive_imports_members_and_stores_archive(importer, import_layout):
import_root, _ = import_layout
# Distinct structure + threshold 0 so BOTH members import (solid
# colors would phash-collapse; reference-phash-test-images).
importer.settings.phash_threshold = 0
arc = import_root / "Bob" / "set.cbz"
arc.parent.mkdir(parents=True, exist_ok=True)
with zipfile.ZipFile(arc, "w") as zf:
zf.writestr("a.jpg", _jpeg_bytes((200, 10, 10)))
zf.writestr("b.jpg", _jpeg_bytes((10, 200, 10)))
zf.writestr("a.jpg", _split_bytes("v"))
zf.writestr("b.jpg", _split_bytes("h"))
zf.writestr("readme.txt", b"hello")
arc.with_suffix(".cbz.json").write_text(json.dumps(
{"category": "patreon", "id": "777", "title": "Set"}))
+3 -1
View File
@@ -58,7 +58,9 @@ async def test_for_image_no_provenance_returns_empty_list(db):
rec = await _seed_image(db)
svc = ProvenanceService(db)
payload = await svc.for_image(rec.id)
assert payload == {"image_id": rec.id, "provenance": []}
assert payload == {
"image_id": rec.id, "provenance": [], "attachments": []
}
@pytest.mark.asyncio