Files
Aniworld/tests/unit
Lukas 818e621288 fix: delete folder before DB row, and add orphan-folder recovery
Two follow-ups to the previous fix that resolved the CWD-relative-path
bug in delete_series:

1. Reorder deletion: filesystem first, database second.

   When both delete_database=True and delete_folder=True were set and
   the folder delete failed (any reason — path math bug, permission
   error, missing volume, etc.), the database row was already gone by
   the time the folder delete was attempted. This left an orphan
   folder on disk that the user had no normal way to clean up — the
   delete UI returns 'Series not found' when the row is gone.

   Doing folder delete first means a folder-side failure preserves
   the DB row, so the user can retry the delete once the underlying
   issue is resolved.

2. Orphan-folder recovery: when the user requests delete_folder=True
   for a key whose DB row no longer exists, scan the configured
   anime directory for a folder that uniquely matches the key
   (normalized: strip trailing (YYYY), lowercase, remove
   hyphens/underscores/non-alphanumerics) and delete it. This
   recovers the Beyblade Burst scenario: a previous delete attempt
   removed the row but the folder stayed on disk; retrying the
   delete now cleans up the orphan.

   Safety: recovery only triggers when exactly one folder matches
   the normalized key. Zero matches → clear 'no folder matching'
   error. Multiple matches (ambiguous) → refuses to delete anything.

Adds four regression tests:
- test_delete_series_db_preserved_when_folder_fails
- test_delete_series_orphan_folder_recovery (the Beyblade Burst case)
- test_delete_series_orphan_folder_no_match
- test_delete_series_orphan_folder_ambiguous
2026-08-28 21:12:44 +02:00
..
2025-12-04 19:22:42 +01:00
2026-06-05 17:18:00 +02:00
2025-12-04 19:22:42 +01:00
2025-10-23 19:00:49 +02:00
2025-10-22 09:20:35 +02:00
2025-11-19 21:20:22 +01:00
2025-10-22 09:20:35 +02:00