Files
romm/backend/tests/utils/test_sibling_groups.py
Georges-Antoine Assi ff412aa09c fix(siblings): group versions by connected component everywhere
The game page's siblings matched on any shared provider id, while the
gallery's group_by_meta_id window partitioned on the first non-null id in
a fixed provider order. A version matched by IGDB and ScreenScraper and
one matched by ScreenScraper alone were siblings on the game page but two
gallery cards. The recommendation surfaces didn't group at all: the
cold-start row ranks by rating, which every version shares, so one game
filled it.

rom_sibling_groups now stores each ROM's connected component over
rom_identity_keys, kept in step by add_rom/update_rom/delete_rom and
rebuilt after a scan. The sibling_roms view, the gallery window and the
recommendations all read it: the feed and similar games collapse each
game to one entry, exclude the other versions of a played game, and
show the version the grouped gallery shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 20:12:06 -04:00

29 lines
835 B
Python

from utils.sibling_groups import sibling_groups
def test_roms_sharing_no_key_are_left_out():
assert sibling_groups([(1, "a"), (2, "b")]) == {}
def test_a_shared_key_groups_under_the_lowest_id():
assert sibling_groups([(7, "a"), (3, "a")]) == {3: 3, 7: 3}
def test_a_chain_of_different_keys_is_one_group():
"""1 and 3 share nothing, but each shares a key with 2."""
rows = [(1, "igdb"), (2, "igdb"), (2, "ss"), (3, "ss")]
assert sibling_groups(rows) == {1: 1, 2: 1, 3: 1}
def test_merging_two_groups_keeps_the_lower_root():
rows = [(5, "a"), (6, "a"), (2, "b"), (9, "b"), (9, "c"), (6, "c")]
assert set(sibling_groups(rows).values()) == {2}
def test_separate_groups_stay_separate():
rows = [(1, "a"), (2, "a"), (3, "b"), (4, "b")]
assert sibling_groups(rows) == {1: 1, 2: 1, 3: 3, 4: 3}