Files
clawhub/scripts/github/plugin-inspector-pin-change.test.mjs
2026-06-26 14:55:55 -07:00

89 lines
2.8 KiB
JavaScript

import { describe, expect, it } from "vitest";
import {
detectPinnedPluginInspectorChange,
EMPTY_TREE_SHA,
normalizeBaseSha,
readPinnedPluginInspectorVersion,
} from "./plugin-inspector-pin-change.mjs";
const packageJson = (version) =>
JSON.stringify({
dependencies: {
"@openclaw/plugin-inspector": version,
react: "19.2.7",
},
});
const packageJsonsByPath = (rootVersion, cliVersion = rootVersion) => ({
"package.json": packageJson(rootVersion),
"packages/clawhub/package.json": packageJson(cliVersion),
});
describe("plugin inspector pin change detection", () => {
it("uses the empty tree for an initial push base SHA", () => {
expect(normalizeBaseSha("0".repeat(40))).toBe(EMPTY_TREE_SHA);
expect(normalizeBaseSha("abc123")).toBe("abc123");
});
it("detects merged changes to the pinned plugin inspector dependency", () => {
expect(
detectPinnedPluginInspectorChange({
changedFiles: ["package.json", "bun.lock"],
basePackageJson: packageJson("0.3.12"),
headPackageJson: packageJson("0.3.13"),
}),
).toEqual({
changed: true,
oldVersion: "0.3.12",
newVersion: "0.3.13",
reason: "pinned @openclaw/plugin-inspector changed in package.json from 0.3.12 to 0.3.13",
});
});
it("detects merged changes to the CLI package inspector pin", () => {
expect(
detectPinnedPluginInspectorChange({
changedFiles: ["packages/clawhub/package.json", "bun.lock"],
basePackageJsonByPath: packageJsonsByPath("0.3.12"),
headPackageJsonByPath: packageJsonsByPath("0.3.12", "0.3.13"),
}),
).toEqual({
changed: true,
oldVersion: "0.3.12",
newVersion: "0.3.13",
reason:
"pinned @openclaw/plugin-inspector changed in packages/clawhub/package.json from 0.3.12 to 0.3.13",
});
});
it("does not dispatch for unrelated merged changes", () => {
expect(
detectPinnedPluginInspectorChange({
changedFiles: ["src/routes/index.tsx"],
basePackageJson: packageJson("0.3.12"),
headPackageJson: packageJson("0.3.12"),
}),
).toMatchObject({
changed: false,
reason: "no package manager files changed",
});
});
it("does not dispatch when package files changed but the inspector pin did not", () => {
expect(
detectPinnedPluginInspectorChange({
changedFiles: ["package.json", "bun.lock"],
basePackageJson: packageJson("0.3.12"),
headPackageJson: packageJson("0.3.12"),
}),
).toMatchObject({
changed: false,
reason: "pinned @openclaw/plugin-inspector did not change",
});
});
it("reads the pinned dependency version from package.json", () => {
expect(readPinnedPluginInspectorVersion(packageJson("0.3.12"))).toBe("0.3.12");
});
});