feat: stewardship doctrine + zero-dep test infra (closes issue/linker-code-stewards-and-test-infra)
Stand up code stewards + testing for the linker, adapted to its JS/Node stack: - service/lib.js: extract the resolver's pure logic (norm + exact-name match + link builders) so it is unit-testable without the server side effect; resolver.js imports it. - service/lib.test.js: node:test coverage of the precision lever (7 tests). - scripts/check.sh: zero-dep gate (node --check + JSON validation + node --test). - AGENTS.md: repo doctrine — plain-repo push flow (NOT towl's PR pipeline), the three stewards (quality/design/security), the test gate, standing decisions (MV2 stays; no ML). Source: issue/linker-code-stewards-and-test-infra (inbox human-feedback 2026-06-16 — "should have a set of code stewards ... ensure a testing infra gets setup and maintained"). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Pure, side-effect-free helpers for the resolver. Kept separate from resolver.js
|
||||
// (which has the HTTP-server side effect) so they can be unit-tested with `node --test`
|
||||
// without starting a server. The artist-match precision lever lives here.
|
||||
|
||||
export const norm = (s) => String(s).normalize("NFKC").trim().toLowerCase();
|
||||
|
||||
export const bandcampSearch = (n) => `https://bandcamp.com/search?q=${encodeURIComponent(n)}&item_type=b`;
|
||||
export const spotifySearch = (n) => `https://open.spotify.com/search/${encodeURIComponent(n)}`;
|
||||
|
||||
// The precision lever: return the result whose name matches the candidate
|
||||
// case-insensitively, else null. `minScore` (MusicBrainz) additionally requires a
|
||||
// confidence score. Tolerates null/garbage items.
|
||||
export function pickArtist(name, items, { minScore = null } = {}) {
|
||||
const want = norm(name);
|
||||
return (
|
||||
(items ?? []).find(
|
||||
(a) => a && norm(a.name) === want && (minScore == null || (a.score ?? 0) >= minScore),
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
// Link object for a confirmed Spotify hit (direct artist url when present, else search).
|
||||
export const spotifyResult = (hit) => ({
|
||||
name: hit.name,
|
||||
spotify: hit.external_urls?.spotify ?? spotifySearch(hit.name),
|
||||
bandcamp: bandcampSearch(hit.name),
|
||||
});
|
||||
|
||||
// Link object for a confirmed MusicBrainz hit (search urls — MB gives no platform ids).
|
||||
export const searchResult = (hit) => ({
|
||||
name: hit.name,
|
||||
spotify: spotifySearch(hit.name),
|
||||
bandcamp: bandcampSearch(hit.name),
|
||||
});
|
||||
Reference in New Issue
Block a user