Files
punktfunk/plugin-kit/test/errors.test.ts
T
enricobuehler d237646c66 fix(host,sdk,kit): library scanners sat in the nav, could not sync local art, and so never got their settings
Three symptoms on .21, two defects. Lutris and Heroic appeared in the console sidebar
they explicitly opt out of; Lutris's settings were unreachable from the Library
screen; and Lutris and Steam logged `sync (startup) failed: HostRequestError`.

**The sidebar is a publish gap.** The console is correct — it keeps
`category: "library"` plugins out of the nav (`uiPlugins`, app-shell.tsx) — but the
host reports no category for them at all. `defineLibraryPlugin` sets it and
`sdk/src/ui.ts` forwards it; what SHIPS does not. `@punktfunk/host` was bumped to
0.1.2 on 2026-07-20 and `category` landed 2026-08-05 without a bump, so the registry's
0.1.2 is the pre-category build and every installed scanner registers without one.
Bumps the SDK to 0.1.3 — **inert until it is published**.

Because the field rides the untyped `pf.request` seam so an older host ignores it
rather than rejecting the registration, dropping it is silent by design. `serveUi` now
reads its own directory entry back and warns once when a requested category did not
land, the same way `defineLibraryPlugin` already warns when a store claim did not take.
That is what turns the next occurrence into a log line instead of a bug report.

**The missing settings and the failed sync are ONE defect: a write/read disagreement
about `file://`.** `local_art_bytes` decodes a `file://` value before testing
containment; `validate_art_paths` handed the raw value to `Path::new`, where
`file:///home/u/c.jpg` is a RELATIVE path whose first component is `file:`. It
canonicalized against the cwd, failed, and read as "outside every art root". So the
host refused every cover the kit's own `fileUrl` helper emits — the documented way for
a plugin to publish local art — while the read path would have served those same files.

That the two symptoms share a cause is not obvious and is why this is one commit: the
Library screen's settings control renders only for `origin: "plugin"`, and a source
becomes `plugin` only once it holds a store CLAIM, which is taken during a successful
reconcile. Lutris failed at entry 0 and Steam at entry 3, so neither ever claimed its
store, both stayed `origin: "builtin"`, and neither got a settings button. Heroic
reconciled (its art is http(s)) and has had its settings all along; rom-manager was
never affected because zero entries meant it never applied.

`art_path_is_servable` now decodes first, so both halves of the confinement judge the
same string. Confinement itself is unchanged: an out-of-root path is still refused in
`file://` clothing, which the test asserts alongside the accept case.

Diagnosing this took the HOST's journal, because both surfaces that should have
explained it lied. `HostRequestError` stringified to its bare tag, so the sync engine's
`${e.cause}` logged `HostRequestError` and discarded the method, the path and the
host's own message; it now renders all three, including an object-shaped cause that
used to print `[object Object]`. And the host logged "payload carries a field this lane
may not set" for BOTH refusals in `check_entry_fields`, so a 400 about an art path read
as an auth problem — it now logs the real reason and the entry title.

Verified on .21 (Linux): 463 host tests pass, clippy clean under `-D warnings`,
`cargo fmt --all --check` clean. The new art test fails without the fix and passes with
it. plugin-kit 71 and SDK 72 tests pass, both typecheck clean, biome clean.
2026-08-08 11:43:30 +02:00

65 lines
2.5 KiB
TypeScript

// What a kit error says when something interpolates it — which is the whole diagnosis surface a
// plugin operator gets, because `sync-engine`'s failure path logs `${e.cause}` and nothing else.
import { describe, expect, test } from "bun:test";
import { HostRequestError } from "../src/errors.js";
describe("HostRequestError", () => {
// Regression for 2026-08-08: this printed the bare tag, so `plugin:lutris sync (startup)
// failed: HostRequestError` was the ENTIRE record of a host that had answered with a precise
// 400. Interpolation is the assertion because interpolation is what the sync engine does.
test("names the call and carries the host's explanation", () => {
const err = new HostRequestError({
method: "PUT",
path: "/library/provider/lutris?store=lutris",
cause: new Error("art.portrait: local art must be an image file"),
});
expect(`${err}`).toContain("PUT");
expect(`${err}`).toContain("/library/provider/lutris?store=lutris");
expect(`${err}`).toContain("art.portrait");
expect(`${err}`).not.toBe("HostRequestError");
});
// The host's rejection arrives as a parsed `{error: "…"}` body, not an Error. Left to default
// stringification that is `[object Object]` — the useful half lost a second way.
test("renders an object cause instead of [object Object]", () => {
const err = new HostRequestError({
method: "PUT",
path: "/library/provider/steam",
cause: { error: "art.header: local art must be an image file" },
});
expect(`${err}`).toContain("art.header");
expect(`${err}`).not.toContain("[object Object]");
});
// Error formatting must never itself throw: a cycle (or a BigInt) would make JSON.stringify
// blow up INSIDE the catch that is trying to report the original failure.
test("survives a cause that cannot be serialized", () => {
const cyclic: Record<string, unknown> = {};
cyclic.self = cyclic;
const err = new HostRequestError({
method: "GET",
path: "/library",
cause: cyclic,
});
expect(() => `${err}`).not.toThrow();
expect(`${err}`).toContain("/library");
});
// The tag stays matchable — `Effect.catchTag`/`_tag` narrowing must not be traded away for a
// readable message.
test("keeps its tag and its fields", () => {
const err = new HostRequestError({
method: "DELETE",
path: "/library/provider/heroic",
cause: "boom",
});
expect(err._tag).toBe("HostRequestError");
expect(err.method).toBe("DELETE");
expect(err.path).toBe("/library/provider/heroic");
});
});