Files
romm/backend/tests/endpoints/test_virtual_collection_id.py
Stu Anderson 0941b3033e feat(roms): load roms by an array of ids (#5663)
* feat(roms): load roms by an array of ids

GET /api/roms accepts up to 256 rom_ids and returns those roms in the
order given. Ids the caller can't see, or that don't exist, are left out.

Closes #5659

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(roms): code-review pass on rom_ids window

Reuse RomIdScope (dedupe, shared 500 cap), skip sidecar and grouped page
cache reads for a window by id, report offset 0 and the id count as limit,
and rename the shadowed rom_ids local in _transform.

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

* refactor(roms): simplify pass on rom_ids window

Return early for rom_ids before building the filtered query, the sidecars
or any cache key, through a shared _hydrate helper, so the paged path is
back to its prior shape. Tests use the headers fixture.

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

* test(roms): review-polish pass, cover a hidden platform in the rom_ids window

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

* fix(collections): refuse malformed virtual collection ids, require page-row visibility

A malformed virtual_collection_id raised an uncaught decode error (500) on
the gallery, random and bulk download routes. It is now a 422 at the query
boundary, and GET /collections/virtual/{id} answers 404.

get_page_rows_query takes visibility as a required argument, since it is
the access check on caller-supplied rom ids.

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

* feat(gallery): load scroll windows by rom id

Once the bootstrap holds the whole ordered id index, a window fetch sends
that slice as rom_ids, so the backend skips the filtered, offset-paged
query. Items are placed by id, since ids that went missing or hidden are
dropped from the response.

On a 100k-rom MariaDB library, a filtered grouped window went from
0.8-2.0 s to ~50 ms, and a deep ungrouped window from 106 to 50 ms.

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

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
2026-11-20 11:12:57 -05:00

32 lines
923 B
Python

import pytest
from fastapi import status
from fastapi.testclient import TestClient
MALFORMED_ID = "!!!"
@pytest.mark.parametrize(
"path",
["/api/roms", "/api/roms/random", "/api/roms/download"],
ids=["gallery", "random", "bulk download"],
)
def test_a_malformed_virtual_collection_id_is_refused(
client: TestClient, headers: dict[str, str], path: str
):
response = client.get(
path, headers=headers, params={"virtual_collection_id": MALFORMED_ID}
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
assert any(
"virtual_collection_id" in error["loc"] for error in response.json()["detail"]
)
def test_a_malformed_virtual_collection_is_not_found(
client: TestClient, headers: dict[str, str]
):
response = client.get(f"/api/collections/virtual/{MALFORMED_ID}", headers=headers)
assert response.status_code == status.HTTP_404_NOT_FOUND