




















@@ -1,5 +1,5 @@
11import { Command } from "commander";
2-import { afterEach, beforeEach, describe, expect, it } from "vitest";
2+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33import type { OpenClawConfig } from "../config/config.js";
44import {
55loadConfig,
@@ -37,6 +37,23 @@ function createTrackedPluginConfig(params: {
3737} as OpenClawConfig;
3838}
393940+function expectRestartNoticeLogged() {
41+expect(
42+runtimeLogs.some((message) =>
43+message.includes("Restart the gateway to load plugins and hooks."),
44+),
45+).toBe(true);
46+}
47+48+function expectSingleCallParams(mockFn: ReturnType<typeof vi.fn>) {
49+expect(mockFn).toHaveBeenCalledTimes(1);
50+const params = mockFn.mock.calls[0]?.[0] as Record<string, unknown> | undefined;
51+if (params === undefined) {
52+throw new Error("expected call params");
53+}
54+return params;
55+}
56+4057describe("plugins cli update", () => {
4158beforeEach(() => {
4259resetPluginsCliTestState();
@@ -132,19 +149,12 @@ describe("plugins cli update", () => {
132149133150await runPluginsCommand(["plugins", "update", "demo-hooks"]);
134151135-expect(updateNpmInstalledHookPacks).toHaveBeenCalledWith(
136-expect.objectContaining({
137-config: cfg,
138-hookIds: ["demo-hooks"],
139-}),
140-);
152+const hookUpdateParams = expectSingleCallParams(updateNpmInstalledHookPacks);
153+expect(hookUpdateParams.config).toBe(cfg);
154+expect(hookUpdateParams.hookIds).toEqual(["demo-hooks"]);
141155expect(writeConfigFile).toHaveBeenCalledWith(nextConfig);
142156expect(refreshPluginRegistry).not.toHaveBeenCalled();
143-expect(runtimeLogs).toEqual(
144-expect.arrayContaining([
145-expect.stringContaining("Restart the gateway to load plugins and hooks."),
146-]),
147-);
157+expectRestartNoticeLogged();
148158});
149159150160it("exits when update is called without id and without --all", async () => {
@@ -194,13 +204,10 @@ describe("plugins cli update", () => {
194204"--dangerously-force-unsafe-install",
195205]);
196206197-expect(updateNpmInstalledPlugins).toHaveBeenCalledWith(
198-expect.objectContaining({
199- config,
200-pluginIds: ["openclaw-codex-app-server"],
201-dangerouslyForceUnsafeInstall: true,
202-}),
203-);
207+const updateParams = expectSingleCallParams(updateNpmInstalledPlugins);
208+expect(updateParams.config).toEqual(config);
209+expect(updateParams.pluginIds).toEqual(["openclaw-codex-app-server"]);
210+expect(updateParams.dangerouslyForceUnsafeInstall).toBe(true);
204211});
205212206213it("writes updated config when updater reports changes", async () => {
@@ -239,13 +246,10 @@ describe("plugins cli update", () => {
239246240247await runPluginsCommand(["plugins", "update", "alpha"]);
241248242-expect(updateNpmInstalledPlugins).toHaveBeenCalledWith(
243-expect.objectContaining({
244-config: cfg,
245-pluginIds: ["alpha"],
246-dryRun: false,
247-}),
248-);
249+const updateParams = expectSingleCallParams(updateNpmInstalledPlugins);
250+expect(updateParams.config).toEqual(cfg);
251+expect(updateParams.pluginIds).toEqual(["alpha"]);
252+expect(updateParams.dryRun).toBe(false);
249253expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenCalledWith(
250254nextConfig.plugins?.installs,
251255);
@@ -255,11 +259,7 @@ describe("plugins cli update", () => {
255259installRecords: nextConfig.plugins?.installs,
256260reason: "source-changed",
257261});
258-expect(runtimeLogs).toEqual(
259-expect.arrayContaining([
260-expect.stringContaining("Restart the gateway to load plugins and hooks."),
261-]),
262-);
262+expectRestartNoticeLogged();
263263});
264264265265it("exits non-zero when a plugin update reports an error after persisting successes", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。