From 72212e7bfd231241b431e66a8e80e368507531ad Mon Sep 17 00:00:00 2001 From: byrongamatos Date: Tue, 14 Jul 2026 01:21:51 +0200 Subject: [PATCH] fix(career): gig backfill offsets by qualifying taken, not picks length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit on #954: after the stakes loop appends near-bar songs, qualifying[len(picks):] overshoots and skips eligible qualifying songs — a stocked passport could still get a short set. Co-Authored-By: Claude Fable 5 --- plugins/career/routes.py | 12 +++++++----- tests/plugins/career/test_passports.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/career/routes.py b/plugins/career/routes.py index 802d236..b8bc5e1 100644 --- a/plugins/career/routes.py +++ b/plugins/career/routes.py @@ -722,18 +722,20 @@ def setup(app, context): # first gig is how stubs start. random per call = free re-roll. random.shuffle(qualifying) rest.sort(key=lambda s: -s["best_accuracy"]) - picks = qualifying[:max(1, size - cfg["stakes_songs"])] + qtaken = max(1, size - cfg["stakes_songs"]) + picks = qualifying[:qtaken] for s in rest: if len(picks) >= size: break picks.append(s) # Surplus qualifying songs backfill a short set — a mature passport - # with no near-bar songs left must still fill the bill. - for s in qualifying[len(picks):] if len(picks) < size else []: + # with no near-bar songs left must still fill the bill. Offset by how + # many QUALIFYING songs were taken, not len(picks): rest's stakes + # additions would otherwise skip eligible qualifying songs entirely. + for s in qualifying[qtaken:]: if len(picks) >= size: break - if s not in picks: - picks.append(s) + picks.append(s) if len(picks) < size: exclude = {s["filename"] for s in picks} picks.extend(_unplayed_genre_songs(gkey, exclude, size - len(picks))) diff --git a/tests/plugins/career/test_passports.py b/tests/plugins/career/test_passports.py index cfdf6af..469b14c 100644 --- a/tests/plugins/career/test_passports.py +++ b/tests/plugins/career/test_passports.py @@ -358,3 +358,16 @@ def test_gig_propose_backfills_from_surplus_qualifying(client, meta_db): res = client.post("/api/plugins/career/gigs/propose", json={"instrument": "guitar", "genre": "Ska", "size": 5}) assert len(res.json()["songs"]) == 5 + + +def test_gig_propose_backfill_offset_survives_stakes(client, meta_db): + # 4 qualifying + 1 near-bar stake, size 5: the stake must not shift the + # qualifying backfill window past eligible songs. + for i in range(4): + meta_db.add(f"q{i}.feedpak", 0, 0.9, genre="Reggae", arrangements=LEAD) + meta_db.add("near.feedpak", 0, 0.7, genre="Reggae", arrangements=LEAD) + res = client.post("/api/plugins/career/gigs/propose", + json={"instrument": "guitar", "genre": "Reggae", "size": 5}) + files = [s["filename"] for s in res.json()["songs"]] + assert len(files) == 5 and len(set(files)) == 5 + assert "near.feedpak" in files