feat: Playnite library sync plugin + exporter
CI / exporter (push) Failing after 24s
CI / build (push) Failing after 25s
CI / publish (push) Has been skipped

A two-part Punktfunk plugin that syncs the Playnite library into the host
game library as the `playnite` provider:

- exporter/ — a minimal C# Playnite GenericPlugin ("Punktfunk Sync") that
  writes punktfunk-library.json on every library change. Reading Playnite's
  live-locked LiteDB from outside isn't robust, so this adapter runs inside
  Playnite. Builds net462 via reference assemblies; packaged as a .pext.
- src/ — the TS plugin (on @punktfunk/host, rom-manager shape): watches the
  export, embeds covers as data URLs, reconciles via
  PUT /library/provider/playnite, with a console-hosted web UI + standalone
  fallback + CLI. Launch = playnite://playnite/start/<id>, run by the host
  in the interactive session so Playnite performs the real launch.

Verified locally: backend tsc + 23 tests + biome clean, SPA build, C#
exporter build + .pext pack.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-18 23:35:35 +02:00
commit 6694be9848
48 changed files with 3885 additions and 0 deletions
+149
View File
@@ -0,0 +1,149 @@
import { describe, expect, test } from "bun:test";
import { resolveConfig } from "../src/config.js";
import {
computeEntries,
isGuid,
launchCommand,
} from "../src/engine/reconcile.js";
import type { ExportedGame, LibraryExport } from "../src/export-schema.js";
const G1 = "11111111-1111-1111-1111-111111111111";
const G2 = "22222222-2222-2222-2222-222222222222";
const game = (over: Partial<ExportedGame>): ExportedGame => ({
id: G1,
name: "Game",
installed: true,
hidden: false,
source: "Steam",
platforms: ["PC (Windows)"],
cover: null,
background: null,
icon: null,
...over,
});
const exp = (games: ExportedGame[]): LibraryExport => ({
schema: 1,
generatedAt: "2026-01-01T00:00:00Z",
playnite: { version: "10", mode: "Desktop" },
games,
});
const noArt = () => undefined;
describe("isGuid", () => {
test("accepts a real Playnite guid", () => {
expect(isGuid(G1)).toBe(true);
});
test("rejects junk", () => {
expect(isGuid("not-a-guid")).toBe(false);
expect(isGuid('570" & calc')).toBe(false);
});
});
describe("launchCommand", () => {
test("Windows uses start + playnite:// uri", () => {
expect(launchCommand(G1, "win32")).toEqual({
kind: "command",
value: `start "" "playnite://playnite/start/${G1}"`,
});
});
test("non-Windows falls back to xdg-open", () => {
expect(launchCommand(G1, "linux")?.value).toContain("xdg-open");
});
});
describe("computeEntries filtering", () => {
test("installedOnly drops uninstalled games", () => {
const config = resolveConfig({});
const { entries, report } = computeEntries({
exp: exp([game({ id: G1 }), game({ id: G2, installed: false })]),
config,
platform: "win32",
artFor: noArt,
});
expect(entries.map((e) => e.external_id)).toEqual([G1]);
expect(report.skipped[0]?.reason).toBe("not installed");
});
test("includeHidden lets hidden games through", () => {
const hidden = exp([game({ id: G1, hidden: true })]);
expect(
computeEntries({
exp: hidden,
config: resolveConfig({}),
platform: "win32",
artFor: noArt,
}).entries.length,
).toBe(0);
expect(
computeEntries({
exp: hidden,
config: resolveConfig({ filter: { includeHidden: true } }),
platform: "win32",
artFor: noArt,
}).entries.length,
).toBe(1);
});
test("source include/exclude is case-insensitive", () => {
const games = exp([
game({ id: G1, source: "Steam" }),
game({ id: G2, source: "GOG" }),
]);
const only = computeEntries({
exp: games,
config: resolveConfig({ filter: { sources: ["steam"] } }),
platform: "win32",
artFor: noArt,
});
expect(only.entries.map((e) => e.external_id)).toEqual([G1]);
const without = computeEntries({
exp: games,
config: resolveConfig({ filter: { excludeSources: ["GOG"] } }),
platform: "win32",
artFor: noArt,
});
expect(without.entries.map((e) => e.external_id)).toEqual([G1]);
});
test("invalid ids and empty titles are skipped", () => {
const { entries, report } = computeEntries({
exp: exp([game({ id: "bogus" }), game({ id: G2, name: " " })]),
config: resolveConfig({}),
platform: "win32",
artFor: noArt,
});
expect(entries.length).toBe(0);
expect(report.skipped.map((s) => s.reason).sort()).toEqual([
"invalid game id",
"no title",
]);
});
test("entries are title-sorted and per-source counted", () => {
const { entries, report } = computeEntries({
exp: exp([
game({ id: G1, name: "Zelda", source: "Nintendo" }),
game({ id: G2, name: "Antichamber", source: "Steam" }),
]),
config: resolveConfig({}),
platform: "win32",
artFor: noArt,
});
expect(entries.map((e) => e.title)).toEqual(["Antichamber", "Zelda"]);
expect(report.perSource).toEqual({ Nintendo: 1, Steam: 1 });
});
test("artFor result is attached", () => {
const { entries } = computeEntries({
exp: exp([game({ id: G1 })]),
config: resolveConfig({}),
platform: "win32",
artFor: () => ({ portrait: "data:image/png;base64,AAAA" }),
});
expect(entries[0]?.art?.portrait).toBe("data:image/png;base64,AAAA");
});
});