From 2205b2927bd54644eb11442346518ffc0b08e667 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 15:56:18 -0400 Subject: [PATCH] test: fix the Suspect sources tests CI rejected (#5410) - staticcheck QF1001: the nil-vs-empty check in TestSourceMarkersFor is now an early continue instead of a negated conjunction. - The page test mocks #lib/api/admin.js whole, so suspectSourcesNextOffset was undefined there. Its test moves to admin.suspect-sources.test.ts, beside admin.scan.test.ts, against the real module. Co-Authored-By: Claude Opus 5.5 --- internal/api/admin_suspect_sources_test.go | 5 ++- web/src/lib/api/admin.suspect-sources.test.ts | 43 +++++++++++++++++++ .../suspect-sources/suspect-sources.test.ts | 12 ------ 3 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 web/src/lib/api/admin.suspect-sources.test.ts diff --git a/internal/api/admin_suspect_sources_test.go b/internal/api/admin_suspect_sources_test.go index f92d52f9..2956838a 100644 --- a/internal/api/admin_suspect_sources_test.go +++ b/internal/api/admin_suspect_sources_test.go @@ -39,7 +39,10 @@ func TestSourceMarkersFor(t *testing.T) { } for _, c := range cases { got := sourceMarkersFor("/music/x/" + c.base) - if !slices.Equal(got, c.want) && !(len(got) == 0 && len(c.want) == 0) { + if len(got) == 0 && len(c.want) == 0 { + continue // nil and empty both mean "no markers" + } + if !slices.Equal(got, c.want) { t.Errorf("%s:\n got %v\n want %v", c.base, got, c.want) } } diff --git a/web/src/lib/api/admin.suspect-sources.test.ts b/web/src/lib/api/admin.suspect-sources.test.ts new file mode 100644 index 00000000..00caca9c --- /dev/null +++ b/web/src/lib/api/admin.suspect-sources.test.ts @@ -0,0 +1,43 @@ +import { describe, expect, test } from 'vitest'; +import { suspectSourcesNextOffset } from './admin'; +import type { AdminSuspectResponse, AdminSuspectTrack } from './types'; + +function track(id: string): AdminSuspectTrack { + return { + track_id: id, + title: id, + artist_id: 'ar', + artist_name: 'Artist', + album_id: 'al', + album_title: 'Album', + file_path: `/music/${id}.mp3`, + duration_sec: 180, + disc_number: null, + track_number: null, + markers: [] + }; +} + +function page(offset: number, total: number): AdminSuspectResponse { + return { + total, + limit: 50, + offset, + groups: [ + { directory: 'a', tracks: [track('1'), track('2')] }, + { directory: 'b', tracks: [track('3')] } + ] + }; +} + +// limit and total are in tracks, so the next offset must count tracks across +// groups, not the number of groups. +describe('suspectSourcesNextOffset', () => { + test('counts tracks, not groups', () => { + expect(suspectSourcesNextOffset(page(0, 10))).toBe(3); + }); + + test('stops at the total', () => { + expect(suspectSourcesNextOffset(page(7, 10))).toBeUndefined(); + }); +}); diff --git a/web/src/routes/admin/suspect-sources/suspect-sources.test.ts b/web/src/routes/admin/suspect-sources/suspect-sources.test.ts index 3a8bfe6b..96192d94 100644 --- a/web/src/routes/admin/suspect-sources/suspect-sources.test.ts +++ b/web/src/routes/admin/suspect-sources/suspect-sources.test.ts @@ -9,7 +9,6 @@ vi.mock('#lib/api/admin.js', () => ({ import SuspectSourcesPage from './+page.svelte'; import { createSuspectSourcesQuery } from '#lib/api/admin.js'; -import { suspectSourcesNextOffset } from '#lib/api/admin.js'; const mocked = createSuspectSourcesQuery as ReturnType; @@ -112,14 +111,3 @@ describe('Suspect sources page', () => { expect(screen.queryByRole('button', { name: /more/i })).not.toBeInTheDocument(); }); }); - -describe('suspectSourcesNextOffset', () => { - test('counts tracks, not groups, and stops at the total', () => { - const groups = [ - { directory: 'a', tracks: [track('1', '1.mp3', []), track('2', '2.mp3', [])] }, - { directory: 'b', tracks: [track('3', '3.mp3', [])] } - ]; - expect(suspectSourcesNextOffset(page(0, 10, groups))).toBe(3); - expect(suspectSourcesNextOffset(page(7, 10, groups))).toBeUndefined(); - }); -});