mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:40:43 +00:00
fix(plugins): refresh registry after chat toggles
This commit is contained in:
@@ -11,6 +11,7 @@ const buildPluginDiagnosticsReportMock = vi.hoisted(() => vi.fn());
|
||||
const buildPluginInspectReportMock = vi.hoisted(() => vi.fn());
|
||||
const buildAllPluginInspectReportsMock = vi.hoisted(() => vi.fn());
|
||||
const formatPluginCompatibilityNoticeMock = vi.hoisted(() => vi.fn(() => "ok"));
|
||||
const refreshPluginRegistryAfterConfigMutationMock = vi.hoisted(() => vi.fn(async () => undefined));
|
||||
|
||||
vi.mock("../../cli/npm-resolution.js", () => ({
|
||||
buildNpmInstallRecordFields: vi.fn(),
|
||||
@@ -27,6 +28,10 @@ vi.mock("../../cli/plugins-install-persist.js", () => ({
|
||||
persistPluginInstall: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("../../cli/plugins-registry-refresh.js", () => ({
|
||||
refreshPluginRegistryAfterConfigMutation: refreshPluginRegistryAfterConfigMutationMock,
|
||||
}));
|
||||
|
||||
vi.mock("../../config/config.js", () => ({
|
||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||
validateConfigObjectWithPlugins: validateConfigObjectWithPluginsMock,
|
||||
@@ -208,6 +213,18 @@ describe("handlePluginsCommand", () => {
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(refreshPluginRegistryAfterConfigMutationMock).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
reason: "policy-changed",
|
||||
config: expect.objectContaining({
|
||||
plugins: expect.objectContaining({
|
||||
entries: expect.objectContaining({
|
||||
superpowers: expect.objectContaining({ enabled: true }),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
const disableParams = buildPluginsParams("/plugins disable superpowers", buildCfg());
|
||||
disableParams.command.senderIsOwner = true;
|
||||
@@ -223,6 +240,18 @@ describe("handlePluginsCommand", () => {
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(refreshPluginRegistryAfterConfigMutationMock).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
reason: "policy-changed",
|
||||
config: expect.objectContaining({
|
||||
plugins: expect.objectContaining({
|
||||
entries: expect.objectContaining({
|
||||
superpowers: expect.objectContaining({ enabled: false }),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves write targets by runtime-derived plugin name", async () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
resolveFileNpmSpecToLocalPath,
|
||||
} from "../../cli/plugins-command-helpers.js";
|
||||
import { persistPluginInstall } from "../../cli/plugins-install-persist.js";
|
||||
import { refreshPluginRegistryAfterConfigMutation } from "../../cli/plugins-registry-refresh.js";
|
||||
import {
|
||||
readConfigFileSnapshot,
|
||||
validateConfigObjectWithPlugins,
|
||||
@@ -473,11 +474,23 @@ export const handlePluginsCommand: CommandHandler = async (params, allowTextComm
|
||||
};
|
||||
}
|
||||
await writeConfigFile(validated.config);
|
||||
let registryWarning: string | undefined;
|
||||
await refreshPluginRegistryAfterConfigMutation({
|
||||
config: validated.config,
|
||||
reason: "policy-changed",
|
||||
logger: {
|
||||
warn: (message) => {
|
||||
registryWarning = message;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
shouldContinue: false,
|
||||
reply: {
|
||||
text: `🔌 Plugin "${plugin.id}" ${pluginsCommand.action}d in ${loaded.path}. Restart the gateway to apply.`,
|
||||
text:
|
||||
`🔌 Plugin "${plugin.id}" ${pluginsCommand.action}d in ${loaded.path}. Restart the gateway to apply.` +
|
||||
(registryWarning ? `\n${registryWarning}` : ""),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user