mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
fix(config): auto-enable configured plugins
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
import { applyPluginAutoEnable } from "./plugin-auto-enable.js";
|
import { applyPluginAutoEnable } from "./plugin-auto-enable.js";
|
||||||
|
|
||||||
describe("applyPluginAutoEnable", () => {
|
describe("applyPluginAutoEnable", () => {
|
||||||
it("configures channel plugins with disabled state and updates allowlist", () => {
|
it("auto-enables channel plugins and updates allowlist", () => {
|
||||||
const result = applyPluginAutoEnable({
|
const result = applyPluginAutoEnable({
|
||||||
config: {
|
config: {
|
||||||
channels: { slack: { botToken: "x" } },
|
channels: { slack: { botToken: "x" } },
|
||||||
@@ -11,9 +11,9 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
env: {},
|
env: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.slack?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.slack?.enabled).toBe(true);
|
||||||
expect(result.config.plugins?.allow).toEqual(["telegram", "slack"]);
|
expect(result.config.plugins?.allow).toEqual(["telegram", "slack"]);
|
||||||
expect(result.changes.join("\n")).toContain("Slack configured, not enabled yet.");
|
expect(result.changes.join("\n")).toContain("Slack configured, enabled automatically.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects explicit disable", () => {
|
it("respects explicit disable", () => {
|
||||||
@@ -29,7 +29,7 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
expect(result.changes).toEqual([]);
|
expect(result.changes).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("configures irc as disabled when configured via env", () => {
|
it("auto-enables irc when configured via env", () => {
|
||||||
const result = applyPluginAutoEnable({
|
const result = applyPluginAutoEnable({
|
||||||
config: {},
|
config: {},
|
||||||
env: {
|
env: {
|
||||||
@@ -38,11 +38,11 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.irc?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.irc?.enabled).toBe(true);
|
||||||
expect(result.changes.join("\n")).toContain("IRC configured, not enabled yet.");
|
expect(result.changes.join("\n")).toContain("IRC configured, enabled automatically.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("configures provider auth plugins as disabled when profiles exist", () => {
|
it("auto-enables provider auth plugins when profiles exist", () => {
|
||||||
const result = applyPluginAutoEnable({
|
const result = applyPluginAutoEnable({
|
||||||
config: {
|
config: {
|
||||||
auth: {
|
auth: {
|
||||||
@@ -57,7 +57,7 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
env: {},
|
env: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.["google-antigravity-auth"]?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.["google-antigravity-auth"]?.enabled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips when plugins are globally disabled", () => {
|
it("skips when plugins are globally disabled", () => {
|
||||||
@@ -85,10 +85,12 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
env: {},
|
env: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(true);
|
||||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBeUndefined();
|
expect(result.config.plugins?.entries?.imessage?.enabled).toBeUndefined();
|
||||||
expect(result.changes.join("\n")).toContain("bluebubbles configured, not enabled yet.");
|
expect(result.changes.join("\n")).toContain("bluebubbles configured, enabled automatically.");
|
||||||
expect(result.changes.join("\n")).not.toContain("iMessage configured, not enabled yet.");
|
expect(result.changes.join("\n")).not.toContain(
|
||||||
|
"iMessage configured, enabled automatically.",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps imessage enabled if already explicitly enabled (non-destructive)", () => {
|
it("keeps imessage enabled if already explicitly enabled (non-destructive)", () => {
|
||||||
@@ -103,7 +105,7 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
env: {},
|
env: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(true);
|
||||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -120,8 +122,8 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBe(false);
|
||||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||||
expect(result.changes.join("\n")).toContain("iMessage configured, not enabled yet.");
|
expect(result.changes.join("\n")).toContain("iMessage configured, enabled automatically.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows imessage auto-configure when bluebubbles is in deny list", () => {
|
it("allows imessage auto-configure when bluebubbles is in deny list", () => {
|
||||||
@@ -137,10 +139,10 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBeUndefined();
|
expect(result.config.plugins?.entries?.bluebubbles?.enabled).toBeUndefined();
|
||||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("configures imessage as disabled when only imessage is configured", () => {
|
it("auto-enables imessage when only imessage is configured", () => {
|
||||||
const result = applyPluginAutoEnable({
|
const result = applyPluginAutoEnable({
|
||||||
config: {
|
config: {
|
||||||
channels: { imessage: { cliPath: "/usr/local/bin/imsg" } },
|
channels: { imessage: { cliPath: "/usr/local/bin/imsg" } },
|
||||||
@@ -148,8 +150,8 @@ describe("applyPluginAutoEnable", () => {
|
|||||||
env: {},
|
env: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(false);
|
expect(result.config.plugins?.entries?.imessage?.enabled).toBe(true);
|
||||||
expect(result.changes.join("\n")).toContain("iMessage configured, not enabled yet.");
|
expect(result.changes.join("\n")).toContain("iMessage configured, enabled automatically.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ function registerPluginEntry(cfg: OpenClawConfig, pluginId: string): OpenClawCon
|
|||||||
...cfg.plugins?.entries,
|
...cfg.plugins?.entries,
|
||||||
[pluginId]: {
|
[pluginId]: {
|
||||||
...(cfg.plugins?.entries?.[pluginId] as Record<string, unknown> | undefined),
|
...(cfg.plugins?.entries?.[pluginId] as Record<string, unknown> | undefined),
|
||||||
enabled: false,
|
enabled: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
@@ -426,7 +426,7 @@ function formatAutoEnableChange(entry: PluginEnableChange): string {
|
|||||||
const label = getChatChannelMeta(channelId).label;
|
const label = getChatChannelMeta(channelId).label;
|
||||||
reason = reason.replace(new RegExp(`^${channelId}\\b`, "i"), label);
|
reason = reason.replace(new RegExp(`^${channelId}\\b`, "i"), label);
|
||||||
}
|
}
|
||||||
return `${reason}, not enabled yet.`;
|
return `${reason}, enabled automatically.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyPluginAutoEnable(params: {
|
export function applyPluginAutoEnable(params: {
|
||||||
|
|||||||
Reference in New Issue
Block a user