|
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import type { OpenClawConfig } from "../config/types.js"; |
4 | 4 | import 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"; |
6 | 9 |
|
7 | 10 | function npmRecord( |
8 | 11 | version: string, |
@@ -318,3 +321,69 @@ describe("detectPluginVersionDrift", () => { |
318 | 321 | expect(result.drifts.map((d) => d.pluginId)).toEqual(["discord", "matrix", "whatsapp"]); |
319 | 322 | }); |
320 | 323 | }); |
| 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/[email protected]", |
| 335 | + }), |
| 336 | + ).toBe("openclaw plugins update @openclaw/[email protected]"); |
| 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/[email protected]", |
| 347 | + }), |
| 348 | + ).toBe("openclaw plugins update @openclaw/[email protected]"); |
| 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/[email protected]", |
| 360 | + }), |
| 361 | + ).toBe("openclaw plugins update @openclaw/[email protected]"); |
| 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/[email protected]", |
| 386 | + }), |
| 387 | + ).toBe("openclaw plugins update brave"); |
| 388 | + }); |
| 389 | +}); |
0 commit comments