Extract runCatalogTrackSearchCascade helper (#982)#985
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract the CTA → Discogs (Track 1 → Track 2) cascade slice into a single shared helper,
runCatalogTrackSearchCascade(query, limit, on_streaming?), exported fromlibrary.service.ts. BothsearchLibraryBothMode(powers/library/) andlibrary-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— cleannpm run lint— 0 errors (413 unchanged warnings on unrelated files)npm run format:check— cleannpm 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[], andon_streamingthreading into the CTA primitivenpm 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/querycascade behavior unchanged on the wireCloses #982