mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(test): route plugin dependency helpers
This commit is contained in:
@@ -27,7 +27,10 @@ export function packageNameFromSpecifier(specifier) {
|
||||
if (!first) {
|
||||
return null;
|
||||
}
|
||||
return first.startsWith("@") && second ? `${first}/${second}` : first;
|
||||
if (first.startsWith("@")) {
|
||||
return second ? `${first}/${second}` : null;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
/** Collect runtime dependency specs across bundled plugin packages and note conflicts. */
|
||||
|
||||
@@ -1242,6 +1242,10 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
|
||||
"test/plugin-npm-package-manifest.test.ts",
|
||||
],
|
||||
],
|
||||
[
|
||||
"scripts/lib/plugin-package-dependencies.mjs",
|
||||
["test/scripts/plugin-package-dependencies.test.ts"],
|
||||
],
|
||||
[
|
||||
"scripts/lib/plugin-npm-runtime-assets.mjs",
|
||||
["test/scripts/plugin-npm-runtime-build-args.test.ts"],
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// Plugin package dependency tests cover bundled plugin runtime dependency helpers.
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
collectBundledPluginPackageDependencySpecs,
|
||||
collectRuntimeDependencySpecs,
|
||||
packageNameFromSpecifier,
|
||||
} from "../../scripts/lib/plugin-package-dependencies.mjs";
|
||||
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
|
||||
|
||||
const tempDirs = new Set<string>();
|
||||
|
||||
afterEach(() => {
|
||||
cleanupTempDirs(tempDirs);
|
||||
});
|
||||
|
||||
function writePackageJson(root: string, pluginId: string, packageJson: unknown): void {
|
||||
const pluginDir = join(root, pluginId);
|
||||
mkdirSync(pluginDir, { recursive: true });
|
||||
writeFileSync(join(pluginDir, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`);
|
||||
}
|
||||
|
||||
describe("scripts/lib/plugin-package-dependencies.mjs", () => {
|
||||
it("extracts dependency package names from bare import specifiers", () => {
|
||||
expect(packageNameFromSpecifier("@scope/pkg/subpath")).toBe("@scope/pkg");
|
||||
expect(packageNameFromSpecifier("plain-pkg/subpath")).toBe("plain-pkg");
|
||||
expect(packageNameFromSpecifier("@scope")).toBeNull();
|
||||
expect(packageNameFromSpecifier("@scope/")).toBeNull();
|
||||
expect(packageNameFromSpecifier("node:fs")).toBeNull();
|
||||
expect(packageNameFromSpecifier("./local")).toBeNull();
|
||||
expect(packageNameFromSpecifier("/absolute")).toBeNull();
|
||||
expect(packageNameFromSpecifier("#internal")).toBeNull();
|
||||
});
|
||||
|
||||
it("collects only runtime dependency specs from package manifests", () => {
|
||||
expect(
|
||||
[...collectRuntimeDependencySpecs({
|
||||
dependencies: {
|
||||
empty: "",
|
||||
objectValue: { version: "1.0.0" },
|
||||
runtime: "^1.0.0",
|
||||
},
|
||||
devDependencies: {
|
||||
devOnly: "^3.0.0",
|
||||
},
|
||||
optionalDependencies: {
|
||||
optional: "~2.0.0",
|
||||
},
|
||||
})],
|
||||
).toEqual([
|
||||
["runtime", "^1.0.0"],
|
||||
["optional", "~2.0.0"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("collects bundled plugin dependency owners and conflicts deterministically", () => {
|
||||
const root = makeTempDir(tempDirs, "openclaw-plugin-dependencies-");
|
||||
writePackageJson(root, "alpha", {
|
||||
dependencies: {
|
||||
shared: "^1.0.0",
|
||||
},
|
||||
optionalDependencies: {
|
||||
optional: "^2.0.0",
|
||||
},
|
||||
});
|
||||
writePackageJson(root, "beta", {
|
||||
dependencies: {
|
||||
shared: "^1.0.0",
|
||||
},
|
||||
});
|
||||
writePackageJson(root, "gamma", {
|
||||
dependencies: {
|
||||
shared: "^1.1.0",
|
||||
},
|
||||
});
|
||||
|
||||
expect([...collectBundledPluginPackageDependencySpecs(root)]).toEqual([
|
||||
[
|
||||
"shared",
|
||||
{
|
||||
conflicts: [{ pluginId: "gamma", spec: "^1.1.0" }],
|
||||
pluginIds: ["alpha", "beta"],
|
||||
spec: "^1.0.0",
|
||||
},
|
||||
],
|
||||
["optional", { conflicts: [], pluginIds: ["alpha"], spec: "^2.0.0" }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1985,6 +1985,10 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
"scripts/validate-release-publish-approval.mjs",
|
||||
["test/scripts/validate-release-publish-approval.test.ts"],
|
||||
],
|
||||
[
|
||||
"scripts/lib/plugin-package-dependencies.mjs",
|
||||
["test/scripts/plugin-package-dependencies.test.ts"],
|
||||
],
|
||||
[
|
||||
"scripts/lib/plugin-npm-runtime-assets.mjs",
|
||||
["test/scripts/plugin-npm-runtime-build-args.test.ts"],
|
||||
|
||||
Reference in New Issue
Block a user