From dcd197f146d6e316f2ba7130e19deefa2428cc8f Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:22:01 +0100 Subject: [PATCH 1/4] fix(genre-tree): adopt grow-api next.13 contract Pin grow-api 0.1.0-next.13 (peer >=0.1.0-next.13 <0.2.0) and use the generated reference genre roots directly, dropping the nullable and count workarounds. A song without a YouTube video is not playable. Co-Authored-By: Claude Sonnet 5.5 --- packages/app-kit/package.json | 4 +-- .../schemas/reference-genre.test.ts | 21 ++------------ .../src/genre-tree/schemas/reference-genre.ts | 29 ++++--------------- .../src/genre-tree/schemas/reference.ts | 2 +- pnpm-lock.yaml | 10 +++---- 5 files changed, 16 insertions(+), 50 deletions(-) diff --git a/packages/app-kit/package.json b/packages/app-kit/package.json index c339ebc..0543032 100644 --- a/packages/app-kit/package.json +++ b/packages/app-kit/package.json @@ -66,7 +66,7 @@ "test": "vitest run --coverage" }, "peerDependencies": { - "@behindthemusictree/grow-api": ">=0.1.0-next.9 <0.2.0", + "@behindthemusictree/grow-api": ">=0.1.0-next.13 <0.2.0", "@tanstack/react-query": ">=5.0.0", "next": ">=14.0.0", "react": ">=18.0.0", @@ -77,7 +77,7 @@ "zod": "^4.6.6" }, "devDependencies": { - "@behindthemusictree/grow-api": "0.1.0-next.8", + "@behindthemusictree/grow-api": "0.1.0-next.13", "@tanstack/react-query": "^5.72.2", "@testing-library/jest-dom": "^7.0.0", "@testing-library/react": "^16.3.2", diff --git a/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts b/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts index 33f2b3b..7d9028f 100644 --- a/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts +++ b/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts @@ -23,7 +23,7 @@ const identity = { uuid: "ec29efb8-3fc6-4e3b-9f24-98e9974d7979", name: "Jazz" }; const counts = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: { global: 139, regional: 2, all: 140 } }; const wikidataIdentity = { ...identity, wikidataId: "Q8341" }; const criteria = { - ...wikidataIdentity, parent: identity, createdOn: "2026-01-01T00:00:00Z", side: "core", + ...wikidataIdentity, parent: identity, createdOn: "2026-01-01T00:00:00Z", side: "core", treeName: "global", primaryParents: [], secondaryParents: [], }; const playlist = { @@ -31,7 +31,7 @@ const playlist = { tracksCount: 139, songsCount: 139, createdOn: "2026-01-01T00:00:00Z", updatedOn: null, isUnacceptedRoot: false, isUmbrella: false, scene: null, }; const detail = { - ...wikidataIdentity, catalogue: counts, criteriaPlaylist: { ...identity, ...counts }, + ...wikidataIdentity, summary: "Jazz", catalogue: counts, criteriaPlaylist: { ...identity, ...counts }, parent: null, root: wikidataIdentity, children: [], ascendants: [], side: "left", essentialSongs: [], tracksCount: 0, createdOn: "2026-01-01T00:00:00Z", updatedOn: null, }; @@ -42,10 +42,6 @@ describe("reference genre contracts", () => { expect(ReferenceGenrePlaylistSchema.parse([playlist])[0]).toMatchObject({ ...counts, catalogue: counts }); }); - it("accepts detail without a criteria playlist", () => { - expect(ReferenceGenreDetailedSchema.parse({ ...detail, criteriaPlaylist: null }).criteriaPlaylist).toBeNull(); - }); - it("rejects inconsistent catalogue and playlist counts", () => { const inclusive = (global: number, all: number) => ({ genreOnlyTracksCount: 5, genreAndSubgenresTracksCount: { global, regional: 5, all } }); const parse = (override: object) => ReferenceGenreDetailedSchema.safeParse({ ...detail, ...override }).success; @@ -90,22 +86,11 @@ describe("grow-api generated roots accept the captured responses", () => { ["searchArtists", zV1ArtistsSearchListResponse], ["searchGenres", zV1GenresSearchListResponse], ["artistCounts", zV1ArtistsGenreCountsListResponse], + ["playlistTracks", zV1GenrePlaylistsTracksListResponse], ])("%s", (name, schema) => { const result = schema.safeParse(fixture(name)); expect(result.error?.issues ?? []).toEqual([]); }); - - // grow-api#672: the backend sends `album: null` for tracks without album; the generated root requires an object. - it("playlistTracks differ from the generated root only by nullable albums", () => { - const page = fixture("playlistTracks"); - const issues = zV1GenrePlaylistsTracksListResponse.safeParse(page).error?.issues ?? []; - expect(issues.length).toBeGreaterThan(0); - expect(issues.every((issue) => issue.path.at(-1) === "album")).toBe(true); - - const withAlbum = structuredClone(page); - for (const rel of withAlbum.results) rel.track.album ??= { uuid: "00000000-0000-4000-8000-000000000001", name: "Album", albumArtists: [] }; - expect(zV1GenrePlaylistsTracksListResponse.safeParse(withAlbum).error?.issues ?? []).toEqual([]); - }); }); describe("refined reference schemas accept the captured responses", () => { diff --git a/packages/app-kit/src/genre-tree/schemas/reference-genre.ts b/packages/app-kit/src/genre-tree/schemas/reference-genre.ts index 1f04e77..e0bf907 100644 --- a/packages/app-kit/src/genre-tree/schemas/reference-genre.ts +++ b/packages/app-kit/src/genre-tree/schemas/reference-genre.ts @@ -1,8 +1,6 @@ import { z } from "zod"; import { zV1GenresRetrieveResponse, zV1GenrePlaylistsTreeListResponse } from "@behindthemusictree/grow-api"; -import { CriteriaDetailedSchema } from "./criteria/detailed"; import { CriteriaPlaylistSimpleSchema } from "./criteria-playlist/simple"; -import { GenreCountsSchema, GenrePlaylistSummarySchema } from "./genre-music"; interface GenreCountsShape { genreOnlyTracksCount: number; @@ -21,30 +19,13 @@ function checkGenreCounts(counts: GenreCountsShape, path: (string | number)[], c } } -// The previous local schema accepted a null `criteriaPlaylist` (a genre without a playlist); the generated root -// declares it non-null. Keep it nullable here until grow-api#672 settles the contract. -export const ReferenceGenreDetailedSchema = zV1GenresRetrieveResponse - .extend({ criteriaPlaylist: zV1GenresRetrieveResponse.shape.criteriaPlaylist.nullable() }) - .superRefine((genre, ctx) => { - checkGenreCounts(genre.catalogue, ["catalogue"], ctx); - if (genre.criteriaPlaylist) checkGenreCounts(genre.criteriaPlaylist, ["criteriaPlaylist"], ctx); - }); - - -// grow-api@0.1.0-next.8 omits the playlist-level genre counts that the backend sends (grow-api#672 declares them); -// they are read here so the invariants hold, and the extension is redundant once next.9 is the floor. -const generatedTreeRow = zV1GenrePlaylistsTreeListResponse.element; - -// The backend sends null for a root playlist's `parent` and `criteria` (and a root criteria's `parent`); the generated -// roots declare them non-null. Relax them here until grow-api declares the nullability. -const ReferenceGenrePlaylistRowSchema = generatedTreeRow.extend({ - ...GenreCountsSchema.shape, - criteria: generatedTreeRow.shape.criteria - .extend({ parent: generatedTreeRow.shape.criteria.shape.parent.nullable() }) - .nullable(), - parent: generatedTreeRow.shape.parent.nullable(), +export const ReferenceGenreDetailedSchema = zV1GenresRetrieveResponse.superRefine((genre, ctx) => { + checkGenreCounts(genre.catalogue, ["catalogue"], ctx); + if (genre.criteriaPlaylist) checkGenreCounts(genre.criteriaPlaylist, ["criteriaPlaylist"], ctx); }); +const ReferenceGenrePlaylistRowSchema = zV1GenrePlaylistsTreeListResponse.element; + export const ReferenceGenrePlaylistSchema = z.array(ReferenceGenrePlaylistRowSchema).superRefine((playlists, ctx) => { playlists.forEach((playlist, index) => { checkGenreCounts(playlist, [index], ctx); diff --git a/packages/app-kit/src/genre-tree/schemas/reference.ts b/packages/app-kit/src/genre-tree/schemas/reference.ts index 9e685da..8be9207 100644 --- a/packages/app-kit/src/genre-tree/schemas/reference.ts +++ b/packages/app-kit/src/genre-tree/schemas/reference.ts @@ -32,5 +32,5 @@ export interface GenreSearchParams { /** A song is playable when it has a video with no unplayable reason. */ export function isSongSearchResultPlayable(result: SongSearchResult): boolean { - return result.youtubeVideo.unplayableReason === null; + return result.youtubeVideo !== null && result.youtubeVideo.unplayableReason === null; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 399f11d..fd48a6c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -103,8 +103,8 @@ importers: version: 4.6.7 devDependencies: '@behindthemusictree/grow-api': - specifier: 0.1.0-next.8 - version: 0.1.0-next.8(zod@4.6.7) + specifier: 0.1.0-next.13 + version: 0.1.0-next.13(zod@4.6.7) '@tanstack/react-query': specifier: ^5.72.2 version: 5.101.4(react@18.3.1) @@ -360,8 +360,8 @@ packages: react: '>=18.0.0' react-dom: '>=18.0.0' - '@behindthemusictree/grow-api@0.1.0-next.8': - resolution: {integrity: sha512-UZNGzQvH7g05JaJQd+nxBk/HxwzKfD6Kb6So0Vxq4lDFXcEDlkZ44cXFSbgMHshZ3dtX23aw//tRgznJT08R4A==} + '@behindthemusictree/grow-api@0.1.0-next.13': + resolution: {integrity: sha512-zybtoAqso636ZYC8NwjiP/WSGqNqZYn5hhvV1gbRcQCBBHbWJ5Y1d6GrLvHnWoewZ9iWSDkbeI/7r8/QEbGKaA==} peerDependencies: zod: ^4.6.0 @@ -2349,7 +2349,7 @@ snapshots: react-dom: 18.3.1(react@18.3.1) react-icons: 5.7.0(react@18.3.1) - '@behindthemusictree/grow-api@0.1.0-next.8(zod@4.6.7)': + '@behindthemusictree/grow-api@0.1.0-next.13(zod@4.6.7)': dependencies: zod: 4.6.7 From a5fd54e854e39aad60fc4b3f0240a4c90dab95aa Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:23:03 +0100 Subject: [PATCH 2/4] test(genre-tree): cover song without video as unplayable Co-Authored-By: Claude Sonnet 5.5 --- packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts b/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts index 7d9028f..f4bbb13 100644 --- a/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts +++ b/packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts @@ -161,5 +161,6 @@ describe("isSongSearchResultPlayable", () => { const result = (unplayableReason: string | null) => ({ youtubeVideo: { unplayableReason } }) as unknown as SongSearchResult; expect(isSongSearchResultPlayable(result(null))).toBe(true); expect(isSongSearchResultPlayable(result("blocked"))).toBe(false); + expect(isSongSearchResultPlayable({ youtubeVideo: null } as unknown as SongSearchResult)).toBe(false); }); }); From f11a385c957923499221f0ec6836f818c9632a9d Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:29:22 +0100 Subject: [PATCH 3/4] test(playground): add treeName to e2e criteria fixtures Co-Authored-By: Claude Sonnet 5.5 --- apps/playground/e2e/fixtures.ts | 2 +- apps/playground/e2e/mobile-search.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/playground/e2e/fixtures.ts b/apps/playground/e2e/fixtures.ts index aa9cc30..44f1d3d 100644 --- a/apps/playground/e2e/fixtures.ts +++ b/apps/playground/e2e/fixtures.ts @@ -7,7 +7,7 @@ const counts = { genreOnlyTracksCount: 0, genreAndSubgenresTracksCount: { global const genres = [{ uuid: pop, name: "Picture Pop" }, { uuid: rock, name: "Imageless Rock" }]; const playlists = genres.map((genre, index) => { const uuid = `20000000-0000-4000-8000-00000000000${index + 1}`; - const criteria = { ...genre, wikidataId: null, parent: null, createdOn: "2026-01-01T00:00:00Z", side: "core", + const criteria = { ...genre, wikidataId: null, parent: null, createdOn: "2026-01-01T00:00:00Z", side: "core", treeName: "global", primaryParents: [], secondaryParents: [] }; return { uuid, name: genre.name, criteria, root: { uuid, name: genre.name }, parent: null, tracksCount: 0, songsCount: 0, ...counts, catalogue: counts, viewsCount: 0, isUnacceptedRoot: false, diff --git a/apps/playground/e2e/mobile-search.spec.ts b/apps/playground/e2e/mobile-search.spec.ts index 01e518f..041b3b1 100644 --- a/apps/playground/e2e/mobile-search.spec.ts +++ b/apps/playground/e2e/mobile-search.spec.ts @@ -11,7 +11,7 @@ const counts = { genreOnlyTracksCount: 1, genreAndSubgenresTracksCount: { all: 1 const tree = [{ ...playlist, ...counts, parent: null, root: playlist, criteria: { - ...genre, wikidataId: null, parent: null, createdOn: "2026-01-01T00:00:00Z", side: "core", + ...genre, wikidataId: null, parent: null, createdOn: "2026-01-01T00:00:00Z", side: "core", treeName: "global", primaryParents: [], secondaryParents: [], }, catalogue: counts, tracksCount: 1, songsCount: 1, createdOn: "2026-01-01T00:00:00Z", From 01cf89a2b805fdde08d041b0329da4ad135a5611 Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:40:40 +0100 Subject: [PATCH 4/4] test(playground): align e2e artist and genre fixtures with next.13 contract Co-Authored-By: Claude Sonnet 5.5 --- apps/playground/e2e/fixtures.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/playground/e2e/fixtures.ts b/apps/playground/e2e/fixtures.ts index 44f1d3d..2d194ac 100644 --- a/apps/playground/e2e/fixtures.ts +++ b/apps/playground/e2e/fixtures.ts @@ -40,7 +40,7 @@ export const test = base.extend<{ fixtureApi: void }>({ else if (path === `artists/${artistUuid}/`) data = { uuid: artistUuid, name: "Cover Artist", musicbrainzArtistId: null, type: "person", country: null, beginYear: null, endYear: null, ended: false, links: [], members: [], memberOf: [], albums: [], - tracksCount: 0, playableTracksCount: 0, image, origin: null, createdOn: "2026-01-01T00:00:00Z", + tracksCount: 0, playableTracksCount: 0, image, origin: null, createdOn: "2026-01-01T00:00:00Z", updatedOn: null, }; else { const genre = genres.find((genre) => path === `genres/${genre.uuid}/` || path === `genres/${genre.uuid}/overview/`); @@ -49,7 +49,7 @@ export const test = base.extend<{ fixtureApi: void }>({ ...genre, summary: `${genre.name} summary. `.repeat(100), description: null, summarySourceUrl: null, side: null, essentialSongs: [], image: genre.uuid === pop ? image : null, } : { ...genre, summary: null, parent: null, ascendants: [], children: [], root: { ...genre, wikidataId: null }, - catalogue: counts, criteriaPlaylist: null, essentialSongs: [], tracksCount: 0, updatedOn: null, + catalogue: counts, criteriaPlaylist: { uuid: playlists[genres.indexOf(genre)].uuid, name: genre.name, ...counts }, essentialSongs: [], tracksCount: 0, updatedOn: null, side: null, createdOn: "2026-01-01T00:00:00Z", wikidataId: null }; } else { unexpected.push(`${route.request().method()} ${path}${url.search}`);