Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/playground/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/`);
Expand All @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/e2e/mobile-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/app-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
22 changes: 4 additions & 18 deletions packages/app-kit/src/genre-tree/schemas/reference-genre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ 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 = {
...identity, ...counts, catalogue: counts, criteria, parent: identity, root: identity,
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,
};
Expand All @@ -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;
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -176,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);
});
});
29 changes: 5 additions & 24 deletions packages/app-kit/src/genre-tree/schemas/reference-genre.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/app-kit/src/genre-tree/schemas/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading