Commit Graph

28 Commits

Author SHA1 Message Date
Georges-Antoine Assi
117f420dca Merge pull request #4013 from rommapp/fix/hashes-scan-rematches-hasheous
fix(backend): re-run the Hasheous hash lookup on a hashes scan
2026-07-30 19:23:56 -04:00
Georges-Antoine Assi
11f570fede fix(backend): clear a stale Hasheous match when a rehash no longer matches
A rehashed ROM whose new hashes no longer match Hasheous kept its old
`hasheous_id` and `hasheous_metadata`: the merge loop only writes truthy
values, so an empty match cannot overwrite the values seeded from the
existing ROM, and the verification flags stayed on a ROM that no longer
earned them.

Clearing on any empty match would be wrong, though: `lookup_rom` returns the
same empty fallback whether Hasheous answered "unknown hashes" or was simply
unreachable (#2236), so an outage would silently de-verify a whole library.
Have `lookup_rom` return whether it reached a definitive answer, mirroring
`meta_ss_handler.lookup_rom`, and only clear the match on a conclusive miss.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 19:13:57 -04:00
Georges-Antoine Assi
6fd2d9576c fix(backend): re-run the Hasheous hash lookup on a hashes scan
A ROM's "verified" state comes entirely from the Hasheous signature match
flags in `hasheous_metadata`, but `ScanType.HASHES` was missing from both
Hasheous gates in `scan_rom`. A rehash recomputed the file hashes and then
never re-asked Hasheous about them, so the verification chips stayed dark
(#4001). RetroAchievements was already gated in, which is why its provider
icon appeared while nothing lit up.

A follow-up update scan didn't help either: that branch is gated on
`rom.hasheous_id`, which is never set for a ROM that has yet to match.

Add `HASHES` to `fetch_hasheous_hash_match` and `fetch_hasheous_rom`, and
to the "don't overwrite existing base fields" branch: Hasheous now returns
a name/cover/summary on a rehash, and `_identify_rom` short-circuits before
the cover download, so a changed `url_cover` would point at an image that
is never fetched.

Fixes #4001

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 14:53:46 -04:00
Spinnich
c2786429fd fix(screenscraper): address review feedback on quota awareness
Four points from the PR review:

- Leave the process-global ScreenScraper state alone when a scan does not use
  ScreenScraper. DEV_MODE runs scans in-process, so overlapping scans could
  otherwise clear each other's learned limits and skipped ROMs.
- Return pacing to the defaults when the per-scan state resets. Priming re-reads
  the account moments later; should that fail, the conservative default is safe
  for whatever account the credentials now name, whereas the previous scan's
  allowance may be more than this one is entitled to.
- Stop a rate-limited ROM from trying the next lookup. A refusal that survives
  the retry now propagates out of the handler and is caught once per ROM in
  fetch_ss_rom, instead of being swallowed per call site and sending the caller
  on to spend another retried request against a budget that is already gone.
  _is_daily_quota_error excludes the rate-limit 429 so the two stay distinct.
- Hand the request slot back before inspecting and re-encoding a cover, so
  local image work no longer holds a ScreenScraper thread.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 13:55:19 +00:00
TowyTowy
27a013b1fd fix(scan): make Hasheous and SteamGridDB scan lookups fault-tolerant
HasheousHandler.lookup_rom and SGDBBaseHandler.get_details_by_names now
resolve to an empty match instead of raising, matching the best-effort
pattern already used by PlaymatchHandler.lookup_rom and
SGDBBaseHandler.get_rom_by_id, so one failing provider can't abort a
scan or discard the other providers' results (#2236).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 10:53:00 +02:00
Georges-Antoine Assi
4d9bef4d6e refactor(scan): handle SS daily-quota 429 in the handler
Move the quota-skip decision out of scan_handler and into the SS handler:
lookup_rom, get_rom, and get_rom_by_id now catch the daily-quota 429 and
return an empty SSRom, so the scan degrades to the other providers with no
quota-specific code at the call site. Non-429 errors still propagate.

scan_handler keeps only the fault-tolerant provider gather. The service
breaker still short-circuits repeat calls and manual search still surfaces
the 429 (it does not go through these swallow paths for name search).

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 17:09:03 -04:00
Georges-Antoine Assi
1ac31e9ff0 refactor(scan): move quota breaker into ScreenScraper service
Track the ScreenScraper daily quota where the knowledge lives: a breaker
in the service, tripped on the first HTTP 430/431 and reset at the start
of each scan. When tripped, _request() short-circuits the API call but
still raises the 429, so manual search keeps its clear "quota exhausted"
message while the scan catches it and falls back to the other providers.

Replaces the handler-level skip flag with this service-scoped breaker.

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 16:40:04 -04:00
Georges-Antoine Assi
1338999ae9 refactor(scan): track provider skip state on the handler, reset per scan
Move the "skip this provider for the rest of the scan" state off a set
threaded through scan_rom and onto the MetadataHandler base class, so each
provider tracks it internally. The state is cleared for every provider at
the start of each scan via reset_metadata_handlers_scan_state().

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 16:22:04 -04:00
Georges-Antoine Assi
fc938179e6 refactor(scan): drop user-facing warning for skipped provider
Background scans usually run with RomM closed, so the scan:warning toast
would rarely be seen. Keep the backend skip/fallback behavior and the log
line, and remove the socket event, its frontend handler, and the i18n key.

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 14:56:22 -04:00
Georges-Antoine Assi
ba208efff7 fix(scan): fall back to other providers when ScreenScraper quota is exhausted
When a user hit ScreenScraper's daily API quota mid-scan, the whole scan
stopped matching ROMs against every provider instead of just skipping SS.
The 429 raised for SS quota (HTTP 430/431) propagated out of the per-ROM
provider gather (which lacked return_exceptions), discarding the other
providers' results, and every subsequent ROM re-hit the exhausted API.

- Skip ScreenScraper for the rest of the scan on the first quota hit,
  tracked in a shared per-scan set, so remaining ROMs stop hammering it.
- Keep the current ROM's other-provider data when SS quota is hit.
- Make the provider gather fault-tolerant (return_exceptions) so one
  provider raising never discards the others' results.
- Notify the user once via a non-fatal scan:warning socket toast.

The manual-search path still surfaces the 429 quota message unchanged.

Fixes #3620

Generated-By: PostHog Code
Task-Id: 77dff3d9-6120-4156-bb25-1556a50a75e4
2026-07-05 14:16:21 -04:00
Georges-Antoine Assi
3c5228a9d9 test(scan): omit NotRequired name for no-match HasheousRom
name is NotRequired[str] on HasheousRom, so passing name=None fails mypy's
typeddict-item check. Omit it to represent a no-match result.

Generated-By: PostHog Code
Task-Id: 987bb9c1-1bfb-43f2-adc7-c26e69f06a39
2026-07-05 08:01:24 -04:00
Georges-Antoine Assi
d0dd847dd1 fix: use parsed filename for unmatched ROM titles instead of raw filename
Generated-By: PostHog Code
2026-07-05 07:47:33 -04:00
Claude
0b20ca331e fix(scan): replace placeholder filename with matched provider name
A ROM's name defaults to its raw filename (extension included) when it is
first discovered. On UNMATCHED and UPDATE rescans, the block that preserves
existing base fields kept that placeholder name even after a metadata
provider finally matched the ROM, leaving the filename (with its ".zip"
extension and region tags) as the title.

Treat a name equal to the ROM's filename as "no name" so a freshly matched
provider name replaces it, while still preserving user-edited names.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Shf4omKSP6dHC3dC2Jjg7b
2026-06-28 18:31:30 +00:00
Georges-Antoine Assi
99e8f08513 Use mD5/shA1 keys in Hasheous lookup payload
Match the json-patch camelCase key names the Hasheous endpoint expects,
and update the lookup_rom test assertions accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 09:36:31 -04:00
Georges-Antoine Assi
650ab6925c Send all top-level file hashes to Hasheous lookup
The Hasheous ByHash endpoint now accepts an array of hash objects rather
than a single one. Send the hashes of every top-level file (using
chd_sha1_hash exclusively for files that have one) to improve lookup
accuracy, instead of picking only the largest file.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 07:43:44 -04:00
Georges-Antoine Assi
f4512cb968 run fmt 2026-05-21 17:59:44 -04:00
Georges-Antoine Assi
600adb2c33 drop unused tests 2026-05-21 17:14:32 -04:00
copilot-swe-agent[bot]
90bbf6c9d1 fix: fetch metadata for manually-set IDs on UNMATCHED scan
When a user manually sets metadata IDs (e.g., ra_id, launchbox_id, hasheous_id)
via the UI and then runs "Refresh Metadata" (which defaults to UNMATCHED scan type),
no metadata was fetched because UNMATCHED conditions checked `not rom.xxx_id` — so
if the ID was already set, the handler was skipped entirely.

Fix: Change each handler's UNMATCHED condition to also trigger when the ID is set
but the corresponding metadata dict is empty (i.e., `not rom.xxx_id or not rom.xxx_metadata`).
For handlers that support ID-based lookup (RA, Launchbox, IGDB, MobyGames, SS,
Flashpoint), also add the `get_rom_by_id` path inside the function.

For Hasheous: when hash lookup fails but `hasheous_id` is set on an existing ROM
(not newly added), return a partial HasheousRom built from the existing sub-IDs
(igdb_id, ra_id, tgdb_id) so the downstream get_igdb_game / get_ra_game proxy
calls can still enrich the ROM.

Add three targeted tests to validate:
- UNMATCHED scan fetches RA metadata when ra_id is set but ra_metadata is empty
- UNMATCHED scan skips RA when both ra_id and ra_metadata are already populated
- UNMATCHED scan passes existing sub-IDs to Hasheous proxies when hash lookup fails

Agent-Logs-Url: https://github.com/rommapp/romm/sessions/098b482f-9f73-4f35-819a-b55004a79b13

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
2026-05-21 11:41:23 +00:00
Georges-Antoine Assi
a245ac7330 fix lint 2026-05-20 18:13:09 -04:00
Georges-Antoine Assi
aeb17b95a8 add tests 2026-05-20 18:10:25 -04:00
Georges-Antoine Assi
154165fadf final fixes 2026-04-12 19:26:34 -04:00
Georges-Antoine Assi
f1fb0c726e Disable fastapi_test 2025-12-07 10:40:07 -05:00
Georges-Antoine Assi
5018896396 Fix scan_rom tests 2025-11-26 15:54:12 -05:00
Georges-Antoine Assi
35bfe9ed61 fix tests 2025-09-25 20:44:11 -04:00
Georges-Antoine Assi
b5776be475 Split rom.multi into more specific fields 2025-09-25 18:48:27 -04:00
Georges-Antoine Assi
485b02d1c9 fix scan test 2025-09-23 19:03:24 -04:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Michael Manganiello
ba21cbc1e1 misc: Separate tests folder from backend code
Create separate `tests/` folder for all tests. This will also simplify
not copying tests code into the Docker image.
2025-08-08 12:49:13 -03:00