~150 HTTPExceptions carried a hand-written English sentence as their detail,
shown verbatim under the Hungarian UI — in the blocking error dialog and on
every inline surface that printed HttpError.detail (sign-in, setup wizard,
change password, the passphrase gate, live search). Four also quoted an
upstream exception's text back to the user.
- app/refusal.py: `refused(status, reason, **params)` → {code: "refused",
reason, …params}; localizeDetail translates errors.refused.<reason> with the
params interpolated. "Unknown X" 404s use the existing not_found(what).
- sysconfig.set_value raises InvalidSetting (reason + bounds) instead of an
English ValueError; the three writers answer it through setting_refused.
- The Plex connection/write/image failures log what the upstream said and
answer a reason; the search scraper's failure is logged and answered as
youtube/unavailable (it crashed refusal_reason before).
- HttpError.detail now only ever holds a translated reason: a string detail
(only the framework's own can remain) is left out, so reading .detail is
safe everywhere — including destructured, the hole the raw-detail source
scan could not see. That scan and its five-file exception list are gone.
- Enforced: test_http_details.py fails on any HTTPException with a sentence
for a detail; the contract test requires every refused reason and every
not_found "what" in both languages, and no key for one that is gone.
- local/jsx-comment-text: a // inside JSX children renders as text; the rule
is ten lines in eslint.config.js rather than eslint-plugin-react's ~1800
lockfile lines.
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
"""Feed cursor endpoint: a malformed ?cursor= must be a clean HTTP 400, not a 500.
|
|
|
|
Locks the refactor that split cursor handling across modules — feedquery.decode_cursor raises a
|
|
plain ValueError and routes/feed.get_feed translates it to 400 — so a future regression (a dropped
|
|
try/except, or a new decode_cursor caller without its own catch) turns the 400 back into a 500 and
|
|
fails right here. DB lane (`db` fixture) — skipped without Postgres.
|
|
"""
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
import app.state as state
|
|
from app.auth import current_user
|
|
from app.db import get_db
|
|
from app.main import app
|
|
from app.models import User
|
|
|
|
|
|
def _get(db, user, monkeypatch, path):
|
|
monkeypatch.setattr(
|
|
state, "_configured_cache", True
|
|
) # the request gate 503s an unconfigured app
|
|
app.dependency_overrides[get_db] = lambda: db
|
|
app.dependency_overrides[current_user] = lambda: user
|
|
try:
|
|
client = TestClient(app) # no context manager: skip lifespan (scheduler/HLS sweep)
|
|
return client.get(path)
|
|
finally:
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
def test_malformed_feed_cursor_returns_400(db, monkeypatch):
|
|
user = User(email="feedcursor@example.com")
|
|
db.add(user)
|
|
db.commit()
|
|
resp = _get(db, user, monkeypatch, "/api/feed?cursor=not-a-real-cursor")
|
|
assert resp.status_code == 400
|
|
assert resp.json()["detail"] == {"code": "refused", "reason": "invalid_cursor"}
|
|
|
|
|
|
def test_feed_without_cursor_is_200(db, monkeypatch):
|
|
# Sanity: the same endpoint without a cursor is a normal 200 (proves the 400 above is the
|
|
# cursor path, not a globally-broken request). A fresh user has no subscriptions → empty feed.
|
|
user = User(email="feednocursor@example.com")
|
|
db.add(user)
|
|
db.commit()
|
|
resp = _get(db, user, monkeypatch, "/api/feed")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["items"] == []
|