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 versionfeature/PAZ-358-fe-credit-error-display
parent
6b7206ed35
commit
3ce5a8366a
@ -0,0 +1,72 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isAtLeast, parseSemver } from "../infra/runtime-guard.js";
|
||||
import { parseMinHostVersionRequirement } from "./min-host-version.js";
|
||||
|
||||
const MIN_HOST_VERSION_BASELINE = "2026.3.14";
|
||||
const PLUGIN_MANIFEST_PATHS_REQUIRING_MIN_HOST_VERSION = [
|
||||
"extensions/bluebubbles/package.json",
|
||||
"extensions/discord/package.json",
|
||||
"extensions/feishu/package.json",
|
||||
"extensions/googlechat/package.json",
|
||||
"extensions/irc/package.json",
|
||||
"extensions/line/package.json",
|
||||
"extensions/matrix/package.json",
|
||||
"extensions/mattermost/package.json",
|
||||
"extensions/memory-lancedb/package.json",
|
||||
"extensions/msteams/package.json",
|
||||
"extensions/nextcloud-talk/package.json",
|
||||
"extensions/nostr/package.json",
|
||||
"extensions/synology-chat/package.json",
|
||||
"extensions/tlon/package.json",
|
||||
"extensions/twitch/package.json",
|
||||
"extensions/voice-call/package.json",
|
||||
"extensions/whatsapp/package.json",
|
||||
"extensions/zalo/package.json",
|
||||
"extensions/zalouser/package.json",
|
||||
] as const;
|
||||
|
||||
type PackageJsonLike = {
|
||||
openclaw?: {
|
||||
install?: {
|
||||
minHostVersion?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
describe("install minHostVersion guardrails", () => {
|
||||
it("requires published plugins that depend on new sdk subpaths to declare a host floor", () => {
|
||||
const baseline = parseSemver(MIN_HOST_VERSION_BASELINE);
|
||||
expect(baseline).not.toBeNull();
|
||||
if (!baseline) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const relativePath of PLUGIN_MANIFEST_PATHS_REQUIRING_MIN_HOST_VERSION) {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.resolve(relativePath), "utf-8"),
|
||||
) as PackageJsonLike;
|
||||
const requirement = parseMinHostVersionRequirement(
|
||||
manifest.openclaw?.install?.minHostVersion,
|
||||
);
|
||||
|
||||
expect(
|
||||
requirement,
|
||||
`${relativePath} should declare openclaw.install.minHostVersion`,
|
||||
).not.toBeNull();
|
||||
if (!requirement) {
|
||||
continue;
|
||||
}
|
||||
const minimum = parseSemver(requirement.minimumLabel);
|
||||
expect(minimum, `${relativePath} should use a parseable semver floor`).not.toBeNull();
|
||||
if (!minimum) {
|
||||
continue;
|
||||
}
|
||||
expect(
|
||||
isAtLeast(minimum, baseline),
|
||||
`${relativePath} should require at least OpenClaw ${MIN_HOST_VERSION_BASELINE}`,
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -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",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,82 @@
|
||||
import { isAtLeast, parseSemver } from "../infra/runtime-guard.js";
|
||||
|
||||
export const MIN_HOST_VERSION_FORMAT =
|
||||
'openclaw.install.minHostVersion must use a semver floor in the form ">=x.y.z"';
|
||||
const MIN_HOST_VERSION_RE = /^>=(\d+)\.(\d+)\.(\d+)$/;
|
||||
|
||||
export type MinHostVersionRequirement = {
|
||||
raw: string;
|
||||
minimumLabel: string;
|
||||
};
|
||||
|
||||
export type MinHostVersionCheckResult =
|
||||
| { ok: true; requirement: MinHostVersionRequirement | null }
|
||||
| { ok: false; kind: "invalid"; error: string }
|
||||
| { ok: false; kind: "unknown_host_version"; requirement: MinHostVersionRequirement }
|
||||
| {
|
||||
ok: false;
|
||||
kind: "incompatible";
|
||||
requirement: MinHostVersionRequirement;
|
||||
currentVersion: string;
|
||||
};
|
||||
|
||||
export function parseMinHostVersionRequirement(raw: unknown): MinHostVersionRequirement | null {
|
||||
if (typeof raw !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const match = trimmed.match(MIN_HOST_VERSION_RE);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const minimumLabel = `${match[1]}.${match[2]}.${match[3]}`;
|
||||
if (!parseSemver(minimumLabel)) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
raw: trimmed,
|
||||
minimumLabel,
|
||||
};
|
||||
}
|
||||
|
||||
export function validateMinHostVersion(raw: unknown): string | null {
|
||||
if (raw === undefined) {
|
||||
return null;
|
||||
}
|
||||
return parseMinHostVersionRequirement(raw) ? null : MIN_HOST_VERSION_FORMAT;
|
||||
}
|
||||
|
||||
export function checkMinHostVersion(params: {
|
||||
currentVersion: string | undefined;
|
||||
minHostVersion: unknown;
|
||||
}): MinHostVersionCheckResult {
|
||||
if (params.minHostVersion === undefined) {
|
||||
return { ok: true, requirement: null };
|
||||
}
|
||||
const requirement = parseMinHostVersionRequirement(params.minHostVersion);
|
||||
if (!requirement) {
|
||||
return { ok: false, kind: "invalid", error: MIN_HOST_VERSION_FORMAT };
|
||||
}
|
||||
const currentVersion = params.currentVersion?.trim() || "unknown";
|
||||
const currentSemver = parseSemver(currentVersion);
|
||||
if (!currentSemver) {
|
||||
return {
|
||||
ok: false,
|
||||
kind: "unknown_host_version",
|
||||
requirement,
|
||||
};
|
||||
}
|
||||
const minimumSemver = parseSemver(requirement.minimumLabel)!;
|
||||
if (!isAtLeast(currentSemver, minimumSemver)) {
|
||||
return {
|
||||
ok: false,
|
||||
kind: "incompatible",
|
||||
requirement,
|
||||
currentVersion,
|
||||
};
|
||||
}
|
||||
return { ok: true, requirement };
|
||||
}
|
||||
Loading…
Reference in New Issue