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:
paul
2026-06-16 06:36:41 +00:00
co-authored by Claude Opus 4.8
parent 779eba6cb1
commit 9f9858a050
6 changed files with 175 additions and 16 deletions
+6 -15
View File
@@ -6,10 +6,11 @@
// DIRECT artist links;
// * without creds -> MusicBrainz validation + Spotify/Bandcamp SEARCH links (zero setup).
// Either way a candidate only resolves when an artist's name matches it case-insensitively
// (the precision lever that keeps random capitalized words from being linked).
// (the precision lever). The pure matching/link logic lives in lib.js (unit-tested).
import { createServer } from "node:http";
import { readFileSync } from "node:fs";
import { norm, pickArtist, spotifyResult, searchResult } from "./lib.js";
// --- minimal .env loader (no dependency) ------------------------------------
try {
@@ -27,10 +28,6 @@ const USE_SPOTIFY = Boolean(SPOTIFY_ID && SPOTIFY_SECRET);
const UA = "reddit-spotify-linker/0.1 (https://git.yapplesauce.com/paul/linker)";
const MAX_CANDIDATES = 100;
const norm = (s) => String(s).normalize("NFKC").trim().toLowerCase();
const bandcampSearch = (n) => `https://bandcamp.com/search?q=${encodeURIComponent(n)}&item_type=b`;
const spotifySearch = (n) => `https://open.spotify.com/search/${encodeURIComponent(n)}`;
const cache = new Map(); // norm(name) -> { spotify, bandcamp, name } | null (negatives cached too)
// --- Spotify (optional) -----------------------------------------------------
@@ -57,13 +54,8 @@ async function viaSpotify(name) {
const r = await fetch(url, { headers: { authorization: `Bearer ${token}` } });
if (!r.ok) throw new Error(`spotify search http ${r.status}`);
const j = await r.json();
const hit = (j.artists?.items ?? []).find((a) => norm(a.name) === norm(name));
if (!hit) return null;
return {
name: hit.name,
spotify: hit.external_urls?.spotify ?? spotifySearch(hit.name),
bandcamp: bandcampSearch(hit.name),
};
const hit = pickArtist(name, j.artists?.items);
return hit ? spotifyResult(hit) : null;
}
// --- MusicBrainz (zero-cred fallback) ---------------------------------------
@@ -87,9 +79,8 @@ async function viaMusicBrainz(name) {
const r = await fetch(url, { headers: { "user-agent": UA, accept: "application/json" } });
if (!r.ok) throw new Error(`musicbrainz http ${r.status}`);
const j = await r.json();
const hit = (j.artists ?? []).find((a) => norm(a.name) === norm(name) && (a.score ?? 0) >= 90);
if (!hit) return null;
return { name: hit.name, spotify: spotifySearch(hit.name), bandcamp: bandcampSearch(hit.name) };
const hit = pickArtist(name, j.artists, { minScore: 90 });
return hit ? searchResult(hit) : null;
}
// --- resolve one candidate (cached) -----------------------------------------