From e2545f7da19dc3ec953fb0e4742647e8341df3c1 Mon Sep 17 00:00:00 2001 From: mignot Date: Sat, 5 Dec 2026 13:27:49 +0100 Subject: [PATCH 1/2] feat(genre-tree): expose the region lexicon itemId (grow-api next.17) --- packages/app-kit/package.json | 4 +- .../__fixtures__/grow/regionGenres.json | 3 + .../genre-tree/useRegionGenreLexicon.test.ts | 86 +++++++++++++++++++ .../src/genre-tree/useRegionGenreLexicon.ts | 13 ++- pnpm-lock.yaml | 10 +-- 5 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 packages/app-kit/src/genre-tree/useRegionGenreLexicon.test.ts diff --git a/packages/app-kit/package.json b/packages/app-kit/package.json index cbc4d89..6e82ba0 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.13 <0.2.0", + "@behindthemusictree/grow-api": ">=0.1.0-next.17 <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.13", + "@behindthemusictree/grow-api": "0.1.0-next.17", "@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/__fixtures__/grow/regionGenres.json b/packages/app-kit/src/genre-tree/__fixtures__/grow/regionGenres.json index 25605c7..13ca7c7 100644 --- a/packages/app-kit/src/genre-tree/__fixtures__/grow/regionGenres.json +++ b/packages/app-kit/src/genre-tree/__fixtures__/grow/regionGenres.json @@ -1,5 +1,6 @@ [ { + "itemId": "LOCAL:malay-world", "wikidataId": "LOCAL:malay-world", "uuid": "c9de6dc7-1e68-44ba-bc2c-fb3340f795c7", "name": "music of the Malay world", @@ -9,6 +10,7 @@ "viewsCount": 0 }, { + "itemId": "LOCAL:region-q100", "wikidataId": "LOCAL:region-q100", "uuid": "918f9b52-4d78-4232-81c3-637d4b490038", "name": "music of Boston", @@ -18,6 +20,7 @@ "viewsCount": 0 }, { + "itemId": "LOCAL:region-q10126", "wikidataId": "LOCAL:region-q10126", "uuid": "e386e7d0-5675-46c4-84fa-da7737695f44", "name": "music of Serang", diff --git a/packages/app-kit/src/genre-tree/useRegionGenreLexicon.test.ts b/packages/app-kit/src/genre-tree/useRegionGenreLexicon.test.ts new file mode 100644 index 0000000..b1c101a --- /dev/null +++ b/packages/app-kit/src/genre-tree/useRegionGenreLexicon.test.ts @@ -0,0 +1,86 @@ +import { describe, it, expect, beforeEach, vi } from "vitest"; +import { renderHook } from "@testing-library/react"; + +const { fetchMock, useQueryWithParseMock } = vi.hoisted(() => ({ + fetchMock: vi.fn(), + useQueryWithParseMock: vi.fn(), +})); + +vi.mock("../transport/useFetchWrapper", () => ({ + useFetchWrapper: () => ({ fetch: fetchMock }), +})); + +vi.mock("../transport/lib/use-query-with-parse", () => ({ + useQueryWithParse: (options: unknown) => useQueryWithParseMock(options), +})); + +import { useRegionGenreLexicon } from "./useRegionGenreLexicon"; +import { zRegionMapGenresResponse } from "@behindthemusictree/grow-api"; + +const getBackendBaseUrl = () => "https://backend.example.com"; + +const entry = (itemId: string, wikidataId: string, uuid: string) => ({ + itemId, + wikidataId, + uuid, + name: `Genre ${itemId}`, + treeName: "regional", + genrePlaylistUuid: null, + isUmbrella: false, + viewsCount: 3, +}); + +const localOverview = entry("LOCAL:region-q10690", "LOCAL:region-q10690", "3f0d7b1e-8a3c-4d57-9a53-2b7f4f9c0a11"); +const qidGenre = entry("Q11399", "Q11399", "5b2e4c9a-1d3f-4e6a-8b7c-9d0e1f2a3b4c"); + +describe("useRegionGenreLexicon", () => { + beforeEach(() => { + vi.clearAllMocks(); + useQueryWithParseMock.mockReturnValue({ data: undefined, isPending: true, isError: false }); + }); + + it("parses the response keeping itemId for LOCAL graph IDs and QIDs", () => { + const parsed = zRegionMapGenresResponse.parse([localOverview, qidGenre]); + + expect(parsed.map(({ itemId, uuid }) => ({ itemId, uuid }))).toEqual([ + { itemId: "LOCAL:region-q10690", uuid: localOverview.uuid }, + { itemId: "Q11399", uuid: qidGenre.uuid }, + ]); + }); + + it("stays disabled and not pending until enabled", () => { + const { result } = renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, false)); + + expect(result.current).toEqual({ entries: [], isError: false, isPending: false }); + expect(useQueryWithParseMock.mock.calls[0][0].enabled).toBe(false); + }); + + it("loads the lexicon once with an infinite cache, forwarding the abort signal", async () => { + const { result } = renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true)); + const options = useQueryWithParseMock.mock.calls[0][0]; + const signal = new AbortController().signal; + + expect(result.current).toEqual({ entries: [], isError: false, isPending: true }); + expect(options.queryKey).toEqual(["regionGenreLexicon"]); + expect(options.schema).toBe(zRegionMapGenresResponse); + expect(options.staleTime).toBe(Infinity); + await options.queryFn({ signal }); + expect(fetchMock).toHaveBeenCalledWith("regions/map/genres/", true, false, { signal }); + }); + + it("returns the parsed entries on success and flags an error on failure", () => { + useQueryWithParseMock.mockReturnValue({ data: [localOverview, qidGenre], isPending: false, isError: false }); + expect(renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true)).result.current).toEqual({ + entries: [localOverview, qidGenre], + isError: false, + isPending: false, + }); + + useQueryWithParseMock.mockReturnValue({ data: undefined, isPending: false, isError: true }); + expect(renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true)).result.current).toEqual({ + entries: [], + isError: true, + isPending: false, + }); + }); +}); diff --git a/packages/app-kit/src/genre-tree/useRegionGenreLexicon.ts b/packages/app-kit/src/genre-tree/useRegionGenreLexicon.ts index d95edec..5910141 100644 --- a/packages/app-kit/src/genre-tree/useRegionGenreLexicon.ts +++ b/packages/app-kit/src/genre-tree/useRegionGenreLexicon.ts @@ -8,8 +8,17 @@ import type { RegionGenreLexiconEntry } from "./schemas/reference"; const EMPTY_ENTRIES: RegionGenreLexiconEntry[] = []; -/** Every genre the region map index references, loaded once on demand (`regions/map/genres/`). */ -export function useRegionGenreLexicon(getBackendBaseUrl: () => string, enabled: boolean) { +/** + * Named so the declaration refers to the consumer's installed grow-api schema rather than inlining + * the entry fields of the grow-api this package was built against. + */ +export type RegionGenreLexicon = { entries: RegionGenreLexiconEntry[]; isError: boolean; isPending: boolean }; + +/** + * Every genre the region map index references, loaded once on demand (`regions/map/genres/`). + * Each entry's `itemId` is the index's item ID (a QID or a `LOCAL:` graph ID). + */ +export function useRegionGenreLexicon(getBackendBaseUrl: () => string, enabled: boolean): RegionGenreLexicon { const { fetch } = useFetchWrapper(getBackendBaseUrl); const { data, isError, isPending } = useQueryWithParse({ queryKey: genreSearchQueryKeys.regionLexicon(), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76ed4d5..32b6bf4 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.13 - version: 0.1.0-next.13(zod@4.6.7) + specifier: 0.1.0-next.17 + version: 0.1.0-next.17(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.13': - resolution: {integrity: sha512-zybtoAqso636ZYC8NwjiP/WSGqNqZYn5hhvV1gbRcQCBBHbWJ5Y1d6GrLvHnWoewZ9iWSDkbeI/7r8/QEbGKaA==} + '@behindthemusictree/grow-api@0.1.0-next.17': + resolution: {integrity: sha512-obyB6JQxwFoyDGbOiwRmWuC3izsqzabIJd2FbK4iLFYi4vasKVbgcgpngwji4TMn8+5dm6C8PxtgTzLqaU4+zQ==} 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.13(zod@4.6.7)': + '@behindthemusictree/grow-api@0.1.0-next.17(zod@4.6.7)': dependencies: zod: 4.6.7 From 6a9191865c47a0e003a3c6c5643d76ff29cbebd8 Mon Sep 17 00:00:00 2001 From: mignot Date: Sat, 5 Dec 2026 14:09:33 +0100 Subject: [PATCH 2/2] ci: pin github-workflows v6.9.1 for the test-file coverage fix --- .github/workflows/agent-drift.yml | 2 +- .github/workflows/org-conformance.yml | 2 +- .github/workflows/pr-title.yml | 2 +- .github/workflows/publish.yml | 6 +++--- .github/workflows/validate.yml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/agent-drift.yml b/.github/workflows/agent-drift.yml index 54d4fc2..0d310d0 100644 --- a/.github/workflows/agent-drift.yml +++ b/.github/workflows/agent-drift.yml @@ -9,6 +9,6 @@ concurrency: jobs: agent-drift: - uses: BehindTheMusicTree/github-workflows/.github/workflows/agent-drift.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/agent-drift.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 permissions: contents: read diff --git a/.github/workflows/org-conformance.yml b/.github/workflows/org-conformance.yml index 1b9a28c..a3b59a2 100644 --- a/.github/workflows/org-conformance.yml +++ b/.github/workflows/org-conformance.yml @@ -11,6 +11,6 @@ concurrency: jobs: org-conformance: - uses: BehindTheMusicTree/github-workflows/.github/workflows/org-conformance.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/org-conformance.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 permissions: contents: read diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index bf5fa2c..2a6ab22 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -15,4 +15,4 @@ concurrency: jobs: pr-title: - uses: BehindTheMusicTree/github-workflows/.github/workflows/pr-title.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/pr-title.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4ac1485..9f04156 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,7 @@ jobs: tag: permissions: contents: write - uses: BehindTheMusicTree/github-workflows/.github/workflows/release-tag.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/release-tag.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 with: app-id: ${{ vars.RELEASE_APP_ID }} secrets: @@ -49,7 +49,7 @@ jobs: uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 with: repository: BehindTheMusicTree/github-workflows - ref: b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + ref: 02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 path: .release-foundation persist-credentials: false @@ -99,7 +99,7 @@ jobs: needs: [tag, publish] # Ordinary pushes skip publishing and still reconcile the release PR. if: ${{ !cancelled() && needs.tag.result == 'success' && (needs.tag.outputs.tag == '' || needs.publish.result == 'success') }} - uses: BehindTheMusicTree/github-workflows/.github/workflows/release-please.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/release-please.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 with: app-id: ${{ vars.RELEASE_PR_APP_ID }} auto-merge: true diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 50f8850..7daea68 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -48,7 +48,7 @@ jobs: needs: build permissions: contents: read - uses: BehindTheMusicTree/github-workflows/.github/workflows/coverage.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0 + uses: BehindTheMusicTree/github-workflows/.github/workflows/coverage.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1 with: # Floor shared by both packages; their vitest configs keep stricter per-package thresholds. line: 85