


























@@ -2,7 +2,10 @@
22import { describe, expect, it } from "vitest";
33import type { OpenClawConfig } from "../config/types.js";
44import type { PluginInstallRecord } from "../config/types.plugins.js";
5-import { detectPluginVersionDrift } from "./plugin-version-drift.js";
5+import {
6+detectPluginVersionDrift,
7+resolvePluginVersionDriftUpdateCommand,
8+} from "./plugin-version-drift.js";
69710function npmRecord(
811version: string,
@@ -318,3 +321,69 @@ describe("detectPluginVersionDrift", () => {
318321expect(result.drifts.map((d) => d.pluginId)).toEqual(["discord", "matrix", "whatsapp"]);
319322});
320323});
324+325+describe("resolvePluginVersionDriftUpdateCommand", () => {
326+it("uses an exact npm package target when the drifted install is pinned", () => {
327+expect(
328+resolvePluginVersionDriftUpdateCommand({
329+pluginId: "brave",
330+installedVersion: "2026.6.9",
331+gatewayVersion: "2026.6.10-beta.1",
332+source: "npm",
333+packageName: "@openclaw/brave-plugin",
334+spec: "@openclaw/brave-plugin@2026.6.9",
335+}),
336+).toBe("openclaw plugins update @openclaw/brave-plugin@2026.6.10-beta.1");
337+});
338+339+it("parses the package name from exact npm specs when drift metadata is sparse", () => {
340+expect(
341+resolvePluginVersionDriftUpdateCommand({
342+pluginId: "brave",
343+installedVersion: "2026.6.9",
344+gatewayVersion: "2026.6.10-beta.1",
345+source: "npm",
346+spec: "@openclaw/brave-plugin@2026.6.9",
347+}),
348+).toBe("openclaw plugins update @openclaw/brave-plugin@2026.6.10-beta.1");
349+});
350+351+it("prefers the parsed exact npm spec package over inconsistent drift metadata", () => {
352+expect(
353+resolvePluginVersionDriftUpdateCommand({
354+pluginId: "brave",
355+installedVersion: "2026.6.9",
356+gatewayVersion: "2026.6.10-beta.1",
357+source: "npm",
358+packageName: "@openclaw/other-plugin",
359+spec: "@openclaw/brave-plugin@2026.6.9",
360+}),
361+).toBe("openclaw plugins update @openclaw/brave-plugin@2026.6.10-beta.1");
362+});
363+364+it("keeps plugin-id updates for floating npm install records", () => {
365+expect(
366+resolvePluginVersionDriftUpdateCommand({
367+pluginId: "brave",
368+installedVersion: "2026.6.9",
369+gatewayVersion: "2026.6.10-beta.1",
370+source: "npm",
371+packageName: "@openclaw/brave-plugin",
372+spec: "@openclaw/brave-plugin",
373+}),
374+).toBe("openclaw plugins update brave");
375+});
376+377+it("keeps plugin-id updates when the gateway version is not a registry version", () => {
378+expect(
379+resolvePluginVersionDriftUpdateCommand({
380+pluginId: "brave",
381+installedVersion: "2026.6.9",
382+gatewayVersion: "unknown",
383+source: "npm",
384+packageName: "@openclaw/brave-plugin",
385+spec: "@openclaw/brave-plugin@2026.6.9",
386+}),
387+).toBe("openclaw plugins update brave");
388+});
389+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。