Skip to content

Extract runCatalogTrackSearchCascade helper (#982)#985

Merged
jakebromberg merged 1 commit into
mainfrom
task/982-cascade-helper
May 21, 2026
Merged

Extract runCatalogTrackSearchCascade helper (#982)#985
jakebromberg merged 1 commit into
mainfrom
task/982-cascade-helper

Conversation

@jakebromberg
Copy link
Copy Markdown
Member

Summary

Extract the CTA → Discogs (Track 1 → Track 2) cascade slice into a single shared helper, runCatalogTrackSearchCascade(query, limit, on_streaming?), exported from library.service.ts. Both searchLibraryBothMode (powers /library/) and library-search.service.ts::runCascade (powers /library/query, added in #978) now call into it, eliminating the silent-drift risk of having two flag-gated cascade encodings.

The helper is the smallest factoring that holds: it owns flag-gating + layer ordering, returns raw TaggedLibraryViewEntry[], and leaves post-cascade work (filter, project, sort) at the caller because those concerns are shape-specific to each route.

Why now

#978 surfaced the duplication during review (folded into #982 as a refactor follow-up rather than blocking the original bug fix). Today the two encodings are semantically equivalent — but every future cascade change (per-layer telemetry, error isolation, cost guards, a Track 3 layer, union semantics) would have to be made twice without help from the compiler.

Test plan

  • npm run typecheck — clean
  • npm run lint — 0 errors (413 unchanged warnings on unrelated files)
  • npm run format:check — clean
  • npm run test:unit — 1999/1999 passing, including 8 new helper-direct tests (describe('runCatalogTrackSearchCascade (BS#982)')) covering: both flags off (early return, no primitives called), CTA-only / Discogs-only / both-on combinations, CTA-priority suppression of Discogs lookup, both-miss returning [], and on_streaming threading into the CTA primitive
  • npm run ci:test -- tests/integration/library.spec.js tests/integration/library-query.spec.js — 246/246 integration tests passing against the docker CI stack; both /library/ and /library/query cascade behavior unchanged on the wire

Closes #982

Both `searchLibraryBothMode` (/library/) and `library-search.service.ts::runCascade` (/library/query) encoded the CTA → Discogs cascade with the same flag gating but slightly different shapes. Factor the shared slice into a single exported helper in `library.service.ts` so the two callers can't drift on layer ordering or future per-layer concerns (telemetry, error isolation, cost guards).

Behavior is byte-identical: integration tests covering both routes pass unchanged. Helper-direct unit tests pin the contract (4 flag combos + on_streaming threading + early-return invariants).

Closes #982
@jakebromberg jakebromberg merged commit e315a99 into main May 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract runCatalogTrackSearchCascade helper shared by /library/ and /library/query

1 participant