Commit Graph

42 Commits

Author SHA1 Message Date
Georges-Antoine Assi
6dd3353855 refactor(metadata): give the unreachable-provider error one home
The same 503 was built inline at seven sites across the metadata handlers, and
the previous commits added two more copies of it as per-handler `_unavailable`
helpers. `base_handler.unavailable(provider)` now builds it for all of them.

Also renames the search endpoint's cover filter to say what it does and types
the scan test's lookup factory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 21:16:07 -04:00
Spinnich
24bc4c221b fix(scan): don't let a failed lookup clear the id it couldn't check
A complete rescan clears the id of every source it consulted that came back
empty. That reads an outage as a conclusive miss for the providers that report
a failure as an empty match, so a rescan run while one was down wiped the id it
would otherwise have confirmed, hand-set ones included.

Each of those now reports the failure and leaves the tolerance to the caller,
which is what the gather loop's discard already assumed:

- Pouët, CSDb and Demozoo stop swallowing the 503 their own `_request` raises,
  and Pouët's title search raises it rather than answering "no unique title".
- SteamGridDB and Flashpoint stop catching `Exception` around a whole lookup;
  HLTB stops catching it around its search.
- ScreenScraper answers empty for every remaining ROM once its daily-quota or
  credentials breaker trips, so the scan reads that state off the service and
  drops it from the sources the rescan may clear.

SteamGridDB resolves outside the gather and so needs the discard at its call
site. Search keeps degrading to no thumbnail, since its cover art sits on top
of matches the other providers already produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 20:49:51 +00:00
Georges-Antoine Assi
eec574b49b fix(metadata): give UniversalPlatformSlug a leaf home
Both CI failures came from one import cycle. RQ could no longer resolve
`endpoints.sockets.scan.scan_platforms`, and the e2e seed script failed the
same way, because `sigil` imports the platform slug enum, importing anything
under `handler.metadata` runs its `__init__`, that reaches `gamelist_handler`
which imports `handler.filesystem`, and `roms_handler` there imports `sigil`
back while it is still half-initialised.

The cycle predates this branch. It stayed hidden because `scan.py` reached
the enum through `utils.switch`, imported late enough that
`handler.filesystem` was already loaded; naming the adapter directly moved
that import to the top of the module and the ordering luck ran out.

So the enum moves to `utils/platform_slugs.py`, which imports nothing but
`enum`. Naming a platform no longer drags in httpx, redis and the titledb
task, and the 29 call sites point at the module that owns it rather than
picking it up from a 1000-line metadata handler that happens to re-export
it. `import adapters.services.sigil` now also works on its own, which it
did not before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 14:28:49 -04:00
Georges-Antoine Assi
2a9f7251fd style: trim the HLTB comments down to the non-obvious why
Drop a comment that restated the constant it sat above, and cut the clauses
that defended the approach against the one it replaced.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 08:36:38 -04:00
Georges-Antoine Assi
2a7953ed58 refactor: share the HLTB search wire contract with endpoint discovery
The discovery script imported build_search_payload from hltb_handler, which
pulls in handler/metadata/__init__ and so instantiates every metadata handler,
opens Redis and writes a config file at import time. That import side effect is
why the workflow needed a dummy ROMM_BASE_PATH.

The script also hand-forked the rest of the protocol (base headers, the /init
mint, the session headers and the honeypot body merge), so it validated a
candidate route against a copy of what the handler sends rather than against
the real thing.

Move the contract into utils/hltb_search.py, a leaf module both sides import,
and drop ROMM_BASE_PATH from CI.

Pace failed session mints too: _ensure_session retried on every lookup, so a
down or IP-blocking HLTB cost each ROM in a scan its own rate-limited /init
round trip.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 08:31:14 -04:00
Sam Dornan
d2fafaa089 fix: validate the search contract during HLTB endpoint discovery
Minting a session only proved a candidate route was session-backed, not that it
answers the search the handler sends. A future session-minting route sorting
ahead of the game-search route would have been published on that evidence alone,
leaving installs without completion metadata until the fixture was corrected.

Discovery now completes the real exchange: it mints a session, POSTs a search
with it, and requires the HLTB game shape that search_games() reads back. The
payload is no longer duplicated for the check, it moves to build_search_payload()
so the handler and discovery send the same body.

Also fixes the workflow being unable to run this script at all. It imports the
backend config, which raises unless ROMM_AUTH_SECRET_KEY is set, and the workflow
set no environment, so every run (including the manual dispatches) died at import
before reaching any HLTB logic. That is why the fixture drifted from May despite
the workflow existing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 14:35:13 -05:00
Sam Dornan
d975aa8bc3 fix: restore HowLongToBeat lookups and repair endpoint discovery
HLTB lookups have returned nothing since HLTB rotated their search endpoint.
The published fixture still pointed at /api/bleed, which now 404s on both GET
and POST, and the handler fetches that fixture from master at every startup, so
every install was affected regardless of image version. The live endpoint is
/api/search/site, with the session mint at /api/search/site/init, which the
handler already derives as f"{search_url}/init".

The automation meant to keep the fixture current could not have fixed this on
its own. It only ran on workflow_dispatch, so it never ran unprompted, and HLTB
has since migrated to Turbopack: the homepage no longer serves a pages-router
_app chunk, so both app-chunk regexes matched nothing. The endpoint is also a
plain literal in the bundle now rather than the .concat() obfuscation the token
regex expected.

Discovery now reads _buildManifest.js, where Next.js lists every route as a
plain literal, and selects the route that has an /init sibling, the same pairing
HLTBHandler assumes. That rule uniquely picks /api/search/site out of the 90 API
routes in the manifest, and rejects near misses such as /api/forum/search. Each
candidate then has to mint a real session before the fixture is written, so a
dead URL cannot be published again.

A failed startup was also permanent and silent: _request() returned early
whenever there was no session and nothing re-minted one, so a container that
lost the mint at boot served no HLTB metadata for its whole lifetime with no
error after the startup warning. Failures are now logged, and lookups mint
lazily behind a lock so a scan's concurrent lookups do not each hit /init.

Fixes #4285

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 14:19:31 -05:00
Sam Dornan
808745e7ae fix(hltb): don't mistake markup or a redirect for a rewritten page
Two ways the 502 could fire on a page RomM can still read:

The hydration tag was matched by exact attribute order, so a CSP nonce or a
reordered attribute would have been reported as a rewrite. The id alone
identifies it.

`raise_for_status` lets a 3xx through, so a hop HLTB added later would reach
the parser as a page with no payload. Redirects are now followed; the client
validates every hop against SSRF, redirects included.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 20:38:33 -05:00
Sam Dornan
03fe992101 fix(hltb): map every transport failure on the game page to 503
`ConnectTimeout` is the likely failure when HLTB is slow or unreachable, and
it is not a subclass of `ConnectError`, so it escaped `update_rom` as a bare
500 rather than the actionable 503 the other providers give.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 20:30:28 -05:00
Sam Dornan
e7440a2dfc fix(hltb): fetch metadata when a HowLongToBeat ID is set by hand
`update_rom` fetches from every metadata provider whose ID changed, except
HLTB, which had no by-ID lookup at all. A hand-entered ID was stored and the
How Long to Beat tab stayed empty.

HLTB's API only exposes search, so `get_rom_by_id` reads the record from the
`__NEXT_DATA__` payload the game page already ships. The canonical
`/game/{id}` path is requested directly, as `/game?id=` answers with a
redirect the shared httpx client does not follow, and the game page dates a
release in full where search returns just the year.

A page RomM can no longer read raises 502 naming the cause instead of
reporting a game with no times, since that failure is otherwise
indistinguishable from the bug this fixes.

Fixes #2926

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 20:19:26 -05:00
Sam Dornan
66ddcab7d0 fix(hltb): split the retry term on colons only
Splitting on the shared separator pattern also split in-word hyphens, so
"spider-man 2" would have retried as "man 2" and invited a match on an
unrelated game. The retry fires on any rejected match rather than only an
empty result set, so it reaches that case far more readily than the Moby
and ScreenScraper retries do.

The term has already had " - " rewritten as ": " by this point, so a
series separator is a colon and any hyphen left is inside a word. Every
title the retry exists for splits identically.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:24:51 -05:00
Sam Dornan
26f595d8b9 fix(hltb): match titles whose series prefix the catalogue omits
HowLongToBeat is searched with the filename, and a series prefix that one
side carries and the other does not sinks a strict similarity gate: "007:
Quantum of Solace" scores 0.838 against the catalogue's "Quantum of
Solace", just under 0.85, and a term long enough returns no results at
all. Every James Bond title on PlayStation 2 missed for one of those two
reasons.

Retry with the part after the last separator, the same recovery Moby and
ScreenScraper already make. The trigger is broader than theirs, which
only retry an empty result set: a scored-but-rejected result has to
retry too, since that is how "Quantum of Solace" fails.

Verified against the live API: all five PlayStation 2 James Bond titles
now resolve, and six subtitle-heavy titles that could plausibly match the
wrong game on a tail-only search are unaffected, because the full term
matches first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:01:28 -05:00
Georges-Antoine Assi
e8993c1d4d run fmt 2026-08-07 14:37:11 -04:00
Sam Dornan
4e149fb707 fix(hltb): redact session material from the request debug log
The debug log printed the session headers and the honeypot pair verbatim.
The token decodes to "<issued-at>::<public IP>|<user agent>|<key>|<hmac>",
so anyone pasting DEBUG logs into a bug report published their host's public
IP address. Logs are also downloadable through /api/logs.

Redact the session headers and drop the honeypot entry from the logged
payload, keeping the URL, search terms and timeout that make the line useful.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Sam Dornan
39d7fa0b0f fix(hltb): read the session after pacing, and pace renewals too
Addresses review feedback on concurrent scans (SCAN_WORKERS > 1), where the
handler singleton is shared across in-flight ROM lookups.

Read the session after awaiting the rate limiter rather than before, so a
request paced behind a peer's renewal uses the current session instead of the
one that was live when it queued, and bails out if the session went away.

Acquire the limiter before the /init renewal as well, so a wave of concurrent
403s can't burst past the cap that search requests respect. The endpoint
fixture fetch is left unpaced: it targets GitHub, not HLTB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Sam Dornan
24d990f21a fix(hltb): renew rejected HLTB sessions instead of failing the scan
HLTB sessions are short-lived and pinned to the requesting IP address and
user agent. The handler fetched one session at the start of a scan and never
renewed it, so once HLTB rejected it every remaining lookup failed for the
rest of the scan.

Retry with a renewed session on 403, and back off and retry on 429. Report
the actual cause instead of mapping every HTTP error to "check your internet
connection", which is now used only for genuine connect and timeout errors.

Also fixes two adjacent bugs:

- The honeypot key was written into the caller's payload dict in place. That
  key rotates with the session, so a renewal would leave the dead key in the
  body alongside the new one.
- heartbeat() sent no user agent. HLTB rejects requests without one, and the
  httpx default only happens to be accepted today.

initialize() is now async so the session can be renewed from the async
request path, and uses the shared context httpx client.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:48:59 -05:00
Georges-Antoine Assi
e0214f100d more bot cleanup 2026-04-05 19:15:33 -04:00
Georges-Antoine Assi
6abf60b0fe last fixes 2026-04-03 11:49:32 -04:00
Georges-Antoine Assi
ceddf2f9e9 changes from bot review 2026-04-03 11:24:02 -04:00
Georges-Antoine Assi
ec8583016b mega ton of fixes for 4.8 2026-04-03 10:54:31 -04:00
Eric Daras
8540514b46 add outbound HTTP proxy support for backend requests 2026-03-27 07:02:14 +01:00
Georges-Antoine Assi
16cac7cf64 [ROMM-2972] Fix /props returning stale data 2026-02-08 21:10:12 -05:00
Georges-Antoine Assi
efb157a57d [ROMM-2997] Fix HLTB saerch term fetching 2026-02-06 11:53:11 -05:00
Georges-Antoine Assi
24912eb109 Also replace - with : in edge cases 2025-12-31 10:03:51 -05:00
Georges-Antoine Assi
4e0556c55b [HOTFIX] Fetch security token for HLTB 2025-12-15 09:47:07 -05:00
Georges-Antoine Assi
e8291978ab use stats endpoint for heartbeat in hltb 2025-11-22 22:32:08 -05:00
Georges-Antoine Assi
a50a2373bc add and update tests 2025-10-20 21:53:41 -04:00
Georges-Antoine Assi
dbf1a7d20b [ROMM-2554] Remove htlb from manual search 2025-10-17 09:51:41 -04:00
Georges-Antoine Assi
0fa7c4fd5b add error checking 2025-10-09 16:46:24 -04:00
Georges-Antoine Assi
996dc50f94 only fetch is hltb is enabled 2025-10-09 16:40:31 -04:00
Georges-Antoine Assi
a8b15bd78e cleanup 2025-10-09 16:39:39 -04:00
Georges-Antoine Assi
ffcf99a47b Fetch html search endpoint from file 2025-10-09 16:37:15 -04:00
Georges-Antoine Assi
c95b5b586b only set hltb if some properties exist 2025-10-02 17:38:41 -04:00
Georges-Antoine Assi
d11c83fc4a update hltb api endpoint 2025-10-02 10:58:20 -04:00
Georges-Antoine Assi
7a5185fe22 complete rest of handler 2025-09-20 19:38:26 -04:00
Georges-Antoine Assi
8c33a95637 remove hartbeat from bh endpoint 2025-09-20 17:57:38 -04:00
Georges-Antoine Assi
afc92e73ee Implement file tag matching for HLTB 2025-09-17 11:07:08 -04:00
Georges-Antoine Assi
0d89c15f1b generate hltb correctly 2025-09-16 10:48:26 -04:00
Georges-Antoine Assi
6032792e2f changes from pr review 2025-09-16 09:11:33 -04:00
Georges-Antoine Assi
f9f76e1d18 add rommm header to all requests 2025-09-15 11:13:33 -04:00
Georges-Antoine Assi
4ed1d82a46 add platform checks 2025-09-15 10:28:32 -04:00
Georges-Antoine Assi
123b3f6b8b create makeshift howlongtobeet handler 2025-09-14 19:39:38 -04:00