fix: add channelRuntime regression coverage (#25462) (thanks @guxiaobo)

This commit is contained in:
Peter Steinberger
2026-03-03 01:26:36 +00:00
parent 469cd5b464
commit 1ca69c8fd7
2 changed files with 17 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import {
} from "../logging/subsystem.js";
import { createEmptyPluginRegistry, type PluginRegistry } from "../plugins/registry.js";
import { getActivePluginRegistry, setActivePluginRegistry } from "../plugins/runtime.js";
import type { PluginRuntime } from "../plugins/runtime/types.js";
import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
import type { RuntimeEnv } from "../runtime.js";
import { createChannelManager } from "./server-channels.js";
@@ -87,7 +88,7 @@ function installTestRegistry(plugin: ChannelPlugin<TestAccount>) {
setActivePluginRegistry(registry);
}
function createManager() {
function createManager(options?: { channelRuntime?: PluginRuntime["channel"] }) {
const log = createSubsystemLogger("gateway/server-channels-test");
const channelLogs = { discord: log } as Record<ChannelId, SubsystemLogger>;
const runtime = runtimeForLogger(log);
@@ -96,6 +97,7 @@ function createManager() {
loadConfig: () => ({}),
channelLogs,
channelRuntimeEnvs,
...(options?.channelRuntime ? { channelRuntime: options.channelRuntime } : {}),
});
}
@@ -165,4 +167,17 @@ describe("server-channels auto restart", () => {
expect(account?.enabled).toBe(true);
expect(account?.configured).toBe(true);
});
it("passes channelRuntime through channel gateway context when provided", async () => {
const channelRuntime = { marker: "channel-runtime" } as unknown as PluginRuntime["channel"];
const startAccount = vi.fn(async (ctx) => {
expect(ctx.channelRuntime).toBe(channelRuntime);
});
installTestRegistry(createTestPlugin({ startAccount }));
const manager = createManager({ channelRuntime });
await manager.startChannels();
expect(startAccount).toHaveBeenCalledTimes(1);
});
});