test: load narrow Discord inbound context harness

This commit is contained in:
Peter Steinberger
2026-04-08 07:03:21 +01:00
parent 8a9a3984e4
commit 9a65a5166f

View File

@@ -1,27 +1,27 @@
import { it } from "vitest";
import { expectChannelInboundContextContract } from "../../../src/channels/plugins/contracts/test-helpers.js";
import { loadBundledPluginTestApiSync } from "../../../src/test-utils/bundled-plugin-public-surface.js";
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
type BuildFinalizedDiscordDirectInboundContext =
() => import("../../../src/auto-reply/templating.js").MsgContext;
let buildFinalizedDiscordDirectInboundContextCache:
| BuildFinalizedDiscordDirectInboundContext
| undefined;
const discordInboundContextHarnessModuleId = resolveRelativeBundledPluginPublicModuleId({
fromModuleUrl: import.meta.url,
pluginId: "discord",
artifactBasename: "src/monitor/inbound-context.test-helpers.js",
});
function getBuildFinalizedDiscordDirectInboundContext(): BuildFinalizedDiscordDirectInboundContext {
if (!buildFinalizedDiscordDirectInboundContextCache) {
({ buildFinalizedDiscordDirectInboundContext: buildFinalizedDiscordDirectInboundContextCache } =
loadBundledPluginTestApiSync<{
buildFinalizedDiscordDirectInboundContext: BuildFinalizedDiscordDirectInboundContext;
}>("discord"));
}
return buildFinalizedDiscordDirectInboundContextCache;
async function getBuildFinalizedDiscordDirectInboundContext(): Promise<BuildFinalizedDiscordDirectInboundContext> {
const module = (await import(discordInboundContextHarnessModuleId)) as {
buildFinalizedDiscordDirectInboundContext: BuildFinalizedDiscordDirectInboundContext;
};
return module.buildFinalizedDiscordDirectInboundContext;
}
export function installDiscordInboundContractSuite() {
it("keeps inbound context finalized", () => {
const ctx = getBuildFinalizedDiscordDirectInboundContext()();
it("keeps inbound context finalized", async () => {
const buildContext = await getBuildFinalizedDiscordDirectInboundContext();
const ctx = buildContext();
expectChannelInboundContextContract(ctx);
});