mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:50:42 +00:00
perf(doctor): skip blocker scans without plugin disablement
This commit is contained in:
69
src/commands/doctor/shared/channel-plugin-blockers.test.ts
Normal file
69
src/commands/doctor/shared/channel-plugin-blockers.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as configPresence from "../../../channels/config-presence.js";
|
||||
import * as manifestRegistry from "../../../plugins/manifest-registry.js";
|
||||
import { scanConfiguredChannelPluginBlockers } from "./channel-plugin-blockers.js";
|
||||
|
||||
describe("channel plugin blockers", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("skips plugin registry work when config has no plugin blocker surfaces", () => {
|
||||
const presenceSpy = vi.spyOn(configPresence, "listPotentialConfiguredChannelIds");
|
||||
const registrySpy = vi.spyOn(manifestRegistry, "loadPluginManifestRegistry");
|
||||
|
||||
const hits = scanConfiguredChannelPluginBlockers({
|
||||
channels: {
|
||||
slack: {
|
||||
accounts: {
|
||||
work: {
|
||||
allowFrom: ["alice"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(hits).toEqual([]);
|
||||
expect(presenceSpy).not.toHaveBeenCalled();
|
||||
expect(registrySpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("still evaluates configured channels when plugins are disabled globally", () => {
|
||||
vi.spyOn(configPresence, "listPotentialConfiguredChannelIds").mockReturnValue(["slack"]);
|
||||
vi.spyOn(manifestRegistry, "loadPluginManifestRegistry").mockReturnValue({
|
||||
plugins: [
|
||||
{
|
||||
id: "slack",
|
||||
origin: "bundled",
|
||||
channels: ["slack"],
|
||||
enabledByDefault: true,
|
||||
},
|
||||
],
|
||||
diagnostics: [],
|
||||
} as ReturnType<typeof manifestRegistry.loadPluginManifestRegistry>);
|
||||
|
||||
const hits = scanConfiguredChannelPluginBlockers({
|
||||
plugins: {
|
||||
enabled: false,
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
accounts: {
|
||||
work: {
|
||||
allowFrom: ["alice"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(hits).toEqual([
|
||||
{
|
||||
channelId: "slack",
|
||||
pluginId: "slack",
|
||||
reason: "plugins disabled",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -13,10 +13,32 @@ export type ChannelPluginBlockerHit = {
|
||||
reason: "disabled in config" | "plugins disabled";
|
||||
};
|
||||
|
||||
function hasExplicitChannelPluginBlockerConfig(cfg: OpenClawConfig): boolean {
|
||||
if (cfg.plugins?.enabled === false) {
|
||||
return true;
|
||||
}
|
||||
const entries = cfg.plugins?.entries;
|
||||
if (!entries || typeof entries !== "object") {
|
||||
return false;
|
||||
}
|
||||
return Object.values(entries).some((entry) => {
|
||||
return (
|
||||
entry &&
|
||||
typeof entry === "object" &&
|
||||
!Array.isArray(entry) &&
|
||||
"enabled" in entry &&
|
||||
(entry as { enabled?: unknown }).enabled === false
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function scanConfiguredChannelPluginBlockers(
|
||||
cfg: OpenClawConfig,
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): ChannelPluginBlockerHit[] {
|
||||
if (!hasExplicitChannelPluginBlockerConfig(cfg)) {
|
||||
return [];
|
||||
}
|
||||
const configuredChannelIds = new Set(
|
||||
listPotentialConfiguredChannelIds(cfg, env).map((id) => id.trim()),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user