One plugin = one repo, matching the house pattern (playnite, rom-manager and
virtualhere are already each their own repo with their own biome/bunfig/tsconfig
/CI). The implementation plan's WP5.0 had proposed a single workspace repo for
all six library scanners; this is the piece that makes the split cost nothing.
Everything the six scanners share is already published rather than adjacent: the
parsers and defineLibraryPlugin live in @punktfunk/plugin-kit/library, so repo
boundaries are irrelevant to them. Fixtures are not shared in practice either —
the Rust scanners build theirs inline in code, there are no fixture files, and
the one genuinely cross-plugin builder (binary shortcuts.vdf) is already in this
package's own tests. A pga.db fixture is useless to the epic plugin.
The parity harness was the exception: generic across all six, and parked in the
shared repo the plan assumed. It moves here.
What it is: the acceptance gate for an extracted scanner. Ported unit tests pin
the PARSERS; they do not prove the plugin reproduces the scanner it replaces. A
plugin that parses perfectly and emits steam:440.0 instead of steam:440 breaks
every Moonlight pin on the host and no parser test notices.
punktfunk-plugin-steam parity --snapshot before.json # host on its built-in
punktfunk-plugin-steam parity --compare before.json # offline; exits non-zero
--compare runs the plugin's own scan rather than requiring it to be installed
first, so a mismatch is visible before anything is published and the run is
repeatable while you fix it.
Three judgement calls in the diff, each pinned by a test:
* art is compared by PRESENCE, not value. The representation legitimately
changes on extraction (a host-relative proxy path or inlined data: URL
becomes a file:// path or a CDN URL), so comparing values would fail every
run for no reason. Losing an art kind fails; gaining one does not.
* launcher entries (role: "launcher") are reported separately instead of as
unexpected extras — the built-in scanner had no concept of them, so they can
never be in a baseline. An ORDINARY title the scanner never had still fails,
which is what catches a bad tool filter.
* absent and empty are the same thing in metadata: the host omits empty lists
and nulls, so a plugin sending genres: [] has not changed anything.
plugin-kit: tsc clean, 56 tests pass (10 new).
187 lines
6.3 KiB
TypeScript
187 lines
6.3 KiB
TypeScript
// The parity harness is the release gate for every extracted scanner, so the thing that decides
|
|
// pass/fail needs its own tests. The cases below are the ones that actually happen during a port:
|
|
// a lost title, a wrong id, a dropped launch recipe, art whose representation changed but whose
|
|
// presence didn't, and the launcher entries the plugin legitimately adds.
|
|
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
claimedLibraryId,
|
|
diffParity,
|
|
formatParityReport,
|
|
fromHostEntry,
|
|
fromProviderEntry,
|
|
type HostGameEntry,
|
|
} from "../src/library/parity.js";
|
|
import type { ProviderEntry } from "../src/wire.js";
|
|
|
|
/** What the host reports while its BUILT-IN steam scanner is producing the library. */
|
|
const hostEntry = (over: Partial<HostGameEntry> = {}): HostGameEntry => ({
|
|
id: "steam:440",
|
|
store: "steam",
|
|
title: "Team Fortress 2",
|
|
launch: { kind: "steam_appid", value: "440" },
|
|
// The scanner emits host-relative proxy paths the CLIENT resolves.
|
|
art: {
|
|
portrait: "/api/v1/library/art/steam:440/portrait",
|
|
hero: "/api/v1/library/art/steam:440/hero",
|
|
logo: null,
|
|
header: "/api/v1/library/art/steam:440/header",
|
|
},
|
|
platform: "PC",
|
|
...over,
|
|
});
|
|
|
|
/** What the extracted plugin produces for the same title. */
|
|
const pluginEntry = (over: Partial<ProviderEntry> = {}): ProviderEntry =>
|
|
({
|
|
external_id: "440",
|
|
title: "Team Fortress 2",
|
|
launch: { kind: "steam_appid", value: "440" },
|
|
// The plugin emits file:// paths and CDN URLs — a DIFFERENT representation of the same art.
|
|
art: {
|
|
portrait: "file:///home/u/.steam/appcache/librarycache/440/a/p.jpg",
|
|
hero: "https://cdn.cloudflare.steamstatic.com/steam/apps/440/library_hero.jpg",
|
|
header: "https://cdn.cloudflare.steamstatic.com/steam/apps/440/header.jpg",
|
|
},
|
|
platform: "PC",
|
|
...over,
|
|
}) as ProviderEntry;
|
|
|
|
describe("id mapping", () => {
|
|
test("a claimed entry's id is the scanner's id", () => {
|
|
// The whole migration rests on this one line: Moonlight pins, GameStream app ids and client
|
|
// art caches are all derived from it.
|
|
expect(claimedLibraryId("steam", "440")).toBe("steam:440");
|
|
expect(claimedLibraryId("heroic", "legendary:Quail")).toBe(
|
|
"heroic:legendary:Quail",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("diffParity", () => {
|
|
const base = [fromHostEntry(hostEntry())];
|
|
|
|
test("a faithful port passes, even though the art VALUES all changed", () => {
|
|
const r = diffParity(base, [fromProviderEntry("steam", pluginEntry())]);
|
|
expect(r.ok).toBe(true);
|
|
expect(r.matched).toBe(1);
|
|
expect(r.changed).toEqual([]);
|
|
expect(formatParityReport(r)).toContain("parity OK");
|
|
});
|
|
|
|
test("a lost title is reported as missing", () => {
|
|
const r = diffParity(base, []);
|
|
expect(r.ok).toBe(false);
|
|
expect(r.missing.map((e) => e.id)).toEqual(["steam:440"]);
|
|
expect(formatParityReport(r)).toContain("missing: steam:440");
|
|
});
|
|
|
|
test("a wrong id shows up as BOTH missing and extra — the loudest failure", () => {
|
|
// The exact shape of the bug this harness exists to catch: the plugin found the title, but
|
|
// under an id nothing downstream recognizes.
|
|
const r = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry({ external_id: "440.0" })),
|
|
]);
|
|
expect(r.ok).toBe(false);
|
|
expect(r.missing.map((e) => e.id)).toEqual(["steam:440"]);
|
|
expect(r.extra.map((e) => e.id)).toEqual(["steam:440.0"]);
|
|
});
|
|
|
|
test("a changed launch recipe is caught", () => {
|
|
const r = diffParity(base, [
|
|
fromProviderEntry(
|
|
"steam",
|
|
pluginEntry({ launch: { kind: "command", value: "steam" } }),
|
|
),
|
|
]);
|
|
expect(r.ok).toBe(false);
|
|
expect(r.changed).toEqual([
|
|
{
|
|
id: "steam:440",
|
|
field: "launch",
|
|
before: "steam_appid:440",
|
|
after: "command:steam",
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("a dropped launch recipe is caught (an unlaunchable tile)", () => {
|
|
const r = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry({ launch: null })),
|
|
]);
|
|
expect(r.changed.map((c) => c.field)).toEqual(["launch"]);
|
|
});
|
|
|
|
test("LOSING an art kind fails; gaining one does not", () => {
|
|
const lost = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry({ art: { portrait: null } })),
|
|
]);
|
|
expect(lost.ok).toBe(false);
|
|
expect(lost.changed.map((c) => c.field)).toContain("art.portrait");
|
|
|
|
// The baseline had no logo; the plugin resolves one. That is an improvement, and failing the
|
|
// run over it would only train people to ignore the harness.
|
|
const gained = diffParity(base, [
|
|
fromProviderEntry(
|
|
"steam",
|
|
pluginEntry({
|
|
art: { ...pluginEntry().art, logo: "file:///l.png" },
|
|
}),
|
|
),
|
|
]);
|
|
expect(gained.ok).toBe(true);
|
|
});
|
|
|
|
test("metadata drift is caught, but absent-vs-empty is not drift", () => {
|
|
const changed = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry({ platform: "Linux" })),
|
|
]);
|
|
expect(changed.changed).toEqual([
|
|
{ id: "steam:440", field: "meta.platform", before: "PC", after: "Linux" },
|
|
]);
|
|
// The host omits empty lists and nulls; a plugin sending them has changed nothing.
|
|
const noise = diffParity(base, [
|
|
fromProviderEntry(
|
|
"steam",
|
|
pluginEntry({ genres: [], tags: [], region: null } as never),
|
|
),
|
|
]);
|
|
expect(noise.ok).toBe(true);
|
|
});
|
|
|
|
test("launcher entries are expected extras, not failures", () => {
|
|
// The built-in scanner had no concept of a launcher entry, so it can never be in the
|
|
// baseline — reporting it as `extra` would fail every steam run forever.
|
|
const r = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry()),
|
|
fromProviderEntry(
|
|
"steam",
|
|
pluginEntry({
|
|
external_id: "ui:bigpicture",
|
|
title: "Steam Big Picture",
|
|
role: "launcher",
|
|
launch: { kind: "steam_ui", value: "bigpicture" },
|
|
art: {},
|
|
} as never),
|
|
),
|
|
]);
|
|
expect(r.ok).toBe(true);
|
|
expect(r.extra).toEqual([]);
|
|
expect(r.launchersAdded.map((e) => e.id)).toEqual(["steam:ui:bigpicture"]);
|
|
expect(formatParityReport(r)).toContain("+1 launcher entry");
|
|
});
|
|
|
|
test("an ordinary title the scanner never had IS a failure", () => {
|
|
// The mirror of the case above: only `role: "launcher"` gets the exemption, so a plugin that
|
|
// invents games (a bad filter, a tool listed as a game) still fails.
|
|
const r = diffParity(base, [
|
|
fromProviderEntry("steam", pluginEntry()),
|
|
fromProviderEntry(
|
|
"steam",
|
|
pluginEntry({ external_id: "228980", title: "Steamworks Common" }),
|
|
),
|
|
]);
|
|
expect(r.ok).toBe(false);
|
|
expect(r.extra.map((e) => e.id)).toEqual(["steam:228980"]);
|
|
});
|
|
});
|