mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-20 21:51:28 +00:00
fix: auto-enable configured channel plugins in routed CLI commands (#54809) (thanks @neeravmakwana)
* CLI: auto-enable configured channel plugins in routed commands * fix: auto-enable configured channel plugins in routed CLI commands (#54809) (thanks @neeravmakwana) --------- Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
applyPluginAutoEnable: vi.fn(),
|
||||
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
||||
resolveDefaultAgentId: vi.fn(() => "main"),
|
||||
loadConfig: vi.fn(),
|
||||
@@ -18,6 +19,10 @@ vi.mock("../config/config.js", () => ({
|
||||
loadConfig: mocks.loadConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../config/plugin-auto-enable.js", () => ({
|
||||
applyPluginAutoEnable: mocks.applyPluginAutoEnable,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/loader.js", () => ({
|
||||
loadOpenClawPlugins: mocks.loadOpenClawPlugins,
|
||||
}));
|
||||
@@ -34,17 +39,6 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
mocks.loadConfig.mockReturnValue({
|
||||
plugins: { enabled: true },
|
||||
channels: { telegram: { enabled: false } },
|
||||
});
|
||||
mocks.loadPluginManifestRegistry.mockReturnValue({
|
||||
plugins: [
|
||||
{ id: "telegram", channels: ["telegram"] },
|
||||
{ id: "slack", channels: ["slack"] },
|
||||
{ id: "openai", channels: [] },
|
||||
],
|
||||
});
|
||||
mocks.getActivePluginRegistry.mockReturnValue({
|
||||
plugins: [],
|
||||
channels: [],
|
||||
@@ -52,20 +46,75 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("loads only configured channel plugins for configured-channels scope", async () => {
|
||||
it("uses the auto-enabled config snapshot for configured channel scope", async () => {
|
||||
const baseConfig = {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: "xoxb-test",
|
||||
appToken: "xapp-test",
|
||||
},
|
||||
},
|
||||
};
|
||||
const autoEnabledConfig = {
|
||||
...baseConfig,
|
||||
plugins: {
|
||||
entries: {
|
||||
slack: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
mocks.loadConfig.mockReturnValue(baseConfig);
|
||||
mocks.applyPluginAutoEnable.mockReturnValue({ config: autoEnabledConfig, changes: [] });
|
||||
mocks.loadPluginManifestRegistry.mockReturnValue({
|
||||
plugins: [{ id: "slack", channels: ["slack"] }],
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
const { ensurePluginRegistryLoaded } = await import("./plugin-registry.js");
|
||||
|
||||
ensurePluginRegistryLoaded({ scope: "configured-channels" });
|
||||
|
||||
expect(mocks.applyPluginAutoEnable).toHaveBeenCalledWith({
|
||||
config: baseConfig,
|
||||
env: process.env,
|
||||
});
|
||||
expect(mocks.resolveDefaultAgentId).toHaveBeenCalledWith(autoEnabledConfig);
|
||||
expect(mocks.resolveAgentWorkspaceDir).toHaveBeenCalledWith(autoEnabledConfig, "main");
|
||||
expect(mocks.loadPluginManifestRegistry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: autoEnabledConfig,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: [],
|
||||
config: autoEnabledConfig,
|
||||
onlyPluginIds: ["slack"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("reloads when escalating from configured-channels to channels", async () => {
|
||||
const config = {
|
||||
plugins: { enabled: true },
|
||||
channels: { telegram: { enabled: false } },
|
||||
};
|
||||
|
||||
mocks.loadConfig.mockReturnValue(config);
|
||||
mocks.applyPluginAutoEnable.mockReturnValue({ config, changes: [] });
|
||||
mocks.loadPluginManifestRegistry.mockReturnValue({
|
||||
plugins: [
|
||||
{ id: "telegram", channels: ["telegram"] },
|
||||
{ id: "slack", channels: ["slack"] },
|
||||
{ id: "openai", channels: [] },
|
||||
],
|
||||
diagnostics: [],
|
||||
});
|
||||
mocks.getActivePluginRegistry
|
||||
.mockReturnValueOnce({
|
||||
plugins: [],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
|
||||
import { createSubsystemLogger } from "../logging.js";
|
||||
import {
|
||||
resolveChannelPluginIds,
|
||||
@@ -44,7 +45,11 @@ export function ensurePluginRegistryLoaded(options?: { scope?: PluginRegistrySco
|
||||
return;
|
||||
}
|
||||
const config = loadConfig();
|
||||
const workspaceDir = resolveAgentWorkspaceDir(config, resolveDefaultAgentId(config));
|
||||
const resolvedConfig = applyPluginAutoEnable({ config, env: process.env }).config;
|
||||
const workspaceDir = resolveAgentWorkspaceDir(
|
||||
resolvedConfig,
|
||||
resolveDefaultAgentId(resolvedConfig),
|
||||
);
|
||||
const logger: PluginLogger = {
|
||||
info: (msg) => log.info(msg),
|
||||
warn: (msg) => log.warn(msg),
|
||||
@@ -52,14 +57,14 @@ export function ensurePluginRegistryLoaded(options?: { scope?: PluginRegistrySco
|
||||
debug: (msg) => log.debug(msg),
|
||||
};
|
||||
loadOpenClawPlugins({
|
||||
config,
|
||||
config: resolvedConfig,
|
||||
workspaceDir,
|
||||
logger,
|
||||
throwOnLoadError: true,
|
||||
...(scope === "configured-channels"
|
||||
? {
|
||||
onlyPluginIds: resolveConfiguredChannelPluginIds({
|
||||
config,
|
||||
config: resolvedConfig,
|
||||
workspaceDir,
|
||||
env: process.env,
|
||||
}),
|
||||
@@ -67,7 +72,7 @@ export function ensurePluginRegistryLoaded(options?: { scope?: PluginRegistrySco
|
||||
: scope === "channels"
|
||||
? {
|
||||
onlyPluginIds: resolveChannelPluginIds({
|
||||
config,
|
||||
config: resolvedConfig,
|
||||
workspaceDir,
|
||||
env: process.env,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user