test: move bundled channel config runtime into test helpers
This commit is contained in:
@@ -3,7 +3,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import { createChannelReplyPipeline } from "../runtime-api.js";
|
||||
|
||||
vi.mock("../../../src/config/bundled-channel-config-runtime.js", () => ({
|
||||
vi.mock("../../../test/helpers/config/bundled-channel-config-runtime.js", () => ({
|
||||
getBundledChannelRuntimeMap: () => new Map(),
|
||||
getBundledChannelConfigSchemaMap: () => new Map(),
|
||||
}));
|
||||
|
||||
@@ -3,7 +3,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
|
||||
import { createTestPluginApi } from "../../../test/helpers/plugins/plugin-api.js";
|
||||
import type { OpenClawConfig, OpenClawPluginApi } from "../runtime-api.js";
|
||||
|
||||
vi.mock("../../../src/config/bundled-channel-config-runtime.js", () => ({
|
||||
vi.mock("../../../test/helpers/config/bundled-channel-config-runtime.js", () => ({
|
||||
getBundledChannelRuntimeMap: () => new Map(),
|
||||
getBundledChannelConfigSchemaMap: () => new Map(),
|
||||
}));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
vi.mock("../../../src/config/bundled-channel-config-runtime.js", () => ({
|
||||
vi.mock("../../../test/helpers/config/bundled-channel-config-runtime.js", () => ({
|
||||
getBundledChannelRuntimeMap: () => new Map(),
|
||||
getBundledChannelConfigSchemaMap: () => new Map(),
|
||||
}));
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../../../test/helpers/plugins/start-account-lifecycle.js";
|
||||
import type { ResolvedNextcloudTalkAccount } from "./accounts.js";
|
||||
|
||||
vi.mock("../../../src/config/bundled-channel-config-runtime.js", () => ({
|
||||
vi.mock("../../../test/helpers/config/bundled-channel-config-runtime.js", () => ({
|
||||
getBundledChannelRuntimeMap: () => new Map(),
|
||||
getBundledChannelConfigSchemaMap: () => new Map(),
|
||||
}));
|
||||
|
||||
@@ -12,8 +12,11 @@ describe("bundled channel config runtime", () => {
|
||||
}));
|
||||
|
||||
const runtimeModule = await importFreshModule<
|
||||
typeof import("./bundled-channel-config-runtime.js")
|
||||
>(import.meta.url, "./bundled-channel-config-runtime.js?scope=missing-bundled-list");
|
||||
typeof import("../../test/helpers/config/bundled-channel-config-runtime.js")
|
||||
>(
|
||||
import.meta.url,
|
||||
"../../test/helpers/config/bundled-channel-config-runtime.js?scope=missing-bundled-list",
|
||||
);
|
||||
|
||||
expect(runtimeModule.getBundledChannelConfigSchemaMap().get("msteams")).toBeDefined();
|
||||
expect(runtimeModule.getBundledChannelRuntimeMap().get("msteams")).toBeDefined();
|
||||
@@ -28,9 +31,11 @@ describe("bundled channel config runtime", () => {
|
||||
};
|
||||
});
|
||||
|
||||
const runtime = await importFreshModule<typeof import("./bundled-channel-config-runtime.js")>(
|
||||
const runtime = await importFreshModule<
|
||||
typeof import("../../test/helpers/config/bundled-channel-config-runtime.js")
|
||||
>(
|
||||
import.meta.url,
|
||||
"./bundled-channel-config-runtime.js?scope=tdz-reference-error",
|
||||
"../../test/helpers/config/bundled-channel-config-runtime.js?scope=tdz-reference-error",
|
||||
);
|
||||
const configSchemaMap = runtime.getBundledChannelConfigSchemaMap();
|
||||
|
||||
|
||||
@@ -39,14 +39,6 @@ const CORE_SECRET_SURFACE_GUARDS = [
|
||||
/\bformatWhatsAppConfigAllowFromEntries\b/,
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "src/config/bundled-channel-config-runtime.ts",
|
||||
forbiddenPatterns: [
|
||||
/\bstaticBundledChannelSchemas\b/,
|
||||
/\bMSTeamsConfigSchema\b/,
|
||||
/\bWhatsAppConfigSchema\b/,
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "src/plugin-sdk/command-auth.ts",
|
||||
forbiddenPatterns: [/\bpluginId:\s*"telegram"/],
|
||||
|
||||
+3
-8
@@ -1,9 +1,9 @@
|
||||
import * as bundledChannelModule from "../channels/plugins/bundled.js";
|
||||
import * as bundledChannelModule from "../../../src/channels/plugins/bundled.js";
|
||||
import type {
|
||||
ChannelConfigRuntimeSchema,
|
||||
ChannelConfigSchema,
|
||||
} from "../channels/plugins/types.plugin.js";
|
||||
import { listBundledPluginMetadata } from "../plugins/bundled-plugin-metadata.js";
|
||||
} from "../../../src/channels/plugins/types.plugin.js";
|
||||
import { listBundledPluginMetadata } from "../../../src/plugins/bundled-plugin-metadata.js";
|
||||
|
||||
type BundledChannelRuntimeMap = ReadonlyMap<string, ChannelConfigRuntimeSchema>;
|
||||
type BundledChannelConfigSchemaMap = ReadonlyMap<string, ChannelConfigSchema>;
|
||||
@@ -69,9 +69,6 @@ function readBundledChannelPlugins(): readonly BundledChannelPluginShape[] | und
|
||||
const plugins = bundledChannelModule.listBundledChannelPlugins();
|
||||
return Array.isArray(plugins) ? (plugins as readonly BundledChannelPluginShape[]) : undefined;
|
||||
} catch (error) {
|
||||
// Circular bundled channel imports can transiently hit TDZ during test/bootstrap
|
||||
// initialization. Fall back to manifest-published contract surfaces until the
|
||||
// bundled registry is ready.
|
||||
if (error instanceof ReferenceError) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -86,8 +83,6 @@ function getBundledChannelMaps(): BundledChannelMaps {
|
||||
}
|
||||
|
||||
const maps = buildBundledChannelMaps(plugins ?? []);
|
||||
// Tests and some import cycles can temporarily expose an incomplete bundled list.
|
||||
// Only cache once the exported plugin array is actually available.
|
||||
if (plugins) {
|
||||
cachedBundledChannelMaps = maps;
|
||||
}
|
||||
Reference in New Issue
Block a user