mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
fix: harden plugin auto-enable empty config handling
This commit is contained in:
@@ -436,7 +436,8 @@ describe("exec approvals CLI", () => {
|
||||
effective: "always",
|
||||
}),
|
||||
askFallback: expect.objectContaining({
|
||||
source: "OpenClaw default (deny)",
|
||||
effective: "full",
|
||||
source: "OpenClaw default (full)",
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
|
||||
@@ -121,6 +121,17 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("applyPluginAutoEnable", () => {
|
||||
it("treats an undefined config as empty", () => {
|
||||
const result = applyPluginAutoEnable({
|
||||
config: undefined,
|
||||
env: {},
|
||||
});
|
||||
|
||||
expect(result.config).toEqual({});
|
||||
expect(result.changes).toEqual([]);
|
||||
expect(result.autoEnabledReasons).toEqual({});
|
||||
});
|
||||
|
||||
it("auto-enables built-in channels without appending to plugins.allow", () => {
|
||||
const result = applyWithSlackConfig({ plugins: { allow: ["telegram"] } });
|
||||
|
||||
|
||||
@@ -645,7 +645,7 @@ function formatAutoEnableChange(entry: PluginEnableChange): string {
|
||||
}
|
||||
|
||||
export function applyPluginAutoEnable(params: {
|
||||
config: OpenClawConfig;
|
||||
config?: OpenClawConfig;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
/** Pre-loaded manifest registry. When omitted, the registry is loaded from
|
||||
* the installed plugins on disk. Pass an explicit registry in tests to
|
||||
|
||||
@@ -135,7 +135,8 @@ function getJiti(modulePath: string) {
|
||||
|
||||
function readFacadeBoundaryConfigSafely(): OpenClawConfig {
|
||||
try {
|
||||
return loadConfig();
|
||||
const config = loadConfig();
|
||||
return config && typeof config === "object" ? config : EMPTY_FACADE_BOUNDARY_CONFIG;
|
||||
} catch {
|
||||
return EMPTY_FACADE_BOUNDARY_CONFIG;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ describe("resolvePluginProviders", () => {
|
||||
applyPluginAutoEnableMock.mockReset();
|
||||
applyPluginAutoEnableMock.mockImplementation(
|
||||
(params): PluginAutoEnableResult => ({
|
||||
config: params.config,
|
||||
config: params.config ?? ({} as OpenClawConfig),
|
||||
changes: [],
|
||||
autoEnabledReasons: {},
|
||||
}),
|
||||
|
||||
@@ -306,9 +306,9 @@ describe("resolvePluginWebSearchProviders", () => {
|
||||
applyPluginAutoEnableSpy = vi
|
||||
.spyOn(pluginAutoEnableModule, "applyPluginAutoEnable")
|
||||
.mockImplementation(
|
||||
(params: { config: unknown }) =>
|
||||
(params) =>
|
||||
({
|
||||
config: params.config,
|
||||
config: params.config ?? {},
|
||||
changes: [],
|
||||
autoEnabledReasons: {},
|
||||
}) as ReturnType<PluginAutoEnableModule["applyPluginAutoEnable"]>,
|
||||
|
||||
Reference in New Issue
Block a user