fix(valuation): prefer an artist the account already rosters for a Spotify id (chat#1889 row 8 follow-up)
Follow-up to api#791 — chat#1889 row 8. Found live by @sweetmantech during chat#1900's post-merge re-verification: the artist sidebar showed doubles again.
Why #791 wasn't enough
My "exactly 1 roster entry" assertion on the re-test raced the fire-and-forget valuation — it passed at +8s, and the valuation linked a second entry at ~+20s. Server truth after it completed:
0b91f38a… ← the row the chat client created (POST /api/artists + PATCH social)
7647f901… ← an old canonical, linked by the valuation's fallback
#791 stops the fallback minting a new row. But the chat flow creates its own artist row before the valuation runs — so when the global lookup resolves a different canonical for the same Spotify id, insertAccountArtistId links that one too. No new row minted, two roster entries anyway. My #791 verification called POST /api/valuation directly, with no client-created row in the picture, which is exactly why it passed.
What changed
findCanonicalArtistBySpotifyId(spotifyArtistId, accountId?) now collects every artist linked to the Spotify id and prefers one the requesting account already rosters — i.e. the row the client just created. Resolution stays global when the account rosters none of them (the cross-account reuse #791 verified is unchanged; accountId is used only for preference, never to scope the search).
Verification
TDD red → green:
# RED — global lookup resolves the old canonical over the account's own row
FAIL findCanonicalArtistBySpotifyId.test.ts > prefers an artist the requesting account already rosters
# GREEN — full api suite
Test Files 785 passed · Tests 4255 passed
The new preference test reproduces the live failure shape exactly (two socials, newest resolving to the client row, older to the old canonical, account rostering the client row). A second new test pins that global resolution survives when the account rosters nothing for the id. tsc at the 236 baseline; eslint clean.
Live verification after merge + test-sync: I'll re-run the full chat#1900 cold-start walk and this time assert the roster count after the valuation completes, not before — with a DB cross-check.
Tracked in chat#1889 (matrix row 8, reopening).
Summary by cubic
Fixes duplicate artist roster entries by making the Spotify canonical lookup prefer an artist the requesting account already rosters. Global reuse stays the same when the account has none.
- Bug Fixes
- Updated
findCanonicalArtistBySpotifyIdto collect all artists linked to the Spotify id and return one already rostered by the requesting account; otherwise falls back to the first global match. linkSearchedArtistToAccountnow passesaccountIdto the lookup to avoid linking a second, different artist.- Added tests to cover preference for the account’s artist and to ensure global resolution when the account rosters none.
- Updated