fix(valuation): name the catalog after the measured artist (chat#1942)
Closes row 1 of chat#1942 — the root cause behind 82 of 130 production catalogs (63%) being named "Valuation Catalog".
Problem
runValuationHandler L99-L103 called createSnapshotCatalog({ accountId, ownerId, snapshot }) and omitted name, so createSnapshotCatalog L50 fell back to DEFAULT_CATALOG_NAME. The parameter already existed and was already optional — it was simply never passed. The artist name was fetched by getArtist(...) three lines later in the same handler.
Change
- Hoist the
getArtistlookup abovecreateSnapshotCatalogand passname: searchedArtist?.name?.trim() || undefined. || undefinedrather than??:createSnapshotCatalogusesname ?? DEFAULT_CATALOG_NAME, so an empty-string Spotify name would have created a catalog literally named"". A blank name is treated as unresolved and the default still applies.- No contract change — the response shape is untouched, only the value of
catalog.name. That is why this row carries nodocsPR and merges first in the issue's sequencing.
Tests (TDD, red → green)
New lib/valuation/__tests__/runValuationHandler.test.ts — the first unit tests for this handler.
RED before the change (2 of 5 failing):
× names the catalog after the measured Spotify artist
→ expected "name": "Bad Bunny", received "ownerId": undefined (no name key)
× resolves the Spotify artist before materializing the catalog
→ AssertionError: expected 21 to be less than 20 (getArtist ran after the create)
GREEN after, with the whole domain green alongside it:
pnpm exec vitest run lib/valuation lib/catalog
Test Files 23 passed (23)
Tests 133 passed (133)
pnpm exec tsc --noEmit: 202 pre-existing errors on this branch and 202 on the stashed baseline — unchanged, none in lib/valuation. eslint + prettier --check clean on both touched files.
Verification plan
Preview-verified after the deployment builds: run POST /api/valuation for a real Spotify artist and confirm the returned catalog.name is the artist's name, then confirm a run whose Spotify lookup fails still returns a catalog rather than a 500. Results posted here.
Notes
- This stops the count at 82; it does not heal the existing rows. Healing them needs
PATCH /api/catalogs/{catalogId}— rows 2-3 of the issue. POST /api/catalogs(the manual claim path) already acceptsnameand is unaffected.
🤖 Generated with Claude Code
Summary by cubic
Names valuation catalogs after the measured Spotify artist instead of defaulting to "Valuation Catalog"; fixes the bug behind most production catalogs having the default name (chat#1942).
- Bug Fixes
- Hoisted
getArtist(...)beforecreateSnapshotCatalog(...)and passname: searchedArtist?.name?.trim() || undefined. - Preserve fallback: blank or missing names defer to
DEFAULT_CATALOG_NAME(prevents empty-string catalog names). - Added tests for naming, call order, unresolved artist behavior, blank names, and validation early-return.
- No API contract change; only the
catalog.namevalue is updated.
- Hoisted