test(cleanup): fix prune-spares-fandom fixture — used character keeps fandom alive
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) <noreply@anthropic.com>
This commit is contained in:
@@ -362,7 +362,9 @@ def test_prune_unused_tags_commit_deletes_them(db_sync, tmp_path):
|
|||||||
assert "bye" not in surviving_names
|
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
|
# 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
|
# previously had only the image_tag/series_page checks and deleted every
|
||||||
# fandom the preview correctly excluded (operator-flagged 2026-06-08, real
|
# 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)
|
fandom = _make_tag(db_sync, name="Creux", kind=TagKind.fandom)
|
||||||
char = _make_tag(db_sync, name="OcChar", kind=TagKind.character)
|
char = _make_tag(db_sync, name="OcChar", kind=TagKind.character)
|
||||||
char.fandom_id = fandom.id
|
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)
|
series = _make_tag(db_sync, name="EmptySeries", kind=TagKind.series)
|
||||||
db_sync.add(SeriesChapter(series_tag_id=series.id, chapter_number=1))
|
db_sync.add(SeriesChapter(series_tag_id=series.id, chapter_number=1))
|
||||||
_make_tag(db_sync, name="GenuinelyUnused")
|
_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
|
assert result["deleted"] == 1
|
||||||
|
|
||||||
surviving = db_sync.execute(select(Tag.name)).scalars().all()
|
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 "Creux" in surviving # fandom referenced by a character
|
||||||
assert "EmptySeries" in surviving # series referenced by a chapter
|
assert "EmptySeries" in surviving # series referenced by a chapter
|
||||||
assert "GenuinelyUnused" not in surviving
|
assert "GenuinelyUnused" not in surviving
|
||||||
|
|||||||
Reference in New Issue
Block a user