Commit Graph

691 Commits

Author SHA1 Message Date
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
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
zurdi
ecaa883400 refactor(v2): apply the simplify pass
The folding rule was written three times in two phrasings: as a filter,
as its own inverse inside the auto-open check, and as an arithmetic
difference for the chevron count. A slot band now partitions into
`pinned` and `hidden` once where it is built, so the rule has one home
and the filter stops re-running per render.

Also:
- A band carries its newest asset instead of the id, so ranking no
  longer scans the band to find it again inside a sort comparator.
- `HIDDEN_ASSET_ANNOTATIONS` derives from `AssetAnnotations`, so a third
  annotation field cannot be added without also being masked.
- `normalize_asset_labels` keys the dedupe off a dict, folding each label
  once, and rejects an oversized set as soon as it crosses the cap
  instead of after walking the whole body.
- The clear button's absolute placement moved onto the stage that wants
  it, so the inline variant no longer un-sets it.
- Two duplicated label ternaries became computeds.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK
2026-09-23 00:16:32 +02:00
Sam Dornan
5f05e4ee7b fix(hltb): send a browser user agent so HLTB's firewall lets requests through (#4717)
HowLongToBeat's firewall now answers any tool-style "Name/version" user
agent, including RomM/<version>, with a 403 HTML page. That failed the
heartbeat (shown as "Connection failed" in Settings) and the /init session
mint, so scans and manual matches silently got no HLTB data.

Send a fixed browser user agent instead. Every HLTB call goes through
base_headers(), so the session stays bound to the same agent.


Claude-Session: https://claude.ai/code/session_01Q4AcvMx1hNfc94xqEeqjzw

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-22 16:42:32 -05:00
zurdi
85d2b6e2c6 feat(saves): favorite and label saves and states
A filename and a timestamp cannot tell apart a 100% run from a speedrun
seed, so saves and states carry two owner-only annotations: a favorite
heart that sorts them ahead of their band, and a set of free-text labels.

Backend adds `is_favorite` and a JSON `labels` to both tables, with
`PUT /{saves,states}/{id}/{favorite,labels}` mirroring the existing
visibility toggle. Labels are trimmed, de-duplicated case-insensitively
and capped. Both routes write with `touch=False`, so annotating a save
leaves `updated_at` alone: it is not a write to the bytes, and device
sync reads that column to decide staleness.

In v2 the Save data tab grows a heart and a labels button per row, the
labels dialog suggests the labels already used on the ROM, and favorites
lead their slot or core without ever folding the newest version away.
The heart glyph shows only on the launch screens, where the toggle that
would otherwise say it is not there. Phones give the row four bands:
name, labels, facts, buttons.

Closes #942

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK
2026-09-22 23:03:25 +02:00
Sam Dornan
4542998510 fix(backend): make type ignores honest and replace mypy trunk-ignores with fixes (#4711)
* fix(backend): make type ignores match what mypy reports

Third in the staged series clearing the errors #4655 made visible.
Whole-project mypy: 91 errors in 26 files -> 64 in 23.

Twenty `# type: ignore[assignment]` comments in
endpoints/responses/rom.py never suppressed anything. The request-scoped
values `from_orm_with_request` attaches to a Rom (rom_user, has_notes,
user_saves and the rest) are not declared on the model, so mypy reports
`attr-defined`; it does so under 1.19 as well as 2.3, so the code was
wrong when the comments were written rather than drifting since. They
now name the error they were meant to silence.

Seventy-nine ignores across 24 files suppressed nothing at all under
`--warn-unused-ignores`, and are removed. One of them,
`utils/zip_cache.py`, keeps its `attr-defined` code for the private
`zipfile._get_compressor` and drops only `assignment`. The unused set is
identical under mypy 2.3.0 and 2.3.1, and removing them leaves the error
count unchanged under both, so none was quietly needed.

The two `filter` helpers typed as `[QueryT: Select | Update | Delete]`
bound the TypeVar to the union, so `query.filter(...)` returned the union
and could not be assigned back to `QueryT`. Constraining it to the three
types lets mypy check each one separately, and the callers are unchanged.

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

* fix(backend): replace mypy and ASYNC240 trunk-ignores with real fixes

A `trunk-ignore` only suppresses when Trunk runs the linter. Plain mypy
does not read them, so the 13 on mypy findings were all still errors to
`mypy .` and would fail a whole-project check. Each now has a fix.

endpoints/tasks.py: `common_data` was a plain dict literal unpacked into
eight TypedDict constructors, so mypy saw `dict[str, Any]` and could not
match its keys. It holds exactly the fields of BaseTaskStatusResponse and
is now annotated as one, so the unpacking is checked.

handler/metadata/gamelist_handler.py: both media maps were inferred as
`dict[str, str]`, so indexing the TypedDict with their keys was
unprovable. Their keys are now typed `GamelistMediaKey`, the Literal of
the TypedDict's fields. A misspelt map key is now an error at the entry;
before, only the index site could have noticed, and it was suppressed.

handler/metadata/playmatch_handler.py: `attr` was a bare `str`. A TypeIs
guard narrows it to the five lookup attributes, and the frozenset is
derived from that Literal so the names live in one place. mypy now checks
that each name is a real PlaymatchRomMatch key. It does not check that
each takes an int, since mypy is lenient about value types on a union key;
that still rests on which five names are listed.

endpoints/search.py: the per-source tuples mixed ROM-list and handler
types, which mypy joined to `object`. The dict is now annotated with what
the loop uses: Mapping rows and the MetadataHandler base.

tests/handler/metadata/test_launchbox_handler.py: `Path.stat()` inside an
async test (ASYNC240) now goes through `anyio.Path`, as the rest of the
codebase already does.

Whole-project mypy: 64 errors in 23 files -> 51 in 20, identical under
2.3.0 and 2.3.1.

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

* fix(backend): keep gamelist media keys in one place

Review pointed out that `GamelistMediaKey` repeated all fourteen fields
of GamelistMetadataMedia. Python has no `keyof`, so any Literal of a
TypedDict's keys is a second declaration of them, and a field added to
the TypedDict would be left out of it without any error.

The three index sites go back to suppressing `literal-required`, now as
`# type: ignore[literal-required]` so plain mypy reads it as well as
Trunk. The TypedDict stays the only declaration of the key set.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-22 16:02:39 -05:00
Sam Dornan
1e6174c1cd fix(backend): correct three small typing faults mypy now reports (#4709) 2026-09-22 16:22:08 -04:00
Sam Dornan
27404355f0 fix(security): stop 7-Zip reading an archive member name as a switch
Member names come from the archive's own listing, so an entry stored as
"-x" or "@listfile" was parsed as an option. "--" terminates switch
parsing before the name, matching what the bsdtar path already does.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 09:46:22 -05:00
Sam Dornan
552cf7c213 fix(config): show folder mappings whose folder name is not lowercase (#4676) 2026-09-21 19:52:40 -04:00
Sam Dornan
4ffc7c5ce1 style: apply the formatting requires-python already implies (#4638) 2026-09-19 12:33:45 -04:00
Georges-Antoine Assi
57e6462db8 Merge pull request #4634 from rommapp/claude/patcher-zip-bomb-budget
fix(patcher): budget a zip member as it is extracted
2026-09-19 09:29:12 -04:00
Georges-Antoine Assi
311534c6f9 Update backend/utils/media_types.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-09-19 09:20:04 -04:00
Georges-Antoine Assi
5361dfee4a docs(files): state what actually guards an inline HTML document
Two comments described HTML documents as sanitized on ingest. Nothing
sanitizes them: the only `sanitize_*` helpers cover filenames and usernames,
and `is_html_document_file` is consulted at serve time only. The sandboxing
CSP and the viewer's iframe sandbox are the whole defence, so describe them
that way, and pin the header with a test before someone drops it believing
the sanitizer exists.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-19 08:48:39 -04:00
Georges-Antoine Assi
3e1779f119 fix(patcher): budget a zip member as it is extracted
The size checks around the extraction read `ZipInfo.file_size`, which is
whatever the uploader put in the header, and the check on the finished file
only ran once the member had been written in full. An archive whose method
zipfile cannot decode goes through 7zz, which decompresses it itself and
ignores that header, so a small declared size passed the pre-check while the
real member filled the disk.

Count the bytes as they are written and stop at the cap, which makes the
check on the finished file redundant.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 20:57:56 -04:00
zurdi
5f02a99fd3 fix: trust the repo root as a safe directory for git branch lookup
Addresses Copilot review feedback on PR #4617.

The Docker dev image's bind-mounted .git is host-owned while the
romm-dev container runs as root; git 2.35.2+ refuses that mismatch
as "dubious ownership" and rev-parse fails, so GIT_BRANCH silently
stayed null and the UI kept showing "development" in the very
workflow the mount was added for. Pass safe.directory scoped to
this one read-only invocation instead of touching global git config.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TDMqXzXexRgC89YxeNjn9q
2026-09-18 13:29:38 +02:00
zurdi
2f2230924d fix(ci): suppress bandit B404/B607 on get_git_branch's subprocess call
Trunk Check failed on the PR: bandit flags importing subprocess
(B404) and invoking "git" by name instead of an absolute path
(B607), on top of the B603 shell=False call already suppressed.
Both are accepted here for the same reason B603 was: git is
resolved from PATH by design so this works across dev setups
(Docker and bare-metal alike), and the arguments are hardcoded.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TDMqXzXexRgC89YxeNjn9q
2026-09-18 13:22:15 +02:00
zurdi
b21d4e2693 review(code-review xhigh --fix): keep About reactive, fix branch URL encoding
- AboutDialog's links list was a static array read once at setup, so it
  never picked up a later heartbeat update; made it a computed.
- useVersionDisplay's GitHub tree link blanket-encoded the branch name,
  breaking "/" as a path separator (e.g. "feature/foo"); now encodes
  each segment. Deduped the dev-build/branch check into one computed.
- Trimmed two over-long comments/docstrings per house style.
- Added coverage: a CalledProcessError case for get_git_branch, and a
  full test file for useVersionDisplay.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TDMqXzXexRgC89YxeNjn9q
2026-09-18 13:06:25 +02:00
zurdi
5440c9f03b feat(about): show current git branch instead of "development"
Local checkouts have no release tag, so heartbeat.SYSTEM.VERSION always
falls back to the literal string "development". Add a GIT_BRANCH field
(backend-resolved via git, display-only, not used in the version string
that also feeds outbound User-Agent headers) and use it in the About
dialog and the auth-screen VersionTag so a dev build shows the branch
being worked on instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TDMqXzXexRgC89YxeNjn9q
2026-09-18 12:51:00 +02:00
zurdi
0318f078ae refactor(covers): simplify animated cover handling (simplify)
Simplify pass over the animated cover change:
- Encode animated small covers as WebP whatever the source, which drops
  the per-format GIF/APNG blending params and makes their WebP copy a
  plain file copy.
- Fold the is_animated gate into frame_durations and decode the small
  cover's frames in the same pass that reads their durations.
- Write uploaded animated artwork through the atomic write_file.
- Share test fixture constants and the animation encoder, and pin the
  per-frame pixel budget with a GIF whose canvas grows mid-animation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 11:00:14 +02:00
zurdi
88a82a729f fix(covers): bound and harden animated cover processing (code-review)
Code-review pass over the animated cover change:
- Cap the pixels decoded across an animation (MAX_ANIMATION_PIXELS),
  counted per frame since a GIF canvas can grow mid-animation, so an
  oversized animation falls back to its first frame.
- Fall back to the first frame when a later frame fails to decode,
  instead of dropping the cover or escaping the error handlers.
- Store uploaded animated artwork as uploaded, like downloaded covers.
- Re-encode composited frames so each replaces the last (no GIF/APNG
  ghost trails), and keep GIF loop counts when converting to WebP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 10:45:29 +02:00
zurdi
b326e66db9 fix(covers): keep animated covers animated after applying them
The small cover and the WebP copies were written through PIL, which keeps
only the first frame, so an animated SteamGridDB cover showed as a still
image everywhere once applied. Resize and convert every frame with its
timing, copy WebP sources instead of re-encoding them, and keep all
frames of uploaded animated artwork.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 10:22:02 +02:00
Georges-Antoine Assi
9e940e7d10 refactor(scan): simplify the title id extraction path
Sort title id sources with the natural key the models already compute,
give the compressed suffixes one home, and let SigilService reject a
container itself rather than trusting every caller to.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 22:00:57 -04:00
Georges-Antoine Assi
cf8d79f9f6 fix(scan): apply pr-ready code-review findings
Order discs by their number so "Disc 2" precedes "Disc 10", test one
rule for containers sigil cannot read, and drop the unreachable
OSError handler around Path.is_file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 21:53:31 -04:00
nendo
3ca79a1205 fix(scan): reread title ids on every rescan and break sort ties by exact name 2026-09-17 07:36:21 +09:00
nendo
2e6acaac3c Merge remote-tracking branch 'upstream/master' into fix/sigil-cnf-serial-shapes
# Conflicts:
#	backend/tests/utils/test_m3u.py
2026-09-17 07:09:35 +09:00
nendo
35f799086d fix(scan): apply code-review findings to title id source ordering 2026-09-17 06:57:17 +09:00
nendo
c6170db6bc fix(scan): identify multi-disc and playlist roms by their first disc 2026-09-17 06:14:08 +09:00
Sam Dornan
14fc8d9930 fix: treat every disc descriptor as a disc, not just .cue (#4532)
* Treat every disc descriptor as a disc, not just .cue

playlist_files keyed on .cue alone, so a Dreamcast .gdi set, a CloneCD
.ccd set and an Alcohol .mds set all fell through to "every file is a
disc" -- the descriptor and the raw tracks it cannot boot without were
listed side by side.

The three readers of the rule each got that wrong in their own way: the
playlist shipped inside the download zip named non-bootable tracks, and
the in-browser disc swapper offered them as discs.

Key on a set of descriptor extensions instead, so no one sheet format is
privileged over the others. The shape is unchanged -- descriptors if any,
else everything -- and so is the download zip, which lists every file
regardless.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Keep a disc that stands on its own beside a descriptor

Selecting descriptors and discarding everything else assumed a multi-file
ROM is all one format. It is not: a .chd sitting beside a .gdi boots on
its own, and returning only the .gdi dropped it from the playlist and
from the swapper's targets.

Exclude the raw tracks a sheet points at instead of keeping only sheets.
The tracks are still not discs, so every case the previous commit fixed
stays fixed, and a disc no sheet describes now survives.

This also settles the same bug on the .cue path, which predates this
branch: disc1.cue + disc1.bin + disc2.chd used to list the cue alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Count a sheet's audio tracks as tracks

A .cue names its CDDA tracks the same way it names its data track, so a
.wav or .flac beside one is data, not a disc. The playlist listed them.

Brings the list in step with the shell's own in src/main/discs/m3u.ts,
which has carried the audio formats since it was written.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 11:05:03 -05:00
Georges-Antoine Assi
827aef4221 Merge pull request #4490 from rommapp/fix/trigger-ddl-privilege-guard-3932
fix(migrations): name the fix when the server denies trigger DDL
2026-09-15 09:25:37 -04:00
Georges-Antoine Assi
78ba4c4721 fix(migrations): give the trigger-DDL probe a name no schema can hold
Trigger names are schema-wide, so the fixed probe name could name an
operator's own trigger, and DROP TRIGGER IF EXISTS would really remove it.
A fresh uuid per call makes the statement a guaranteed no-op, so the only
error it can raise is the refusal it is looking for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 09:20:54 -04:00
Georges-Antoine Assi
60e4e385b5 Merge remote-tracking branch 'origin/master' into fix/zip-rom-patching
# Conflicts:
#	frontend/src/locales/zh_CN/patcher.json
2026-09-14 18:44:46 -04:00
Georges-Antoine Assi
ff335ea2c0 fix(patcher): keep zipfile errors matchable and stop forcing ZIP64
A module-level exception tuple freezes zipfile.BadZipFile, but seven test
modules reload the zipfile module, which rebinds the class. After any of
them runs, a corrupt archive escaped the handler and surfaced as a raw
BadZipFile instead of a 400. Look the class up at raise time instead.
NotImplementedError goes with it, being a RuntimeError subclass.

Declare each rebuilt entry's final size instead of passing force_zip64,
so zipfile marks an entry ZIP64 only when it needs to; a patched ROM
handed to a basic unzip implementation was otherwise rejected even though
the unpatched archive loaded fine.

Drop the extracted and patched intermediates once they are consumed,
rather than holding three full-size copies for the life of the download.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-14 18:41:47 -04:00
Zurdi
d4f81f097f Merge pull request #4487 from rommapp/claude/graphql-api-migration-vu20z2
refactor(roms): give the ROM filters a single home, and match them against the facets mirror
2026-09-14 23:46:48 +02:00
Kyle Benzo
d8a32ab7dd fix(patcher): preserve output filesystem errors 2026-09-14 13:01:53 -07:00
Kyle Benzo
fad8b2943d fix(patcher): use archive fallback for zip extraction 2026-09-14 12:55:08 -07:00
kylebenzo
3e73579614 Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-09-14 12:49:58 -07:00
Georges-Antoine Assi
07f5a1d005 refactor(migrations): tighten the roms catalog (simplify)
- `rebuild_generated_columns` owns the index drop, since it is the one
  place a column is dropped, so 0123's downgrade gets it too.
- `ensure_roms_columns` builds its action list first and runs on it, and
  no longer re-reflects the table to re-test a column it just added.
- One list behind `STEAM_FED_COLUMNS`, and `INHERITED_COLUMNS` says what
  the set difference at the use site used to.
- 0112 builds the view through `roms_metadata_view_sql`, and 0126 drops
  the add-column branch the shared copy made unreachable.
- Tests share one generated-expression helper and read index and column
  names off the module that owns them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 07:29:28 -04:00
Georges-Antoine Assi
e3f34a4562 fix(migrations): harden the roms catalog replays (code-review)
- `drop_roms_columns` drops a composite index that still spans a column
  it removes before the ALTER: MariaDB and MySQL would otherwise keep the
  index over the remaining columns, so 0126's unique index left by a run
  that died before its stamp would become UNIQUE (platform_id).
- `ensure_roms_columns` recreates `roms_metadata` whenever it is absent,
  so a run that died between its ALTER and the CREATE VIEW gets the view
  back on the replay instead of only when a rebuild is pending.
- A generated column the engine does not reflect as computed counts as
  not reading Steam and is rebuilt, rather than raising a KeyError.
- One home for the `steam_metadata` column name, imported by 0123.
- Tests pin the lost view, the leftover MariaDB default and the surviving
  unique index; the ALTER recorder matches `roms` as a whole word.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 07:14:10 -04:00