mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-04 22:01:15 +00:00
fix(plugins): enforce minimum host versions for installable plugins (#52094)
* fix(plugins): enforce min host versions * fix(plugins): tighten min host version validation * chore(plugins): trim dead min host version code * fix(plugins): handle malformed min host metadata * fix(plugins): key manifest cache by host version
This commit is contained in:
96
src/plugins/min-host-version.test.ts
Normal file
96
src/plugins/min-host-version.test.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
checkMinHostVersion,
|
||||
MIN_HOST_VERSION_FORMAT,
|
||||
parseMinHostVersionRequirement,
|
||||
validateMinHostVersion,
|
||||
} from "./min-host-version.js";
|
||||
|
||||
describe("min-host-version", () => {
|
||||
it("accepts empty metadata", () => {
|
||||
expect(validateMinHostVersion(undefined)).toBeNull();
|
||||
expect(parseMinHostVersionRequirement(undefined)).toBeNull();
|
||||
expect(checkMinHostVersion({ currentVersion: "2026.3.14", minHostVersion: undefined })).toEqual(
|
||||
{
|
||||
ok: true,
|
||||
requirement: null,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("parses semver floors", () => {
|
||||
expect(parseMinHostVersionRequirement(">=2026.3.14")).toEqual({
|
||||
raw: ">=2026.3.14",
|
||||
minimumLabel: "2026.3.14",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects invalid floor syntax", () => {
|
||||
expect(validateMinHostVersion("2026.3.14")).toBe(MIN_HOST_VERSION_FORMAT);
|
||||
expect(validateMinHostVersion(123)).toBe(MIN_HOST_VERSION_FORMAT);
|
||||
expect(validateMinHostVersion(">=2026.3.14 garbage")).toBe(MIN_HOST_VERSION_FORMAT);
|
||||
expect(
|
||||
checkMinHostVersion({ currentVersion: "2026.3.14", minHostVersion: "2026.3.14" }),
|
||||
).toEqual({
|
||||
ok: false,
|
||||
kind: "invalid",
|
||||
error: MIN_HOST_VERSION_FORMAT,
|
||||
});
|
||||
});
|
||||
|
||||
it("treats non-string host floor metadata as invalid instead of throwing", () => {
|
||||
expect(checkMinHostVersion({ currentVersion: "2026.3.14", minHostVersion: 123 })).toEqual({
|
||||
ok: false,
|
||||
kind: "invalid",
|
||||
error: MIN_HOST_VERSION_FORMAT,
|
||||
});
|
||||
});
|
||||
|
||||
it("reports unknown host versions distinctly", () => {
|
||||
expect(
|
||||
checkMinHostVersion({ currentVersion: "unknown", minHostVersion: ">=2026.3.14" }),
|
||||
).toEqual({
|
||||
ok: false,
|
||||
kind: "unknown_host_version",
|
||||
requirement: {
|
||||
raw: ">=2026.3.14",
|
||||
minimumLabel: "2026.3.14",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("reports incompatible hosts", () => {
|
||||
expect(
|
||||
checkMinHostVersion({ currentVersion: "2026.3.13", minHostVersion: ">=2026.3.14" }),
|
||||
).toEqual({
|
||||
ok: false,
|
||||
kind: "incompatible",
|
||||
currentVersion: "2026.3.13",
|
||||
requirement: {
|
||||
raw: ">=2026.3.14",
|
||||
minimumLabel: "2026.3.14",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts equal or newer hosts", () => {
|
||||
expect(
|
||||
checkMinHostVersion({ currentVersion: "2026.3.14", minHostVersion: ">=2026.3.14" }),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
requirement: {
|
||||
raw: ">=2026.3.14",
|
||||
minimumLabel: "2026.3.14",
|
||||
},
|
||||
});
|
||||
expect(
|
||||
checkMinHostVersion({ currentVersion: "2026.4.0", minHostVersion: ">=2026.3.14" }),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
requirement: {
|
||||
raw: ">=2026.3.14",
|
||||
minimumLabel: "2026.3.14",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user