mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 11:21:07 +00:00
fix(regression): auto-enable channel setup discovery
This commit is contained in:
51
src/commands/channel-setup/discovery.test.ts
Normal file
51
src/commands/channel-setup/discovery.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const loadPluginManifestRegistry = vi.hoisted(() => vi.fn());
|
||||
const applyPluginAutoEnable = vi.hoisted(() => vi.fn(({ config }) => ({ config, changes: [] })));
|
||||
|
||||
vi.mock("../../plugins/manifest-registry.js", () => ({
|
||||
loadPluginManifestRegistry: (...args: unknown[]) => loadPluginManifestRegistry(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../../config/plugin-auto-enable.js", () => ({
|
||||
applyPluginAutoEnable: (...args: unknown[]) => applyPluginAutoEnable(...args),
|
||||
}));
|
||||
|
||||
import { listManifestInstalledChannelIds } from "./discovery.js";
|
||||
|
||||
describe("listManifestInstalledChannelIds", () => {
|
||||
beforeEach(() => {
|
||||
loadPluginManifestRegistry.mockReset();
|
||||
applyPluginAutoEnable.mockReset().mockImplementation(({ config }) => ({ config, changes: [] }));
|
||||
});
|
||||
|
||||
it("uses the auto-enabled config snapshot for manifest discovery", () => {
|
||||
const autoEnabledConfig = {
|
||||
channels: { slack: { enabled: true } },
|
||||
plugins: { allow: ["slack"] },
|
||||
autoEnabled: true,
|
||||
};
|
||||
applyPluginAutoEnable.mockReturnValue({ config: autoEnabledConfig, changes: ["slack"] });
|
||||
loadPluginManifestRegistry.mockReturnValue({
|
||||
plugins: [{ id: "slack", channels: ["slack"] }],
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
const installedIds = listManifestInstalledChannelIds({
|
||||
cfg: {} as never,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
env: { OPENCLAW_HOME: "/tmp/home" } as NodeJS.ProcessEnv,
|
||||
});
|
||||
|
||||
expect(applyPluginAutoEnable).toHaveBeenCalledWith({
|
||||
config: {},
|
||||
env: { OPENCLAW_HOME: "/tmp/home" },
|
||||
});
|
||||
expect(loadPluginManifestRegistry).toHaveBeenCalledWith({
|
||||
config: autoEnabledConfig,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
env: { OPENCLAW_HOME: "/tmp/home" },
|
||||
});
|
||||
expect(installedIds).toEqual(new Set(["slack"]));
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import type { ChannelMeta, ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import { listChatChannels } from "../../channels/registry.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { applyPluginAutoEnable } from "../../config/plugin-auto-enable.js";
|
||||
import { loadPluginManifestRegistry } from "../../plugins/manifest-registry.js";
|
||||
import type { ChannelChoice } from "../onboard-types.js";
|
||||
|
||||
@@ -31,10 +32,14 @@ export function listManifestInstalledChannelIds(params: {
|
||||
workspaceDir?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Set<ChannelChoice> {
|
||||
const workspaceDir = resolveWorkspaceDir(params.cfg, params.workspaceDir);
|
||||
const resolvedConfig = applyPluginAutoEnable({
|
||||
config: params.cfg,
|
||||
env: params.env ?? process.env,
|
||||
}).config;
|
||||
const workspaceDir = resolveWorkspaceDir(resolvedConfig, params.workspaceDir);
|
||||
return new Set(
|
||||
loadPluginManifestRegistry({
|
||||
config: params.cfg,
|
||||
config: resolvedConfig,
|
||||
workspaceDir,
|
||||
env: params.env ?? process.env,
|
||||
}).plugins.flatMap((plugin) => plugin.channels as ChannelChoice[]),
|
||||
|
||||
Reference in New Issue
Block a user