From 65bd1c22c3fe15a9156ecaab3a891ada422a011a Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 3 Jul 2026 08:40:11 -0400 Subject: [PATCH] test: whole-table tag counts become non-system counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The four remaining run-1895 failures were stale expectations, not predicate bugs — prune/reset returned the right counts, but these tests verified no-deletion by counting the ENTIRE tag table (or asserting the full kind set), which now includes the three seeded hygiene tags that survive prunes and resets by design. Filter is_system=false with a pointer to #128 so future system tags cannot re-break them. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM --- tests/test_api_admin.py | 4 +++- tests/test_cleanup_service.py | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/test_api_admin.py b/tests/test_api_admin.py index 0378585..230e27e 100644 --- a/tests/test_api_admin.py +++ b/tests/test_api_admin.py @@ -660,8 +660,10 @@ async def test_reset_content_tagging_apply_requires_confirm_token(client, db): for bad in ({"dry_run": False}, {"dry_run": False, "confirm": "deadbeef"}): resp = await client.post("/api/admin/tags/reset-content", json=bad) assert resp.status_code == 400 + # Non-system only: the seeded hygiene tags (#128) survive a reset by + # design, so they'd inflate a whole-table count. remaining = (await db.execute( - select(func.count()).select_from(Tag) + select(func.count()).select_from(Tag).where(Tag.is_system.is_(False)) )).scalar_one() assert remaining == 1 diff --git a/tests/test_cleanup_service.py b/tests/test_cleanup_service.py index 8b6dab3..e2a89f6 100644 --- a/tests/test_cleanup_service.py +++ b/tests/test_cleanup_service.py @@ -377,8 +377,11 @@ def test_prune_unused_tags_dry_run_returns_count_and_names(db_sync, tmp_path): assert result["count"] == 2 assert "prune-me-1" in result["sample_names"] assert "prune-me-2" in result["sample_names"] - # Nothing actually deleted. - surviving = db_sync.execute(select(func.count(Tag.id))).scalar_one() + # Nothing actually deleted. Non-system only — the seeded hygiene tags + # (#128) are exempt from pruning and would inflate a whole-table count. + surviving = db_sync.execute( + select(func.count(Tag.id)).where(Tag.is_system.is_(False)) + ).scalar_one() assert surviving == 3 @@ -499,8 +502,11 @@ def test_reset_content_tagging_dry_run_counts_without_deleting(db_sync, tmp_path assert result["count"] == 2 assert result["by_kind"] == {"general": 1, "character": 1} assert result["applications"] == 2 - # Nothing deleted — all 4 tags still present. - assert db_sync.execute(select(func.count(Tag.id))).scalar_one() == 4 + # Nothing deleted — all 4 fixture tags still present (non-system count; + # the seeded hygiene tags #128 also survive, by design). + assert db_sync.execute( + select(func.count(Tag.id)).where(Tag.is_system.is_(False)) + ).scalar_one() == 4 def test_reset_content_tagging_deletes_content_keeps_fandom_series(db_sync, tmp_path): @@ -525,8 +531,11 @@ def test_reset_content_tagging_deletes_content_keeps_fandom_series(db_sync, tmp_ result = cleanup_service.reset_content_tagging(db_sync, dry_run=False) assert result["deleted"] == 2 - # general + character gone; fandom + series kept. - kinds = db_sync.execute(select(Tag.kind)).scalars().all() + # general + character gone; fandom + series kept. Non-system only — the + # seeded hygiene tags (#128, kind=general) survive a reset by design. + kinds = db_sync.execute( + select(Tag.kind).where(Tag.is_system.is_(False)) + ).scalars().all() kind_vals = {k.value if hasattr(k, "value") else str(k) for k in kinds} assert kind_vals == {"fandom", "series"} # series_page ordering survived.