|
| 1 | +// Thread-binding artifact parity contract for bundled channel plugins. |
| 2 | +// |
| 3 | +// Core resolves default thread placement from lightweight `thread-binding-api` |
| 4 | +// artifacts before full plugin loading (src/channels/plugins/thread-binding-api.ts). |
| 5 | +// This suite pins artifact exports to the runtime plugin's conversationBindings |
| 6 | +// so the fast path cannot drift from loaded-plugin behavior. |
| 7 | +import { beforeAll, describe, expect, it } from "vitest"; |
| 8 | +import { loadBundledPluginPublicSurface } from "../../../test-utils/bundled-plugin-public-surface.js"; |
| 9 | +import { |
| 10 | + getBundledChannelPluginAsync, |
| 11 | + listBundledChannelPluginIds, |
| 12 | +} from "./test-helpers/bundled-channel-plugin-loader.js"; |
| 13 | + |
| 14 | +// Bundled channels expected to ship a top-level thread-binding artifact. |
| 15 | +const THREAD_BINDING_ARTIFACT_PLUGIN_IDS = ["discord", "matrix"] as const; |
| 16 | + |
| 17 | +const MISSING_PUBLIC_SURFACE_PREFIX = "Unable to resolve bundled plugin public surface "; |
| 18 | + |
| 19 | +type ThreadBindingArtifactModule = { defaultTopLevelPlacement?: unknown }; |
| 20 | + |
| 21 | +async function loadThreadBindingArtifact( |
| 22 | + pluginId: string, |
| 23 | +): Promise<ThreadBindingArtifactModule | null> { |
| 24 | + try { |
| 25 | + return await loadBundledPluginPublicSurface<ThreadBindingArtifactModule>({ |
| 26 | + pluginId, |
| 27 | + artifactBasename: "thread-binding-api.js", |
| 28 | + }); |
| 29 | + } catch (error) { |
| 30 | + if (error instanceof Error && error.message.startsWith(MISSING_PUBLIC_SURFACE_PREFIX)) { |
| 31 | + return null; |
| 32 | + } |
| 33 | + throw error; |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +describe("bundled channel thread-binding artifact parity", () => { |
| 38 | + const artifactPlacements = new Map<string, unknown>(); |
| 39 | + |
| 40 | + beforeAll(async () => { |
| 41 | + for (const id of listBundledChannelPluginIds()) { |
| 42 | + const artifact = await loadThreadBindingArtifact(id); |
| 43 | + if (artifact) { |
| 44 | + artifactPlacements.set(id, artifact.defaultTopLevelPlacement); |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it("keeps the artifact table in sync with bundled channels that ship one", () => { |
| 50 | + expect([...artifactPlacements.keys()].toSorted()).toEqual([ |
| 51 | + ...THREAD_BINDING_ARTIFACT_PLUGIN_IDS, |
| 52 | + ]); |
| 53 | + }); |
| 54 | + |
| 55 | + it.each(THREAD_BINDING_ARTIFACT_PLUGIN_IDS)( |
| 56 | + "keeps the %s artifact placement equal to the runtime plugin default", |
| 57 | + async (id) => { |
| 58 | + const artifactPlacement = artifactPlacements.get(id); |
| 59 | + expect(["current", "child"]).toContain(artifactPlacement); |
| 60 | + |
| 61 | + const plugin = await getBundledChannelPluginAsync(id); |
| 62 | + expect(plugin?.conversationBindings?.defaultTopLevelPlacement).toBe(artifactPlacement); |
| 63 | + }, |
| 64 | + ); |
| 65 | +}); |
0 commit comments