feat(catalogs): claim-time canonical-artist roster attach + Spotify socials at ingest (chat#1850 P1)
Merged
SW
5mo ago+575+575+012345678901234567890123456789-5-5-0123456789
What
The api half of chat#1850 P1 — two changes:
- Claim-time canonical-artist roster attach.
POST /api/catalogs(snapshot path) now resolves the claimed songs' canonical artist through the songs graph — measured ISRCs →song_artists→ the dominant artist account (verified deterministic on the repro: 67/67 links to one account) — and inserts it into the claiming account'saccount_artist_idswhen absent. Runs on first claims (createSnapshotCatalog) AND idempotent re-claims (createCatalogHandler), so pre-fix claims heal on the next click. Best-effort: a failed attach never fails the claim. This replaces the marketing funnel's per-signupPOST /api/artistsas the roster source of truth. - Spotify socials at ingest (forward fix). Capture enrichment (
linkSongsToArtists, the api#684 path) has Spotifytrack.artistsids in hand when auto-creating canonical artist accounts, but attached no socials — making canonicals unfindable by Spotify id. It now attacheshttps://open.spotify.com/artist/{id}(case preserved — ids are case-sensitive base62; the legacy lowercasing corruption is a different write path and is not repeated here) via the sameupdateArtistSocialslib pathPATCH /api/artistsuses, skipping artists that already have a Spotify artist social.
New files (SRP, one exported function each): lib/supabase/song_artists/selectSongArtistsBySongs.ts (chunked batch select), lib/songs/getDominantSongArtist.ts (pure resolution, deterministic tie-break), lib/catalog/attachCanonicalArtistToAccount.ts, lib/songs/attachSpotifySocialsToArtists.ts.
Tests (TDD RED→GREEN)
- 5 new test files + 3 new cases in the 2 existing catalog test files; all written first and confirmed failing.
- Touched domains: 19 files / 110 tests green. Full suite: 718 files / 3,966 tests, all green.
pnpm exec tsc --noEmit: 200 errors — exactly the pre-existing baseline, none in touched files.pnpm lintclean.
Verification
- DB layer verified live post-backfill (see the database sibling PR): repro catalog
4b934253…filtered by the canonical roster artist returns 67 songs / 557,513,905 streams viaget_catalog_measurements_aggregate. - Pending (needs a deploy + authed funnel run): a brand-new funnel signup claiming a snapshot lands the canonical artist on its roster with zero duplicate artist accounts created.
Links
- Tracking: recoupable/chat#1850 (P1)
- Settled design: P1 implementer context
- Siblings: recoupable/docs#269 (contract) · recoupable/database#43 (backfill, applied+verified) · recoupable/marketing#46 (drop the duplicate mint)
Merge order
- docs → 2. database → 3. api (this PR) → 4. marketing. All PRs base
main.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
New Features
- Improved catalog creation and re-claim flows to automatically connect accounts with the most likely canonical artist when matching song data is available.
- Added automatic Spotify profile linking for artists when artist details are resolved.
-
Bug Fixes
- Better handles empty or incomplete song data, avoiding failures and keeping catalog processing resilient.
- Added safer fallback behavior so enrichment steps continue even if one lookup or update fails.