mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 01:58:41 +01:00
* chore(coherence): adopt Coherence with specs, invariants and a PR report Install @posthog/coherence as a frontend dev dependency and wire its Claude Code hooks into the committed .claude/settings.json, so every agent session in the repo gets the vocabulary, specs, journal and checks. The hooks call the binary under frontend/ through $CLAUDE_PROJECT_DIR. Declare 23 components and the entrances that carry outside trust, and six invariants, each refuted with a deliberate break before it counted: - every /api route requires auth and its scopes, except a named public list (new route sweep in tests/endpoints/test_route_guards.py) - a hidden rom, platform or firmware answers every id route exactly as a missing id would (new sweep over every method of every id route) - the unscoped save, state and screenshot fetches by id are reached only from their own routers (chokepoints) - validate_path never resolves outside its base folder The PR workflow runs in comment mode: one report comment, failing only when Coherence itself breaks. Trunk skips Prettier and markdownlint on *.spec.md and *.practice.md, since Prettier escapes their globs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(routes): satisfy mypy in the route guard sweep Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(coherence): record the worktree test database enactment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(roms): answer a hidden rom like a missing one on file routes; tighten route sweeps Addresses Greptile's review on #5584. The rom file delete and reading-progress routes answered "File not found" for a hidden rom but "Rom with id N not found" for a missing one, so a caller could tell them apart. They now raise the same not-found. The route sweeps now reach the checks they claim to test: a protected route with no scopes counts as public (its guard admits anyone), write requests carry a body and upload name so validation can't answer first, RomFile-keyed routes get a real file id, error bodies are compared with the id normalized, and the rom routes are swept with the rom hidden directly, through its platform, and by the unrated filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(coherence): tighten route guard sweeps and isolate oracle test databases (code-review) - Count a route as protected only when its endpoint is the scope-checking wrapper with non-empty scopes, not just when it declares the bearer scopes. - Treat 401 and 403 like 422 as never reaching the visibility check, and sweep /api/streaming/states/{rom_id}. - Run pytest oracles with a per-run ROMM_TEST_DB_TAG unless one is set. - Use the shared setup-frontend action and ubuntu-24.04 in the workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(tests): simplify route guard sweeps and path tests (simplify) - Mark scope-guard wrappers with required_scopes so the auth sweep reads a public attribute instead of the private closure. - Derive the entity regex from one segment list, ask each missing id once, and run the three hide scenarios through one sweep helper. - Fold the new validate_path inputs into the existing valid, traversal and absolute path tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(coherence): trim workflow comments (review-polish) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(filesystem): restore the validate_path property test the paths invariant cites Filesystem.spec.md names test_validate_path_never_escapes_its_base as the invariant's evidence, and Coherence selects it by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(coherence): run hooks from the local binary instead of npx Each hook calls frontend/node_modules/.bin/coherence directly and exits 0 when it isn't installed, so sessions without frontend deps (fresh worktrees, backend-only setups, cloud setup still installing) don't report a hook error on every tool call, and no hook pays npx's startup. Also commits the journal and run records left by earlier sessions, which .coherence/.gitignore keeps as durable records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(tests): share the bearer, user token and hide helpers Tests built the same Authorization headers and HiddenEntity rows in about 40 local copies, and two modules imported private helpers from other test files. They now use bearer, user_headers and hide from tests/auth_helpers.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(endpoints): one 404 for a missing or hidden rom, platform or firmware Each route wrote the missing-row 404 and the hidden-row 404 separately and had to keep them identical by hand. visible_rom_or_404, visible_platform_or_404 and visible_firmware_or_404 take the lookup result and raise one answer for both, either the standard not-found or a bespoke detail. Re-reads after a write keep a plain not-found check, so an edit that hides the row doesn't turn into a 404 after it succeeded. The RomFile-keyed routes (/roms/{file_id}/files, .../files/content/{name}, /roms/{file_id}/patch) name their path parameter file_id instead of id, so the route sweep reads which id a route takes from its path and drops its hand-kept list. URLs are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(setup): develop inside WSL on Windows @posthog/coherence installs only on Linux and macOS, so npm install in frontend/ fails on native Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(coherence): record the whole-repo chokepoint run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(types): regenerate API types for the file_id patch route Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
5.6 KiB
5.6 KiB
Endpoints
The FastAPI routers and Socket.IO event handlers: parse the request, check scopes and visibility, call handlers, shape the response schema.
entrances
- login: a visitor exchanges username and password over HTTP Basic for a session cookie handler: login in backend/endpoints/auth.py trust: visitor
- logout: a caller ends its login session and disconnects the sockets it opened handler: logout in backend/endpoints/auth.py trust: visitor
- token: a visitor exchanges credentials or a refresh token for OAuth2 access and refresh tokens handler: token in backend/endpoints/auth.py trust: visitor
- request password reset: a visitor asks for a reset link for a username or email handler: request_password_reset in backend/endpoints/auth.py trust: visitor
- reset password: a visitor sets a new password with a reset token handler: reset_password in backend/endpoints/auth.py trust: visitor
- login via openid: a visitor starts the OIDC login redirect handler: login_via_openid in backend/endpoints/auth.py trust: visitor
- auth openid: the OIDC provider redirects back with an authorization code that becomes a session handler: auth_openid in backend/endpoints/auth.py trust: provider
- create user from invite: a visitor creates an account from an invite token handler: create_user_from_invite in backend/endpoints/user.py trust: visitor
- exchange pair code: a device trades a short pairing code for a client token handler: exchange_pair_code in backend/endpoints/client_tokens.py trust: device
- device auth init: a device starts the device authorization flow handler: device_auth_init in backend/endpoints/device/auth.py trust: device
- device token: a device polls for and receives its token once a user approved it handler: token in backend/endpoints/device/auth.py trust: device
- heartbeat: anyone reads the server's version and public configuration handler: heartbeat in backend/endpoints/heartbeat.py trust: visitor
- metadata heartbeat: anyone checks whether one metadata provider answers, rate limited per IP handler: metadata_heartbeat in backend/endpoints/heartbeat.py trust: visitor
- retroarch sync: RetroArch and generic WebDAV clients read and write roms, saves and states through the DAV verbs, each checked by one authorizer handler: _authorize in backend/endpoints/sync/retroarch.py trust: device
invariants
- hidden entities answer as missing: A rom, platform or firmware hidden from a user, directly, through its platform or by age limit, answers every route that takes its id exactly as an id that does not exist would. over: every method of every /api route keyed on a rom, platform or firmware id, each called with a hidden id and with a missing id via: test_every_entity_route_answers_a_hidden_id_like_a_missing_one because: visibility is access control in RomM; a route that answers a hidden id differently from a missing one leaks the game, or lets the user act on it crossing: user -> storage entrances: http api kinds: read checklist: scoped-reads declared as hidden entities answer as missing checklist: redaction dismissed: no export scrubbing policy in scope
- save fetch by id stays in its router: A save is changed only by its owner and read by another user only when its owner made it public, both only while the reader can see its rom; the unscoped fetch by id is reached only from the saves router, which applies that check. protects: get_save_by_id in backend/handler/database/saves_handler.py chokepoint: backend/endpoints/saves.py because: get_save_by_id ignores the owner, so a call from any other module would serve or overwrite another user's save crossing: user -> storage kinds: read checklist: scoped-reads declared as save fetch by id stays in its router checklist: redaction dismissed: no export scrubbing policy in scope
- state fetch by id stays in its router: A state is changed only by its owner and read by another user only when its owner made it public, both only while the reader can see its rom; the unscoped fetch by id is reached only from the states router, which applies that check. protects: get_state_by_id in backend/handler/database/states_handler.py chokepoint: backend/endpoints/states.py because: get_state_by_id ignores the owner, so a call from any other module would serve or overwrite another user's state crossing: user -> storage kinds: read checklist: scoped-reads declared as state fetch by id stays in its router checklist: redaction dismissed: no export scrubbing policy in scope
- screenshot fetch by id stays in its router: A screenshot is changed only by its owner and read by another user only when its owner made it public, both only while the reader can see its rom; the unscoped fetch by id is reached only from the screenshots router, which applies that check. protects: get_screenshot_by_id in backend/handler/database/screenshots_handler.py chokepoint: backend/endpoints/screenshots.py because: get_screenshot_by_id ignores the owner, so a call from any other module would serve or overwrite another user's screenshot crossing: user -> storage kinds: read checklist: scoped-reads declared as screenshot fetch by id stays in its router checklist: redaction dismissed: no export scrubbing policy in scope
folded
- device: the device pairing and install routers
- sync: the RetroArch WebDAV router
- forms: request form models the routers share
- responses/**: the response schemas the routers return
- roms: the per-rom sub-routers (files, manuals, uploads, notes, patches)
- sockets: the Socket.IO event handlers behind the socket events and netplay events entrances