From df76bc0f583e088fbbc29162d5b813463ad3773d Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Mon, 8 Jun 2026 18:09:27 -0400 Subject: [PATCH] =?UTF-8?q?test(cleanup):=20fix=20prune-spares-fandom=20fi?= =?UTF-8?q?xture=20=E2=80=94=20used=20character=20keeps=20fandom=20alive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The character pointing at the fandom had no image associations, so it was itself unused and inflated the dry-run count to 2. Tag it on a real image so it is used (the real-world shape) — the fandom survives via a live character. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/test_cleanup_service.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_cleanup_service.py b/tests/test_cleanup_service.py index b883ba9..4a0c420 100644 --- a/tests/test_cleanup_service.py +++ b/tests/test_cleanup_service.py @@ -362,7 +362,9 @@ def test_prune_unused_tags_commit_deletes_them(db_sync, tmp_path): assert "bye" not in surviving_names -def test_prune_unused_tags_commit_spares_fandom_and_chaptered_series(db_sync): +def test_prune_unused_tags_commit_spares_fandom_and_chaptered_series( + db_sync, tmp_path, +): # The LIVE delete (not just the preview) must use the same predicate — it # previously had only the image_tag/series_page checks and deleted every # fandom the preview correctly excluded (operator-flagged 2026-06-08, real @@ -370,6 +372,16 @@ def test_prune_unused_tags_commit_spares_fandom_and_chaptered_series(db_sync): fandom = _make_tag(db_sync, name="Creux", kind=TagKind.fandom) char = _make_tag(db_sync, name="OcChar", kind=TagKind.character) char.fandom_id = fandom.id + # The character itself is used (tagged on an image) — that is the real-world + # shape: characters survive on their image_tag rows, and the fandom they + # point at must survive with them. + a = _make_artist(db_sync, slug="psf") + img = _make_image( + db_sync, artist=a, path=str(tmp_path / "c.jpg"), sha256="d" * 64, + ) + db_sync.execute(image_tag.insert().values( + image_record_id=img.id, tag_id=char.id, + )) series = _make_tag(db_sync, name="EmptySeries", kind=TagKind.series) db_sync.add(SeriesChapter(series_tag_id=series.id, chapter_number=1)) _make_tag(db_sync, name="GenuinelyUnused") @@ -381,6 +393,7 @@ def test_prune_unused_tags_commit_spares_fandom_and_chaptered_series(db_sync): assert result["deleted"] == 1 surviving = db_sync.execute(select(Tag.name)).scalars().all() + assert "OcChar" in surviving # used character assert "Creux" in surviving # fandom referenced by a character assert "EmptySeries" in surviving # series referenced by a chapter assert "GenuinelyUnused" not in surviving