fix(valuation): deterministic oldest-first canonical pick (chat#1889 row 10)
Row 10 of the canonical-artist trilogy on chat#1889.
findCanonicalArtistBySpotifyId iterated socials newest-first, and enrichSearchedArtistProfile bumps socials.updated_at mid-flow — so the pick could flip between two lookups inside one add. Oldest-first is stable, and the oldest social is the true canonical (prod anchor: Ana Bárbara's 2025-05-30 row, shared by OneRPM org accounts + sweetmantech@gmail.com). No account context — per the 2026-07-29 decision that closed api#792.
TDD red→green: the new test stages a newest social resolving to a fresh duplicate and an older one resolving to the true canonical, and asserts the old one wins. 145 valuation+artists tests pass; tsc at the 236 baseline; eslint clean.
Sequencing: correctness is complete once database#49 (row 9) has collapsed existing duplicates — until then oldest-first is still a better pick than newest-first (stable + favors the true canonical) with no downside. Code-independent of api#793; no merge conflict (different files).
Tracked in chat#1889 (matrix row 10).
🤖 Generated with Claude Code
Summary by cubic
Make canonical artist selection deterministic by iterating socials oldest-first in findCanonicalArtistBySpotifyId to prevent flips when enrichSearchedArtistProfile updates socials.updated_at. Aligns with chat#1889 (row 10); no account context required.
- Bug Fixes
- Sort socials by
updated_atascending and traverse oldest-first to select the stable canonical. - Add a test where the newest social maps to a duplicate and the oldest maps to the canonical; asserts the oldest wins.
- Sort socials by
Summary by CodeRabbit
- Bug Fixes
- Improved consistency when identifying canonical artists by checking linked social accounts in a stable, oldest-first order.
- Preserved graceful handling when no linked account is found or an error occurs.