mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
* test(api): check returned and forwarded error statuses too The route error check only saw HTTPException with a literal status. It now also counts error responses a route returns, statuses passed to a helper, status maps, IfExp and local variables. A status it still cannot read fails the check instead of passing silently. Routes left out of the schema are skipped, and 422 counts as documented only when FastAPI documents it. The API description now names the middleware errors no route lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(api): fail on documented statuses a route cannot raise Add a stale check, the reverse of the undocumented one. To keep its false positives near zero, the analyzer now follows functions run through asyncio.to_thread and similar offloads, and skips a try body whose handler swallows every error (keeping the responses it returns). A new `# route-errors: raises <codes>` marker declares what a line raises when the analyzer cannot follow or read it. Following offloads found an undocumented 502 on save-and-exit: a container with no broker address fails the card wipe. search_cover declares the SteamGridDB 401 it re-raises from a gather. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: code-review Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: simplify Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: review-polish Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: plain-prose Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: code-review (best-effort broker PUT never raises) put_binary_json looked up the broker URL outside its try, so a container with no broker address raised a 502 from a helper documented as never raising. Evacuation already fails first on that container, so the 502 documented on save-and-exit could not happen; drop it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: plain-prose (code-review additions) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * pr-ready: review-polish (build a real container in the broker test) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
"""Checks that the OpenAPI document describes every operation."""
|
|
|
|
from main import app
|
|
from tools.route_errors import UNREADABLE_STATUS, stale, undocumented
|
|
|
|
HTTP_METHODS = ("get", "post", "put", "patch", "delete", "head")
|
|
|
|
|
|
def test_every_operation_has_a_description():
|
|
# Arrange
|
|
spec = app.openapi()
|
|
|
|
# Act
|
|
problems = [
|
|
f"{method.upper()} {path}"
|
|
for path, item in spec["paths"].items()
|
|
if path.startswith("/api/")
|
|
for method, operation in item.items()
|
|
if method in HTTP_METHODS and not (operation.get("description") or "").strip()
|
|
]
|
|
|
|
# Assert
|
|
assert (
|
|
not problems
|
|
), f"{len(problems)} operations without a description:\n" + "\n".join(problems)
|
|
|
|
|
|
def test_raised_statuses_are_documented():
|
|
# Act
|
|
gaps = undocumented(app.routes)
|
|
|
|
# Assert
|
|
assert not gaps, (
|
|
"These routes raise or return statuses their `responses=` does not describe."
|
|
" Document each one, or mark code whose errors never reach the client with"
|
|
f" `# route-errors: ignore`. A status of {UNREADABLE_STATUS} is one the"
|
|
" analyzer cannot read: use a literal status, or declare the statuses the"
|
|
" line can take with `# route-errors: raises <codes>`:\n"
|
|
+ "\n".join(f"{route} {codes}" for route, codes in gaps.items())
|
|
)
|
|
|
|
|
|
def test_documented_statuses_are_raised():
|
|
# Act
|
|
gaps = stale(app.routes)
|
|
|
|
# Assert
|
|
assert not gaps, (
|
|
"These routes document statuses they cannot raise. Remove each entry, or,"
|
|
" if the route does raise it in a way the analyzer cannot follow, declare"
|
|
" it on the line that raises it with `# route-errors: raises <codes>`:\n"
|
|
+ "\n".join(f"{route} {codes}" for route, codes in gaps.items())
|
|
)
|