Commit Graph

12 Commits

Author SHA1 Message Date
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
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
75fcb8582c test: mint and search the same HLTB endpoint in the lazy-mint tests
The lazy-mint tests POSTed to a hard-coded /api/search/site while the handler
still defaulted search_url to /api/find, so the mint and the search addressed
unrelated endpoints and the tests would have passed with the two out of sync.

Handlers under test are now built pointed at one endpoint, requests go to
handler.search_url, and the mint is asserted against f"{search_url}/init" rather
than against search_init_url, which the mint reads and so can never contradict.

Stops naming /api/bleed throughout the file as well, since this branch is what
makes that endpoint dead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 14:44:25 -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
6cdac8ad6b test(hltb): cover the separator retry
Pins the behaviour the retry exists for and the limits it must respect: a
series prefix the catalogue omits resolves through the tail, a term that
matches whole is not searched twice, a term with no separator is not
either, and an entry with no recorded times is still no match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 17:08:07 -05: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