|
| 1 | +// Packaged doctor capability tests cover generated catalog lookup without plugin runtime loading. |
| 2 | +import path from "node:path"; |
| 3 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { |
| 5 | + cleanupTempDirs, |
| 6 | + makeTempRepoRoot, |
| 7 | + writeJsonFile, |
| 8 | +} from "../../../test/helpers/temp-repo.js"; |
| 9 | + |
| 10 | +const packageRootMock = vi.hoisted(() => ({ value: "" })); |
| 11 | +const channelPluginMocks = vi.hoisted(() => ({ |
| 12 | + getBundledChannelPlugin: vi.fn(() => undefined), |
| 13 | + getChannelPlugin: vi.fn(() => undefined), |
| 14 | +})); |
| 15 | + |
| 16 | +vi.mock("../../channels/plugins/bundled.js", () => ({ |
| 17 | + getBundledChannelPlugin: channelPluginMocks.getBundledChannelPlugin, |
| 18 | +})); |
| 19 | + |
| 20 | +vi.mock("../../channels/plugins/index.js", () => ({ |
| 21 | + getChannelPlugin: channelPluginMocks.getChannelPlugin, |
| 22 | +})); |
| 23 | + |
| 24 | +vi.mock("../../plugins/bundled-dir.js", () => ({ |
| 25 | + resolveBundledPluginsDir: () => undefined, |
| 26 | + resolveSourceCheckoutDependencyDiagnostic: () => null, |
| 27 | +})); |
| 28 | + |
| 29 | +vi.mock("../../infra/openclaw-root.js", () => ({ |
| 30 | + resolveOpenClawPackageRootSync: () => packageRootMock.value, |
| 31 | + resolveOpenClawPackageRoot: async () => packageRootMock.value, |
| 32 | +})); |
| 33 | + |
| 34 | +import { clearPluginMetadataLifecycleCaches } from "../../plugins/plugin-metadata-lifecycle.js"; |
| 35 | +import { getDoctorChannelCapabilities } from "./channel-capabilities.js"; |
| 36 | + |
| 37 | +const tempDirs: string[] = []; |
| 38 | + |
| 39 | +beforeEach(() => { |
| 40 | + const root = makeTempRepoRoot(tempDirs, "doctor-channel-packaged-"); |
| 41 | + packageRootMock.value = root; |
| 42 | + writeJsonFile(path.join(root, "package.json"), { name: "openclaw" }); |
| 43 | + writeJsonFile(path.join(root, "dist", "channel-catalog.json"), { |
| 44 | + entries: [ |
| 45 | + { |
| 46 | + name: "@openclaw/discord", |
| 47 | + openclaw: { |
| 48 | + channel: { |
| 49 | + id: "discord", |
| 50 | + label: "Discord", |
| 51 | + doctorCapabilities: { |
| 52 | + dmAllowFromMode: "topOnly", |
| 53 | + groupModel: "route", |
| 54 | + groupAllowFromFallbackToAllowFrom: false, |
| 55 | + warnOnEmptyGroupSenderAllowlist: false, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + ], |
| 61 | + }); |
| 62 | + clearPluginMetadataLifecycleCaches(); |
| 63 | + channelPluginMocks.getBundledChannelPlugin.mockReset().mockReturnValue(undefined); |
| 64 | + channelPluginMocks.getChannelPlugin.mockReset().mockReturnValue(undefined); |
| 65 | +}); |
| 66 | + |
| 67 | +afterEach(() => { |
| 68 | + packageRootMock.value = ""; |
| 69 | + clearPluginMetadataLifecycleCaches(); |
| 70 | + cleanupTempDirs(tempDirs); |
| 71 | + vi.restoreAllMocks(); |
| 72 | +}); |
| 73 | + |
| 74 | +describe("doctor channel capabilities in a packaged install", () => { |
| 75 | + it("reads Discord semantics from the generated catalog without loading a plugin", () => { |
| 76 | + expect(getDoctorChannelCapabilities("discord")).toEqual({ |
| 77 | + dmAllowFromMode: "topOnly", |
| 78 | + groupModel: "route", |
| 79 | + groupAllowFromFallbackToAllowFrom: false, |
| 80 | + warnOnEmptyGroupSenderAllowlist: false, |
| 81 | + }); |
| 82 | + expect(channelPluginMocks.getChannelPlugin).not.toHaveBeenCalled(); |
| 83 | + expect(channelPluginMocks.getBundledChannelPlugin).not.toHaveBeenCalled(); |
| 84 | + }); |
| 85 | +}); |
0 commit comments