refactor: replace plugin-sdk dist env hacks with loader option

This commit is contained in:
Peter Steinberger
2026-03-27 13:38:40 +00:00
parent ad89fa669c
commit 546a1aad98
12 changed files with 129 additions and 81 deletions

View File

@@ -1,14 +1,11 @@
import { Command } from "commander";
import { afterAll, afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { registerPluginCliCommands } from "./cli.js";
import { clearPluginLoaderCache } from "./loader.js";
import { clearPluginManifestRegistryCache } from "./manifest-registry.js";
import { resetPluginRuntimeStateForTest } from "./runtime.js";
const previousPreferDistPluginSdk = process.env.OPENCLAW_PLUGIN_SDK_PREFER_DIST;
process.env.OPENCLAW_PLUGIN_SDK_PREFER_DIST = "1";
function resetPluginState() {
clearPluginLoaderCache();
clearPluginManifestRegistryCache();
@@ -24,37 +21,39 @@ describe("registerPluginCliCommands browser plugin integration", () => {
resetPluginState();
});
afterAll(() => {
if (previousPreferDistPluginSdk === undefined) {
delete process.env.OPENCLAW_PLUGIN_SDK_PREFER_DIST;
} else {
process.env.OPENCLAW_PLUGIN_SDK_PREFER_DIST = previousPreferDistPluginSdk;
}
});
it("registers the browser command from the bundled browser plugin", () => {
const program = new Command();
registerPluginCliCommands(program, {
plugins: {
allow: ["browser"],
},
} as OpenClawConfig);
registerPluginCliCommands(
program,
{
plugins: {
allow: ["browser"],
},
} as OpenClawConfig,
undefined,
{ pluginSdkResolution: "dist" },
);
expect(program.commands.map((command) => command.name())).toContain("browser");
});
it("omits the browser command when the bundled browser plugin is disabled", () => {
const program = new Command();
registerPluginCliCommands(program, {
plugins: {
allow: ["browser"],
entries: {
browser: {
enabled: false,
registerPluginCliCommands(
program,
{
plugins: {
allow: ["browser"],
entries: {
browser: {
enabled: false,
},
},
},
},
} as OpenClawConfig);
} as OpenClawConfig,
undefined,
{ pluginSdkResolution: "dist" },
);
expect(program.commands.map((command) => command.name())).not.toContain("browser");
});