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>
52 lines
2.3 KiB
JavaScript
52 lines
2.3 KiB
JavaScript
// Unit tests for the resolver's pure logic (run with `node --test`). Zero-dep.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { norm, bandcampSearch, spotifySearch, pickArtist, spotifyResult, searchResult } from "./lib.js";
|
|
|
|
test("norm lowercases, trims, NFKC-normalizes", () => {
|
|
assert.equal(norm(" Cerebral Bore "), "cerebral bore");
|
|
assert.equal(norm("DEVOURMENT"), "devourment");
|
|
});
|
|
|
|
test("pickArtist matches case-insensitively, rejects non-matches", () => {
|
|
const items = [{ name: "Cattle Decapitation" }, { name: "Cerebral Bore" }];
|
|
assert.equal(pickArtist("cerebral bore", items)?.name, "Cerebral Bore");
|
|
assert.equal(pickArtist("CATTLE DECAPITATION", items)?.name, "Cattle Decapitation");
|
|
assert.equal(pickArtist("Notarealband", items), null);
|
|
});
|
|
|
|
test("pickArtist enforces minScore when given (MusicBrainz path)", () => {
|
|
const items = [{ name: "Devourment", score: 100 }, { name: "Devourment", score: 50 }];
|
|
assert.equal(pickArtist("Devourment", items, { minScore: 90 })?.score, 100);
|
|
assert.equal(pickArtist("Devourment", [{ name: "Devourment", score: 50 }], { minScore: 90 }), null);
|
|
});
|
|
|
|
test("pickArtist tolerates empty / garbage input", () => {
|
|
assert.equal(pickArtist("x", null), null);
|
|
assert.equal(pickArtist("x", []), null);
|
|
assert.equal(pickArtist("x", [null, { name: "y" }]), null);
|
|
});
|
|
|
|
test("spotifyResult prefers the direct url, falls back to search", () => {
|
|
const direct = spotifyResult({
|
|
name: "Devourment",
|
|
external_urls: { spotify: "https://open.spotify.com/artist/abc" },
|
|
});
|
|
assert.equal(direct.spotify, "https://open.spotify.com/artist/abc");
|
|
assert.match(direct.bandcamp, /^https:\/\/bandcamp\.com\/search\?q=Devourment/);
|
|
|
|
const noUrl = spotifyResult({ name: "Devourment" });
|
|
assert.equal(noUrl.spotify, "https://open.spotify.com/search/Devourment");
|
|
});
|
|
|
|
test("searchResult builds spotify + bandcamp search urls", () => {
|
|
const r = searchResult({ name: "Cerebral Bore" });
|
|
assert.equal(r.spotify, "https://open.spotify.com/search/Cerebral%20Bore");
|
|
assert.equal(r.bandcamp, "https://bandcamp.com/search?q=Cerebral%20Bore&item_type=b");
|
|
});
|
|
|
|
test("link builders url-encode", () => {
|
|
assert.equal(spotifySearch("A B"), "https://open.spotify.com/search/A%20B");
|
|
assert.ok(bandcampSearch("A&B").includes("A%26B"));
|
|
});
|