Commit Graph

728 Commits

Author SHA1 Message Date
Georges-Antoine Assi
1027cc3832 Merge pull request #4852 from rommapp/fix/7z-hash-timeout-scales-with-size
fix(scan): raise the 7-Zip timeout default and keep partial bytes out of the fallback hash
2026-09-28 08:08:07 -04:00
Georges-Antoine Assi
847b222b3f fix(scan): keep partial 7z member bytes out of the raw-archive hash
When extracting the largest member of a .7z failed partway, the bytes already
streamed stayed in the file and ROM-level hashers, and the raw-archive
fallback was appended on top, giving a hash that matched neither. The hashers
are now restored to their pre-extraction state before the fallback runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 07:53:39 -04:00
Georges-Antoine Assi
5f244afe8f Merge pull request #4851 from rommapp/fix/validate-emulator-path-segment
fix(assets): reject emulator names that are not a single folder on upload
2026-09-28 07:48:30 -04:00
Sam Dornan
29220cd59e fix(backend): restart the log forwarder and harden three Redis call sites (#4847) 2026-09-27 20:10:06 -04:00
Georges-Antoine Assi
2b4dfebab5 fix(mypy): drop redis generic args after the stubs upgrade
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:28:47 -04:00
Georges-Antoine Assi
41767a6a44 Merge remote-tracking branch 'origin/master' into feat/device-push-install 2026-09-27 16:13:58 -04:00
Sam Dornan
452b52cbae chore(mypy): replace type-ignore defaults with typed injection sentinels (#4843) 2026-09-27 15:51:50 -04:00
Georges-Antoine Assi
96e2c2ad42 refactor(backend): pr-ready follow-ups for device installs
- Replace the inline bytes-to-text decodes with redis_handler.as_text
- Add utils.auth.token_device_id for a request's token-bound device
- Look up a group's member tokens in one query and close them in one pass

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:04:56 -04:00
Georges-Antoine Assi
bb0de382bb fix(assets): reject emulator names that are not a single folder on upload
POST /api/saves and POST /api/states joined the `emulator` query parameter
straight into the asset path, so a value like `a/b` created nested
directories and landed in file_path. Both endpoints now return 400 unless
the name survives sanitize_filename unchanged, and cap it at the column
length so an over-long value is a 422 instead of a database error.

Fixes #4839

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 14:47:33 -04:00
Sam Dornan
146464551b perf(scan): download a rom's media files concurrently (#4842)
* perf(scan): download a rom's media files concurrently

download_rom_resources fetched the cover, manual, each screenshot, each
provider media type and every RetroAchievements badge one after another,
so a single ROM never used more than one of the ScreenScraper account's
request slots.

They now download together. ScreenScraper media still goes through its
existing thread and rate limiters, and badges share a new cap of 8 in
flight across all scans. The path columns and changed provider media
dicts are written back in one update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

* style(tests): sort imports with the Trunk isort config

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

* fix(scan): code-review fixes for concurrent media downloads

- Run provider media dicts one after another, since they share paths
- Await every download before raising the first failure (gather_all)
- Fetch each duplicate media or badge path once (store_ra_badges)
- Reuse store_ra_badges in update_rom
- Share the in-flight test helper and trim comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

* refactor(scan): simplify pass on concurrent media downloads

- Move gather_all to utils/concurrency and unpack its results directly
- Let write_file_streamed create the badge directory instead of every badge
- Share the in-flight test helper through tests/concurrency_stubs
- Stub downloads with AsyncMock through one fixture, drop a redundant test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

* fix(scan): save the paths that landed when a provider download fails

Cover, manual and screenshot paths are written before a provider media or
badge failure is re-raised, so a failure there no longer loses them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

* fix(scan): save each download group's results independently

Paths, provider media and badges each keep their own outcome, and every
change that landed is written before the first failure is re-raised. The
test builds a real Rom instead of a namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DAQNWjH7teMsMkFMuUrLTf

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:35:21 -05:00
Sam Dornan
6b13fd1698 chore(deps): bump redis to 8.1 and fakeredis to 2.38, drop types-redis (#4844)
* chore(deps): bump redis to 8.1 and fakeredis to 2.38

redis-py 6.2.0 -> 8.1.0 and fakeredis 2.30.1 -> 2.38.0. RQ 2.12
(redis!=6,>=3.5) and fakeredis (redis>=4.3) both accept redis 8.

fakeredis 2.38 types FakeServer's version argument as a tuple, so pass
(7,) instead of 7. Behaviour is unchanged since fakeredis normalises an
int to a one-element tuple.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx

* chore(deps): drop types-redis in favour of redis-py's own types

types-redis only covers redis 4.6 and shadowed the inline types that
redis 8 ships, so mypy was checking calls against a stale API. Removing
it also drops its transitive stub packages (types-cffi, types-pyopenssl,
types-setuptools), which nothing else uses.

redis-py's types differ from the stubs in three ways:
- Redis, AsyncRedis and Pipeline are not generic, so drop the [str] and
  [bytes] parameters.
- Responses are typed bytes | str regardless of decode_responses, so cast
  at the few call sites that rely on the decoded (or raw) type.
- watch, unwatch, multi, aclose and execute_command are unannotated, so
  add redis to untyped_calls_exclude, as is done for rq and apprise.

Also replace setex, deprecated in redis 8, with set(..., ex=...).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx

* fix(device-auth): replace deprecated GETSET with SET ... GET

code-review step. GETSET is deprecated since Redis 6.2 in favour of
SET with GET. Using it with ex= also sets the poll key's TTL in the same
command, instead of a separate EXPIRE that a crash could skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 13:28:09 -05:00
Sam Dornan
23191407c1 chore(backend): replace zstandard with stdlib compression.zstd (#4831) 2026-09-26 21:20:34 -04:00
Sam Dornan
3206bc541f chore(deps): move from httpx to httpx2 (#4830) 2026-09-26 21:17:13 -04:00
Sam Dornan
e0df54cba5 chore(backend): enforce mypy's disallow_untyped_calls and disallow_untyped_decorators (#4827) 2026-09-26 20:21:54 -04:00
Sam Dornan
7c2b049b70 chore(mypy): drop warn_return_any and validate provider responses with strict JSON (#4826) 2026-09-26 20:13:55 -04:00
Sam Dornan
84726ba9a2 refactor(backend): move FORCE INDEX hint and FULLTEXT match into sql_dialect (#4825) 2026-09-26 19:08:25 -04:00
Sam Dornan
5a6c895d33 chore(mypy): give every generic its type arguments (#4818)
* chore(mypy): switch to strict mode with listed exceptions

Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.

That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
  sites patched a dependency through the module that imported it
  (`scan_module.fs_rom_handler`); they now import the same object from
  its source, so every patch targets what it did before. Tests that
  replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
  explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
  dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
  NotRequired dump_* keys spelled out, and the media dict never has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* chore(mypy): give every generic its type arguments

Drop disallow_any_generics from the strict-mode exceptions and fix the
347 bare generics it reports, 230 of them in app code.

- Bare `dict` becomes `dict[str, Any]`: update payloads, raw provider
  JSON and endpoint bodies map string keys to mixed values, so the Any is
  real and now written down. The OpenAPI document is unchanged.
- Rom query filters take and return RomSelect; _music_facet_joins and
  _exclude_hidden are generic over the Select they're given, and
  _build_hash_selects returns id-only selects.
- Redis clients are typed by what they return: the decoding caches are
  Redis[str], the RQ connection and binary cache Redis[bytes].
- The rest get explicit parameters: Row, Pattern, ColumnElement,
  QueryableAttribute, SpooledTemporaryFile, Task, Future and friends.

Precise types reached callers that had been getting Any, which surfaced:
- The LaunchBox cache writer is fed binary-cache pipelines.
- The flashpoint and IGDB request helpers return raw JSON of varying
  shape, not always a dict.
- The rom search endpoint returned dicts under a list[SearchRomSchema]
  annotation; it now validates them into that schema.
- The audit filter's id subquery selects strings.
- In tests the binary cache is the non-decoding fake shared with
  async_cache, so it is cast to Redis[bytes] rather than changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* test(upload): assert cleanup against the patched upload directory

The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

* chore(mypy): keep the row type through the ROM filter helpers

filter_roms and its helpers also receive select(Rom.id) membership queries,
so they now take and return the caller's Select type instead of narrowing to
RomSelect. merged_ra_metadata mixes scalar and list values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 16:32:29 -05:00
Georges-Antoine Assi
8c3874a5b0 Merge remote-tracking branch 'origin/master' into HEAD
# Conflicts:
#	backend/tests/endpoints/test_saves.py
2026-09-26 16:08:30 -04:00
Sam Dornan
3750d6ff70 chore(mypy): require full annotations outside tests, type the setup responses (#4795) 2026-09-26 15:31:00 -04:00
Georges-Antoine Assi
b6c03e79eb fix(saves): stamp save and state file names with local time
State names were built with toISOString() in the browser, and save,
streaming save and memory card names with datetime.now(timezone.utc) on
the server, so every timestamp in an asset's file name was UTC. States
now use the browser's local time and server-named assets use the
server's local time (the container's TZ). Matching and ordering read the
stored file_name and the DB timestamps, so existing files are unaffected.

Fixes #4726

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 13:58:54 -04:00
Sam Dornan
9c1e6b2d86 refactor(backend): move engine-specific query SQL out of handlers into utils/sql_dialect.py (#4793) 2026-09-26 13:48:33 -04:00
Georges-Antoine Assi
cdbced8d53 Merge pull request #4764 from rommapp/feat/pinned-media
feat(v2): pin any media to the game overview
2026-09-26 13:40:34 -04:00
Sam Dornan
0b98e5ff63 fix(scan): compute RA hash for archives whose member read fails (#4806) 2026-09-26 13:35:27 -04:00
Georges-Antoine Assi
c6ffa3ca57 Merge remote-tracking branch 'origin/master' into feat/pinned-media
# Conflicts:
#	backend/tests/test_migrations.py
2026-09-26 12:45:12 -04:00
Sam Dornan
d1ce4e3db2 fix(sync): make deleted-save tracking exact, complete, and effective on filled slots (#4789) 2026-09-26 12:33:54 -04:00
Georges-Antoine Assi
c79db61cb2 refactor(v2): simplify pinned media
Build each media source once per resolve, gate isPinned on scope inside
the composable, sync cached ROM copies on pin writes, require pinKey on
screenshot items, and share the order-preserving dedupe validator.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 10:52:32 -04:00
Sam Dornan
c4f4d22687 chore(mypy): require coded ignores and flag stale ones, type protected_route (#4794) 2026-09-25 22:33:13 -04:00
Sam Dornan
2c71226887 ci: run mypy in its own workflow instead of through Trunk (#4724) 2026-09-25 21:37:01 -04:00
Georges-Antoine Assi
9131ac9f43 Merge remote-tracking branch 'origin/master' into streaming-reaper
# Conflicts:
#	backend/tasks/registry.py
2026-09-25 10:45:52 -04:00
Sam Dornan
7dd35aa139 fix(sync): give a sync session the life of one launch, and drop the dead play-session link (#4670) 2026-09-25 10:14:09 -04:00
Georges-Antoine Assi
29e6b8c1e9 fix(streaming): keep a claim fresh through its setup, log what spawned work raised, and notify a task's success only after that work ends (code-review)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 08:40:50 -04:00
Georges-Antoine Assi
2fc0460670 Merge remote-tracking branch 'origin/master' into streaming-reaper
# Conflicts:
#	backend/tasks/registry.py
#	backend/tasks/tasks.py
#	backend/tests/tasks/test_tasks.py
#	docs/BACKEND_ARCHITECTURE.md
2026-09-24 21:52:08 -04:00
Georges-Antoine Assi
8a33ccb35a Merge branch 'master' into streaming-patches-5 2026-09-24 21:01:09 -04:00
Georges-Antoine Assi
808239db37 refactor(streaming): generate the remaining streaming API types from the backend
The launch socket payloads, the 409 busy detail and the card-import answer
were hand-written in services/api/streaming.ts and could drift from the
backend models they mirror.

- Publish Socket.IO payload models into the OpenAPI components
  (utils/openapi.py), starting with the three streaming launch events.
- Raise the busy 409 from a ContainerBusyDetail model and declare it on
  the game and desktop claim routes.
- Derive MemoryCardImport from ClaimStreamingSessionRequest, and type the
  list and control calls with their generated response models.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 20:57:36 -04:00
Zurdi
404518c5e0 Merge pull request #4749 from rommapp/claude/issue-2653-7225d5
feat: rename saves and states, and one public/private look across v2
2026-09-24 22:37:54 +02:00
Georges-Antoine Assi
258d7a8892 Merge remote-tracking branch 'origin/master' into feat/retroarch-cloud-sync 2026-09-24 16:17:32 -04:00
Sam Dornan
abd061f59a perf(backend): read the gallery sorts out of an index (#4647)
* perf(backend): read the nullable gallery sorts out of an index

Sorting the gallery by release date, rating or HowLongToBeat time placed
unset roms last with `ORDER BY <column> IS NULL, <column>`. The leading
term is an expression, so MariaDB and MySQL could not read the order out
of `idx_roms_<column>` and filesorted instead. PostgreSQL had the mirror
problem descending: `DESC NULLS LAST` does not match the index's own
order, so it fell back to a sequential scan.

Neither engine paid this once. v2 window fetches send no sidecars, so
each scroll window is its own `ORDER BY ... LIMIT 72 OFFSET n` over the
full filtered set, and `roms` carries a JSON metadata blob per provider
on every row.

Each column now carries a STORED `_unset` flag with an
`idx_roms_<column>_sort` pair the ascending sort leads with, and
PostgreSQL gets an `idx_roms_<column>_desc` for the descending one. Row
order is unchanged in both directions.

Measured on PostgreSQL 16 over 120k roms, first page:

  ascending    30.6 ms / 8109 buffers -> 0.074 ms / 13 buffers
  descending   33.5 ms / 8091 buffers -> 0.112 ms / 14 buffers

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* fix(backend): rebuild a sort index MariaDB narrowed instead of dropped

Testing the previous commit against MariaDB rather than PostgreSQL alone
turned up a real bug in it.

The two engines leave a dropped generated column in different states:
PostgreSQL drops every index that reads it, while MariaDB and MySQL keep
a composite one over the columns that survive. `_restore_generated_indexes`
only created indexes missing by name, so on MariaDB the rebuild path in
`ensure_roms_columns` (a chain predating 0123) would leave
`idx_roms_<column>_sort` narrowed to the unset flag alone and the
ascending gallery sort walking half an index.

It now reconciles on the columns an index spans, not just its name, and
`_drop_index_sql` gives the two dialects their own DROP INDEX spelling.

Also corrects the flag columns' comments: MariaDB accepts no NOT NULL on
a generated column in either position, so they are nullable in the DDL on
both engines. `IS NULL` never evaluates to NULL, so no row carries one.

Verified on MariaDB 10.11 over 120k roms. The ascending page went from
`rows=116503, Using index; Using filesort` to `rows=72, Using index`,
134 ms to 6 ms, with the same plan once the rom_user join is added.
Migration, schema and flag values also checked under utf8mb3_unicode_ci,
the collation these expressions are most fragile under.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* style(backend): give the sort-flag rationale one home

Greptile flagged the comment blocks in this PR against CLAUDE.md's
comment discipline. The length was a symptom: the same explanation of
why MariaDB cannot index the NULLS LAST emulation appeared in four
places. It now lives once, beside `SORTABLE_NULLABLE_ROM_COLUMNS`, and
the other sites say only what is local to them.

No behaviour change; the migration docstrings are left as they are,
matching the narrative style every recent revision uses.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* fix(backend): drop the sort indexes with the rest of the catalog

Copilot pointed out that `ensure_roms_columns` installs the `_unset`
columns long before 0129 runs, so a chain that stops short and then
downgrades leaves them behind. Checking that turned up a real leak next
to it: 0108's downgrade, which the module documents as removing whatever
of the catalog such a chain still carries, was leaving two indexes.

A descending sort index reads a value column this module inherited
rather than added, so `drop_roms_columns` re-adds that column and the
index over it survives. `_drop_sort_indexes` now takes them explicitly.
PostgreSQL only, since no other engine has those indexes.

The flag columns themselves are not a leak: the catalog front-loads every
column it owns, so at 0127 the table already carries 0123's
`generated_keywords`, `generated_themes` and `generated_rating_count`
too. Verified on both engines that a 0128 to 0127 downgrade leaves the
table writable with the flags still computing, and that re-upgrading
restores the pair, narrowed index included.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* style(backend): tighten the teardown docstrings and the test annotation

Two more from Greptile, both worth taking even though the reasoning
behind each was off.

`_drop_sort_indexes` and its test now carry a summary plus one line,
matching `drop_roms_columns` right above them, and the parametrized
metadata argument is typed instead of a bare `dict`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* perf(backend): index the remaining gallery sorts (#4644)

* perf(backend): span the gallery sort indexes through the id tiebreak

The gallery appends `id` to every ORDER BY, but `idx_roms_<column>_sort`
stopped at the value and `idx_roms_<column>_desc` at the value alone. On
PostgreSQL that leaves every tie to be sorted, and unset metadata is a single
tie covering the whole bucket: a scroll window inside it fell back to a Seq
Scan and an external merge sort. Both indexes now carry `id` in the sort's own
direction, which InnoDB was already appending for MariaDB and MySQL.

Measured on 120k roms, a window at offset 100000 (inside the unset bucket),
all three columns, both directions:

  PostgreSQL ascending   119 ms, external merge sort  ->  15 ms, index only
  PostgreSQL descending   92 ms, incremental sort     ->  13 ms, index only
  MariaDB, both          already index-only; unchanged

No sort node remains in any of the twelve plans. Also trims the docstrings and
comments this change touches to the repo's one-or-two-line rule.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* test(backend): pin the reflected order of the descending sort indexes

The existing assertion read column names only, which a default ascending index
satisfies just as well, and `AUTOGENERATE_EXEMPT_INDEX_NAMES` keeps the drift
check away from these. Asserts the reflected `column_sorting` instead, and its
absence on the ascending pair.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* fix(backend): declare the unset flags nullable, as their DDL is

`Mapped[bool]` inferred NOT NULL while both engines create the column nullable,
MariaDB because it takes no NOT NULL on a generated column. The four generated
columns beside them already match their DDL. The annotation stays `bool`, since
`IS NULL` never yields NULL.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8

* fix(backend): renumber the gallery sort revisions after 0132

master gained its own 0129-0132 while this branch was open, and both
chains started from 0128_hltb_main_story_column, leaving alembic with
two heads (`upgrade head` fails with MultipleHeads).

0129_indexed_gallery_sorts -> 0133, now revising 0132_audit_events;
0130_gallery_sort_indexes -> 0134. No content change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VgcWNtJy6ucWRaibqNKNJC

* fix(backend): re-chain the renamed gallery sort revisions onto 0132

The previous commit renamed the files but left their revision IDs and
parent as they were. 0133 now revises 0132_audit_events, and both IDs
match their filenames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VgcWNtJy6ucWRaibqNKNJC

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 14:56:43 -05:00
Sam Dornan
d084723bfb fix(hltb): accept token-only sessions and discover the endpoint when GitHub fails (#4758)
* fix(hltb): accept token-only sessions from /init

HowLongToBeat's /api/search/site/init now returns only a token and the
site's own search sends just x-auth-token. parse_session still required
hpKey and hpVal, so every mint read as "no session" and all HLTB lookups
(and the endpoint discovery workflow) silently returned nothing. The
honeypot pair is now optional and only sent when HLTB issues it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHm9rRfJsxunF1RckjQqzx

* review: share the honeypot check and narrow optional mock calls

Move the both-fields honeypot check into HLTBSession.honeypot() so the
headers and body cannot drift apart, drop the historical note from its
comment, and assert mock call args are not None before reading kwargs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHm9rRfJsxunF1RckjQqzx

* feat(hltb): discover the search endpoint from HLTB when GitHub fails

If the endpoint fixture can't be fetched from GitHub, run the same
build-manifest discovery the weekly workflow uses against HLTB itself,
and fall back to the fixture bundled in the image rather than the stale
hard-coded /api/find. The discovery helpers now log instead of printing
so their output joins RomM's logs. Search requests also send an Origin
header, as the browser does for HLTB's same-origin POST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHm9rRfJsxunF1RckjQqzx

* fix(hltb): keep a malformed discovery response from aborting scans

parse_session and the discovery validator called .get() on whatever JSON
HLTB returned, so a non-object body raised AttributeError out of
initialize() and aborted the scan. Both now reject non-object JSON, and
the handler logs any discovery failure and keeps the bundled endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHm9rRfJsxunF1RckjQqzx

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 14:20:47 -05:00
Georges-Antoine Assi
9e7933ae97 fix(cloud-sync): apply code-review xhigh findings
- Bound /api/cloud-sync uploads with the asset size limit
- Cap PSP bundle member count and uncompressed size
- Keep PSP writes and deletes on the existing bundle row, one member at a time
- Match PSP bundles by exact folder, support the no-core-folder layout
- Reject . and .. PSP segments; map parse_sfo struct errors and write
  errors to 4xx
- Require ROMS_READ for roms/ browsing
- Clear missing_from_fs on overwrite
- Resolve state screenshots by exact name, never a gallery screenshot
- Round-trip unknown core folder names exactly
- Keep + allowed in the shared sanitizer, strip it only on ROM rename (#2746)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:31:51 -04:00
zurdi
387765b04f review: address Greptile findings on #4749
- rename_file links then unlinks, so a name another worker took after the
  check is refused instead of replaced; filesystems without hard links fall
  back to rename.
- rename_asset owns the whole rename: the thumbnail and asset rows commit
  in one transaction, and a failed commit moves the files back.
- A thumbnail another save or state still resolves is copied for the
  renamed asset instead of moved away from the other one.
- Collection Apply and the visibility switch wait for each other.
- The collection settings test builds its fixture with a typed factory,
  the RSwitch label-slot story uses a colour token, and the moved assets
  fixture keeps a one-line docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 17:07:47 +02:00
Georges-Antoine Assi
7808bf004b Merge remote-tracking branch 'origin/master' into feat/retroarch-cloud-sync
# Conflicts:
#	backend/handler/database/states_handler.py
#	backend/tests/utils/test_filesystem.py
2026-09-24 08:22:22 -04:00
zurdi
d9d65d8b56 refactor(audit): apply the pr-ready simplify pass
- record() takes the request as its actor, and a target can be a
  function: the lookups that name it now run inside the recorder's error
  handling, and for downloads only once the dedupe lets them record.
  That also restores the minimal visibility query on the file route.
- One changed_fields/change pair for rom, user, collection and platform
  edits, one collection helper, AuditActor.anonymous, a shared
  count_in_window and current_device_id, one test helper for recorded
  events and one fixture for audit events.
- The describers share simple/counted/visibility builders and the
  eventData readers with notifications, join lists per locale, and treat
  any *.delete as unlinked.
- EventLog builds one item list with the phase folded in, keeps each
  event's sentence across pages, formats days once, and loads users
  through the users store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 02:45:12 +02:00
Sam Dornan
d7f226934b fix(roms): order lettered discs like numbered ones (#4738)
* fix(roms): order lettered discs like numbered ones

"(Disc A)", "(Disc B)" didn't match the disc tag pattern, so a lettered
set fell back to plain file-name order. A bonus file whose name sorted
earlier could then take the first playlist slot and boot instead of
disc A, and mixed-case names ordered wrongly. Lettered discs now count
from A as 1. The letter needs a space after the word, so "(CDi)" is not
read as disc 9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkUQt5fewjBenaaUMD4XpG

* fix(roms): match only ASCII letters as a disc letter

With re.I alone, [a-z] case-folds non-ASCII letters too: "(Disc İ)"
crashed ord() with a two-code-point lowercase and "(Disc ſ)" became
disc 287. Also trim the pattern comment and docstring to the repo's
comment limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkUQt5fewjBenaaUMD4XpG

* fix(roms): keep Unicode whitespace in disc tags matching

re.ASCII on the whole pattern also narrowed \s, so "(Disc 2)" with a
non-breaking space lost its disc number. Scope the ASCII flag to the
disc letter alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkUQt5fewjBenaaUMD4XpG

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 11:57:02 -05:00
Zurdi
f11725b835 Merge pull request #4735 from rommapp/claude/notification-channels
feat: forward notifications to webhooks, Discord, ntfy and email
2026-09-23 18:56:29 +02:00
Sam Dornan
01d05101f9 fix(roms): order a playlist by disc number, not by file name (#4737) 2026-09-23 11:47:56 -04:00
zurdi
7ac95be747 feat: forward notifications to webhooks and email
Each user can add channels that forward their notifications: a webhook
posting RomM's JSON (optionally HMAC-signed), a Discord embed or an ntfy
message, or an email address confirmed with a code. A channel filters by
minimum level and by topic, and every stored notification that passes goes
out in its own RQ job, retried three times; ten failures in a row turn the
channel off and tell its owner.

Channel configs are sealed with a key derived from ROMM_AUTH_SECRET_KEY,
since a webhook URL carries its own token. Only an admin's webhooks may
reach private addresses; everyone else's go through the SSRF guard. Email
goes out over the SMTP_* settings, which the heartbeat reports as
NOTIFICATIONS.EMAIL_ENABLED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 16:30:33 +02:00
zurdi
01483dd715 fix: disconnect a session's sockets when it is revoked
A socket joins its user's room, and an admin's the admin room, once at
connect time, so logging out or revoking a user's sessions left their open
sockets receiving notifications and the log stream. Each socket is now
recorded against the login session that opened it, and removing a session
disconnects those sockets on whichever worker holds them.

The main server takes one disconnect handler, so it moves next to the
connect handler and runs the activity cleanup as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 14:23:39 +02:00
Zurdi
2a479fe796 Merge pull request #4714 from rommapp/feat/save-state-favorites-labels
feat(saves): favorite and label saves and states
2026-09-23 09:36:48 +02:00
Georges-Antoine Assi
0215577c04 Merge pull request #4694 from rommapp/claude/authz-and-invite-hardening
fix(security): check endpoint ownership and consume invites atomically
2026-09-22 20:49:04 -04:00
Sam Dornan
cf19c8ae35 fix(backend): clear the remaining mypy errors outside roms_handler (#4723) 2026-09-22 19:00:24 -04:00