fix(cleanup): unused-tags delete must use the same predicate as the preview #87

Merged
bvandeusen merged 2 commits from dev into main 2026-06-08 18:17:50 -04:00
Showing only changes of commit df76bc0f58 - Show all commits
+14 -1
View File
@@ -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