* 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>
States gain a nullable `core` column (migration 0141). A pulled state keeps
the core the broker names in its X-State-Core header, and a pushed state
names its core on the way down so a broker running another one refuses it.
NULL keeps meaning the platform's default core, which wrote every state
stored before cores were recorded.
- A label longer than the request limit no longer becomes a container's
name, so every published name is one the desktop endpoint accepts. The
limit moves to handler.streaming.config as CONTAINER_NAME_MAX_LENGTH.
- A label equal to another container's key in any case no longer names
its container, matching the case-insensitive lookup.
- An oversized broker manifest now fails the import build instead of
being dropped, which lost the state typing of the base's entries.
- A broker error body is read against a 5 second deadline, like every
other broker read.
- Type the _labelled test helper.
Security (from the step 1 audit):
- Inflate zip entries a chunk at a time, so an entry whose header
understates its size fails the CRC check instead of inflating in full.
- Cap the broker manifest at 1 MiB before reading it.
- Rebuild copied entries as regular files, keeping only permission bits,
so a symlink entry cannot ride into the container.
Code review (xhigh):
- Bound the broker error body read at 1 MiB and truncate what is logged
and returned.
- De-duplicate refusal hints in Stream.vue.
- Unpack only save members as zips; a zip-shaped state stays whole.
- Pick the newest state off an archive by created_at.
- Run newest_restorable off the event loop.
- Name a carried base entry by its staged path in the manifest.
- build ImportRefusalSchema directly in the broker, dropping the mirror dataclass and the asdict conversion
- replace the resume_via_import/resume_needs_import pair with one ResumeImport literal
- stage base and foreign zips through a shared helper, parse each member once, and read the base only when something is imported
- ImportSpec.kinds is a set of names, and a successful import-spec answer is cached briefly so one claim asks once
- show the suggested emulator's display name in the refusal hint
- trim long comments and the dangling spec reference
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The magic-byte test moves behind `_is_png`, so the two places that need it (the
broker body, where the answer decides whether the embedded frame is tried, and
the filesystem sink) read as one rule instead of two. Narrowing the extract
catch back to the failures a savestate archive can raise keeps a programming
error loud rather than logging it as a missing thumbnail.
The frame fetch gets its own 10s deadline: it runs while the claim is still
held and the player waits on the exit screen, and a thumbnail does not need the
archive-transfer budget.
From the pr-ready simplify pass.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
endpoints/streaming.py had grown to 3778 lines, but only about a third of
that was routes. The rest was a second copy of the layer handler/streaming
already exists to hold: broker verbs, webstation protocol translation,
state and save and memory-card transfer, session teardown.
Split it along those seams rather than by route, and give claim_session
the same treatment: its 406 lines are now four named phases.
Cross-module calls go through the module (states.pull_state_to_library,
commands.stop) instead of imported names, so one definition site is what
tests patch and what every caller reads.
No route path, scope or response model changed, so the OpenAPI schema is
untouched.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- The five new modules each defined `log = logging.getLogger("romm")`, which is
what `logger.logger` already exports; they import it now.
- `ACK_TIMEOUT` had two homes. It is a protocol fact, so `protocol.py` owns it
and the endpoint imports it from there; the unused
`BROKER_LOAD_STATE_TIMEOUT` copy goes.
- Module and function docstrings trimmed to what the code cannot say: the
change history and the justifications belong in the commit messages they came
from.
- `asset_store` takes the union `write_file` accepts rather than `Any`.
- Four hand-rolled `setInterval` pairs (presence beat, session poll, exit
chord, live sessions, activity tick) become `useIntervalFn`, which also
cleared a real gap: the presence composable's timer had no scope teardown.
- The launch pushes are matched on the container the claim's 202 named, not on
the platform: a pool serves one platform from more than one container, so a
second tab could otherwise act on the first's launch.
- Test helpers typed: the push capture and the resume-claim tuple carry real
types, and an unused `_claim_ready` helper goes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`endpoints/streaming.py` held a general-purpose Redis session store and an HTTP
client alongside its routes, so both were reachable only through the ASGI test
client and neither could serve a second caller. They now sit in
`handler/streaming/` next to the container and protocol modules, matching how
`handler/netplay_handler.py` already owns its Redis room state.
- `session_store.py`: the keys, TTLs, compare-and-set helpers, drain markers,
staleness rule and termination notices. Its names are public now, because the
module boundary is the privacy boundary.
- `broker.py`: the urllib transport, its bounded reads and byte caps, and the
translation of a transport failure into the 502/503 the frontend parses.
The endpoint module drops from 5157 lines to 3616 and keeps the routes, the
claim and teardown flows, and the asset sync.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>