import { afterEach, describe, expect, it } from "@suaveplan/testing/runner"; import { runWorkerHostConformance } from "./testing.js"; const cleanups: Array<() => void> = []; afterEach(() => { while (cleanups.length > 0) cleanups.pop()?.(); }); describe("runWorkerHostConformance", () => { it("boots with defaults and exposes the manifest", { timeout: 5000, }, () => { const h = runWorkerHostConformance(); cleanups.push(() => h.dispose()); expect(h.host.manifest.name).toBe("test-plugin"); }); it("drives a lifecycle install command through mainClient", { timeout: 5000, }, async () => { const calls: string[] = []; const h = runWorkerHostConformance({ hooks: { install: () => { calls.push("install"); }, }, }); cleanups.push(() => h.dispose()); const ack = (await h.mainClient.call("lifecycle.dispatch", [ { command: "install" }, ])) as { ok: boolean }; expect(ack.ok).toBe(true); expect(calls).toEqual(["install"]); }); it("round-trips a capability call against the stubbed handler", { timeout: 5000, }, async () => { const h = runWorkerHostConformance({ capabilityHandles: { db: { methods: ["query"] } }, capabilityHandlers: { "db.query": (params) => ({ echo: params[0] }), }, }); cleanups.push(() => h.dispose()); const query = h.host.capabilities.db?.query; if (query === undefined) throw new Error("missing"); expect(await query("ping")).toEqual({ echo: "ping" }); }); it("respects a manifest override", { timeout: 5000 }, () => { const h = runWorkerHostConformance({ manifest: { name: "override", version: "9.9.9", capabilities: ["x"], tier: "sandboxed", }, }); cleanups.push(() => h.dispose()); expect(h.host.manifest.name).toBe("override"); expect(h.host.manifest.tier).toBe("sandboxed"); }); });