mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-06 23:01:08 +00:00
fix(ci): stabilize browser bundled integration tests
This commit is contained in:
@@ -1,54 +1,56 @@
|
||||
import { Command } from "commander";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createBundledBrowserPluginFixture } from "../../test/helpers/browser-bundled-plugin-fixture.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
let registerPluginCliCommands: typeof import("./cli.js").registerPluginCliCommands;
|
||||
let clearPluginLoaderCache: typeof import("./loader.js").clearPluginLoaderCache;
|
||||
let clearPluginManifestRegistryCache: typeof import("./manifest-registry.js").clearPluginManifestRegistryCache;
|
||||
let resetPluginRuntimeStateForTest: typeof import("./runtime.js").resetPluginRuntimeStateForTest;
|
||||
import { clearPluginDiscoveryCache } from "./discovery.js";
|
||||
import { clearPluginLoaderCache, loadOpenClawPlugins } from "./loader.js";
|
||||
import { clearPluginManifestRegistryCache } from "./manifest-registry.js";
|
||||
import { resetPluginRuntimeStateForTest } from "./runtime.js";
|
||||
|
||||
function resetPluginState() {
|
||||
clearPluginLoaderCache();
|
||||
clearPluginDiscoveryCache();
|
||||
clearPluginManifestRegistryCache();
|
||||
resetPluginRuntimeStateForTest();
|
||||
}
|
||||
|
||||
describe("registerPluginCliCommands browser plugin integration", () => {
|
||||
beforeEach(async () => {
|
||||
({ clearPluginLoaderCache } =
|
||||
await vi.importActual<typeof import("./loader.js")>("./loader.js"));
|
||||
({ clearPluginManifestRegistryCache } =
|
||||
await vi.importActual<typeof import("./manifest-registry.js")>("./manifest-registry.js"));
|
||||
({ resetPluginRuntimeStateForTest } =
|
||||
await vi.importActual<typeof import("./runtime.js")>("./runtime.js"));
|
||||
({ registerPluginCliCommands } = await vi.importActual<typeof import("./cli.js")>("./cli.js"));
|
||||
let bundledFixture: ReturnType<typeof createBundledBrowserPluginFixture> | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
bundledFixture = createBundledBrowserPluginFixture();
|
||||
vi.stubEnv("OPENCLAW_BUNDLED_PLUGINS_DIR", bundledFixture.rootDir);
|
||||
resetPluginState();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetPluginState();
|
||||
vi.unstubAllEnvs();
|
||||
bundledFixture?.cleanup();
|
||||
bundledFixture = null;
|
||||
});
|
||||
|
||||
it("registers the browser command from the bundled browser plugin", () => {
|
||||
const program = new Command();
|
||||
registerPluginCliCommands(
|
||||
program,
|
||||
{
|
||||
const registry = loadOpenClawPlugins({
|
||||
config: {
|
||||
plugins: {
|
||||
allow: ["browser"],
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
undefined,
|
||||
{ pluginSdkResolution: "dist" },
|
||||
);
|
||||
cache: false,
|
||||
env: {
|
||||
...process.env,
|
||||
OPENCLAW_BUNDLED_PLUGINS_DIR:
|
||||
bundledFixture?.rootDir ?? path.join(process.cwd(), "extensions"),
|
||||
} as NodeJS.ProcessEnv,
|
||||
});
|
||||
|
||||
expect(program.commands.map((command) => command.name())).toContain("browser");
|
||||
expect(registry.cliRegistrars.flatMap((entry) => entry.commands)).toContain("browser");
|
||||
});
|
||||
|
||||
it("omits the browser command when the bundled browser plugin is disabled", () => {
|
||||
const program = new Command();
|
||||
registerPluginCliCommands(
|
||||
program,
|
||||
{
|
||||
const registry = loadOpenClawPlugins({
|
||||
config: {
|
||||
plugins: {
|
||||
allow: ["browser"],
|
||||
entries: {
|
||||
@@ -58,10 +60,9 @@ describe("registerPluginCliCommands browser plugin integration", () => {
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig,
|
||||
undefined,
|
||||
{ pluginSdkResolution: "dist" },
|
||||
);
|
||||
cache: false,
|
||||
});
|
||||
|
||||
expect(program.commands.map((command) => command.name())).not.toContain("browser");
|
||||
expect(registry.cliRegistrars.flatMap((entry) => entry.commands)).not.toContain("browser");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user