Skip to content

test: cover the "preferences unavailable" degradation path - #344

Merged
untraceablez merged 1 commit into
mainfrom
test/prefs-degraded-fallbacks
Aug 17, 2026
Merged

test: cover the "preferences unavailable" degradation path#344
untraceablez merged 1 commit into
mainfrom
test/prefs-degraded-fallbacks

Conversation

@untraceablez

Copy link
Copy Markdown
Collaborator

What I found

You asked why request.state.prefs was None in tests. It isn't — I had the line numbers inverted when I reported that. The middleware runs and succeeds normally; card.py:104 and search.py:71 (the prefs-populated branches) are covered. What was uncovered were the fallbacks on the next lines.

Re-reading them, the last three uncovered spots in the repo turned out to be a single coherent path split across three files:

Location Line Role
main.py 147-148 except SQLAlchemyErrorrequest.state.prefs = None
routes/card.py 105 _hist_currency cookie fallback when prefs is None
routes/search.py 72-73 _display_prefs cookie fallback when prefs is None

They're unreachable in normal tests precisely because the middleware always runs and always succeeds. _install_prefs_loader promises:

Never 500s a request over prefs: a DB hiccup (or the table not yet migrated) falls back to None, and the read helpers use their existing cookie/default path.

Nothing tested that promise. And "the table not yet migrated" is a real scenario — an instance upgraded before alembic upgrade head catches up, which is exactly when you most want pages to render.

What this adds

A fixture makes every Preferences lookup raise OperationalError, then asserts /search, /card/{id} and / still render and still honor the visitor's cookies — not just "doesn't 500", but "doesn't silently revert to defaults either":

  • /search still applies the scryme_search_filter cookie (Counterspell in, Grizzly Bears out).
  • /card/{id} still resolves scryme_hist_currency=gbp and renders £5.00.
  • / renders with no prefs cookies at all.

I verified the fixture actually bites rather than passing vacuously: under it, coverage of those three files invertsmain.py misses 143-146 instead of 147-148, card.py misses 104 instead of 105, search.py misses 71 instead of 72-73. So the tests are genuinely driving the degradation path.

Result

Repo-wide coverage is back to 100% (0 missed lines), 1179 tests. Tests only, no behavior change.

Local note: a full run can trip the known test_images.py::test_ensure_downloads_then_caches flake if SCRYME_IMAGE_CACHE_DIR has leftovers from a previous run (it sees 0 downloads). Clean cache → passes. CI starts clean so it never hits this.

🤖 Generated with Claude Code

`_install_prefs_loader` promises it "never 500s a request over prefs: a DB
hiccup (or the table not yet migrated) falls back to None, and the read
helpers use their existing cookie/default path." Nothing tested that.

The last three uncovered spots in the repo turned out to be exactly that
one path, split across three files:

- main.py 147-148       except SQLAlchemyError -> request.state.prefs = None
- routes/card.py 105     _hist_currency cookie fallback when prefs is None
- routes/search.py 72-73 _display_prefs cookie fallback when prefs is None

They are unreachable in normal tests because the middleware always runs and
always succeeds, which is also why "the table not yet migrated" — an
instance upgraded before `alembic upgrade head` catches up — was an
untested claim rather than a verified one.

A fixture makes every Preferences lookup raise OperationalError, and the
tests assert /search, /card/{id} and / still render *and still honor the
visitor's cookies* rather than 500ing or silently reverting to defaults.
Verified the fixture actually bites: under it, coverage of those files
inverts (the prefs branches go uncovered, the fallbacks get hit).

Repo-wide coverage is back to 100% (0 missed lines).

Tests only — no behavior change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@untraceablez
untraceablez merged commit 15899d5 into main Aug 17, 2026
9 checks passed
@untraceablez
untraceablez deleted the test/prefs-degraded-fallbacks branch August 17, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant