feat(catalogs): claim-time canonical-artist roster attach + Spotify socials at ingest (chat#1850 P1)

Merged
SW
5mo ago
+575-5

What

The api half of chat#1850 P1 — two changes:

  1. 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's account_artist_ids when 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-signup POST /api/artists as the roster source of truth.
  2. Spotify socials at ingest (forward fix). Capture enrichment (linkSongsToArtists, the api#684 path) has Spotify track.artists ids in hand when auto-creating canonical artist accounts, but attached no socials — making canonicals unfindable by Spotify id. It now attaches https://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 same updateArtistSocials lib path PATCH /api/artists uses, 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 lint clean.

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 via get_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

Merge order

  1. 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.