test: fix the Suspect sources tests CI rejected (#5410)
release / govulncheck (push) Successful in 15s
release / web (push) Successful in 1m23s
release / go (push) Successful in 1m36s
release / integration (push) Successful in 4m36s
release / android (push) Successful in 5m4s
release / Build signed APK (releases and dev) (push) Successful in 5m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 1m11s
release / Verify release artifacts (tag releases only) (push) Skipped

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 15:56:18 -04:00
co-authored by Claude Opus 5.5
parent 3f0540cb7a
commit 2205b2927b
3 changed files with 47 additions and 13 deletions
@@ -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();
});
});