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:
Vincent Koc
2026-03-22 09:12:08 -07:00
committed by GitHub
parent 6b7206ed35
commit 3ce5a8366a
29 changed files with 653 additions and 21 deletions

View 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",
},
});
});
});