[PR #185] [MERGED] [cache] Reset a broken cache file instead of crashing, run clean-cache through a use case #182

Closed
opened 2026-10-13 19:48:30 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Glitchy-Sheep/boosty-downloader/pull/185
Author: @Glitchy-Sheep
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @Glitchy-Sheep

Base: main ← Head: fix/cache-reinit-and-clean-cache


📝 Commits (2)

  • 9629a36 [cache] Reset a broken cache file on open instead of crashing
  • b0d2e86 [cli] Run clean-cache through a use case without opening the database

📊 Changes

12 files changed (+249 additions, -90 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 boosty_downloader/application/ports.py (+8 -0)
➕ boosty_downloader/application/use_cases/clean_cache.py (+34 -0)
📝 boosty_downloader/cli/commands/clean_cache.py (+15 -39)
📝 boosty_downloader/cli/composition_root.py (+12 -8)
📝 boosty_downloader/infrastructure/post_caching/post_cache.py (+20 -20)
➕ boosty_downloader/infrastructure/post_caching/storage.py (+33 -0)
📝 test/e2e/credentials_scope_test.py (+2 -9)
📝 test/unit/cli/cli_smoke_test.py (+24 -0)
➕ test/unit/post_caching/cache_storage_test.py (+50 -0)
📝 test/unit/post_caching/post_cache_test.py (+11 -14)
➕ test/unit/use_cases/clean_cache_test.py (+36 -0)

📄 Description

📝 Summary

Audit stage 3, part 2 of 3: the cache stops crashing on a broken file, and clean-cache joins the other commands in shape.

🔧 What changes

Fixed

  • A post_cache.db that is not a SQLite database (truncated, overwritten, hand-edited) used to crash the run with DatabaseError: file is not a database. It now resets with the same warning an outdated schema already got. This was the one strict xfail in the suite; it is a regular test now.
  • After a reset the cache session stayed bound to the disposed engine and worked only because both pointed at the same file. _connect now builds the engine, the session factory and the session together.
  • clean-cache failed with RuntimeError: no running event loop after #184: load_settings built an aiohttp.CookieJar, which needs a running loop, and clean-cache is the only sync command. AppSettings keeps the auth header and the cookie as strings; aiohttp objects are built inside open_app.

Changed

  • clean-cache runs through CleanCacheUseCase over a CacheStorage port. SQLiteCacheStorage works on the files only: it never opens the database, so a missing cache is reported instead of being created and "cleaned". The folder is dropped only when nothing else is in it; downloaded posts next to the cache survive.
  • remove_cache_completely is gone from SQLitePostCache: the command was its only user.

🧪 Tests

  • Corrupted-file reset, session binding after a reset, SQLiteCacheStorage on tmp_path (exists, empty folder removed, folder with posts kept, no-op on a missing cache), CleanCacheUseCase on a fake storage, and a CLI smoke that runs clean-cache end to end with a temporary config and no event loop.
  • task ci green locally: ruff, pyright strict, 246 tests + e2e.
  • Live: a garbage post_cache.db in a scratch cache dir makes check print "corrupted or inaccessible. Reinitializing..." and finish with exit 0; clean-cache twice in a row says "cleaned" then "nothing to clean", keeps a folder that holds a post, removes an empty one; download --dry-run afterwards still reaches the API with the credentials.

⏭️ Next

PR 3: DownloadContentTypeFilter into domain and an import-linter layers contract in CI.

✅ Checklist

  • Tested live on a real blog (feature or fix)
  • Updated CLI --help and README if needed
  • Updated docs/ if the download flow or dev process changed
  • Added a line to ## Unreleased in CHANGELOG.md (or the ci/skip-changelog label if not user-facing)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Glitchy-Sheep/boosty-downloader/pull/185 **Author:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Created:** 9/13/2026 **Status:** ✅ Merged **Merged:** 9/13/2026 **Merged by:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Base:** `main` ← **Head:** `fix/cache-reinit-and-clean-cache` --- ### 📝 Commits (2) - [`9629a36`](https://github.com/Glitchy-Sheep/boosty-downloader/commit/9629a36d96eb80e898f0990a819a3778d8bb8538) [cache] Reset a broken cache file on open instead of crashing - [`b0d2e86`](https://github.com/Glitchy-Sheep/boosty-downloader/commit/b0d2e86242dc6ef70a366b84b8c95e72a260699a) [cli] Run clean-cache through a use case without opening the database ### 📊 Changes **12 files changed** (+249 additions, -90 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `boosty_downloader/application/ports.py` (+8 -0) ➕ `boosty_downloader/application/use_cases/clean_cache.py` (+34 -0) 📝 `boosty_downloader/cli/commands/clean_cache.py` (+15 -39) 📝 `boosty_downloader/cli/composition_root.py` (+12 -8) 📝 `boosty_downloader/infrastructure/post_caching/post_cache.py` (+20 -20) ➕ `boosty_downloader/infrastructure/post_caching/storage.py` (+33 -0) 📝 `test/e2e/credentials_scope_test.py` (+2 -9) 📝 `test/unit/cli/cli_smoke_test.py` (+24 -0) ➕ `test/unit/post_caching/cache_storage_test.py` (+50 -0) 📝 `test/unit/post_caching/post_cache_test.py` (+11 -14) ➕ `test/unit/use_cases/clean_cache_test.py` (+36 -0) </details> ### 📄 Description ## 📝 Summary Audit stage 3, part 2 of 3: the cache stops crashing on a broken file, and `clean-cache` joins the other commands in shape. ## 🔧 What changes **Fixed** - A `post_cache.db` that is not a SQLite database (truncated, overwritten, hand-edited) used to crash the run with `DatabaseError: file is not a database`. It now resets with the same warning an outdated schema already got. This was the one strict xfail in the suite; it is a regular test now. - After a reset the cache session stayed bound to the disposed engine and worked only because both pointed at the same file. `_connect` now builds the engine, the session factory and the session together. - `clean-cache` failed with `RuntimeError: no running event loop` after #184: `load_settings` built an `aiohttp.CookieJar`, which needs a running loop, and `clean-cache` is the only sync command. `AppSettings` keeps the auth header and the cookie as strings; aiohttp objects are built inside `open_app`. **Changed** - `clean-cache` runs through `CleanCacheUseCase` over a `CacheStorage` port. `SQLiteCacheStorage` works on the files only: it never opens the database, so a missing cache is reported instead of being created and "cleaned". The folder is dropped only when nothing else is in it; downloaded posts next to the cache survive. - `remove_cache_completely` is gone from `SQLitePostCache`: the command was its only user. ## 🧪 Tests - Corrupted-file reset, session binding after a reset, `SQLiteCacheStorage` on tmp_path (exists, empty folder removed, folder with posts kept, no-op on a missing cache), `CleanCacheUseCase` on a fake storage, and a CLI smoke that runs `clean-cache` end to end with a temporary config and no event loop. - `task ci` green locally: ruff, pyright strict, 246 tests + e2e. - Live: a garbage `post_cache.db` in a scratch cache dir makes `check` print "corrupted or inaccessible. Reinitializing..." and finish with exit 0; `clean-cache` twice in a row says "cleaned" then "nothing to clean", keeps a folder that holds a post, removes an empty one; `download --dry-run` afterwards still reaches the API with the credentials. ## ⏭️ Next PR 3: `DownloadContentTypeFilter` into domain and an import-linter layers contract in CI. ## ✅ Checklist - [x] Tested live on a real blog (feature or fix) - [x] Updated CLI `--help` and README if needed - [x] Updated `docs/` if the download flow or dev process changed - [x] Added a line to `## Unreleased` in CHANGELOG.md (or the `ci/skip-changelog` label if not user-facing) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-13 19:48:30 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Glitchy-Sheep/boosty-downloader#182
No description provided.