mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 12:41:12 +00:00
test: speed up core runtime suites
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { BUNDLED_WEB_SEARCH_PLUGIN_IDS } from "./bundled-web-search-ids.js";
|
||||
import { loadPluginManifestRegistry } from "./manifest-registry.js";
|
||||
|
||||
let hasBundledWebSearchCredential: typeof import("./bundled-web-search-registry.js").hasBundledWebSearchCredential;
|
||||
let listBundledWebSearchProviders: typeof import("./bundled-web-search.js").listBundledWebSearchProviders;
|
||||
let resolveBundledWebSearchPluginIds: typeof import("./bundled-web-search.js").resolveBundledWebSearchPluginIds;
|
||||
|
||||
function resolveManifestBundledWebSearchPluginIds() {
|
||||
return loadPluginManifestRegistry({})
|
||||
.plugins.filter(
|
||||
@@ -14,13 +18,18 @@ function resolveManifestBundledWebSearchPluginIds() {
|
||||
}
|
||||
|
||||
async function resolveRegistryBundledWebSearchPluginIds() {
|
||||
const { listBundledWebSearchProviders } = await import("./bundled-web-search.js");
|
||||
return listBundledWebSearchProviders()
|
||||
.map(({ pluginId }) => pluginId)
|
||||
.filter((value, index, values) => values.indexOf(value) === index)
|
||||
.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
({ listBundledWebSearchProviders, resolveBundledWebSearchPluginIds } =
|
||||
await import("./bundled-web-search.js"));
|
||||
({ hasBundledWebSearchCredential } = await import("./bundled-web-search-registry.js"));
|
||||
});
|
||||
|
||||
function expectBundledWebSearchIds(actual: readonly string[], expected: readonly string[]) {
|
||||
expect(actual).toEqual(expected);
|
||||
}
|
||||
@@ -33,12 +42,7 @@ function expectBundledWebSearchAlignment(params: {
|
||||
}
|
||||
|
||||
describe("bundled web search metadata", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
it("keeps bundled web search compat ids aligned with bundled manifests", async () => {
|
||||
const { resolveBundledWebSearchPluginIds } = await import("./bundled-web-search.js");
|
||||
expectBundledWebSearchAlignment({
|
||||
actual: resolveBundledWebSearchPluginIds({}),
|
||||
expected: resolveManifestBundledWebSearchPluginIds(),
|
||||
@@ -54,10 +58,6 @@ describe("bundled web search metadata", () => {
|
||||
});
|
||||
|
||||
describe("hasBundledWebSearchCredential", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
const baseCfg = {
|
||||
agents: { defaults: { model: { primary: "ollama/mistral-8b" } } },
|
||||
browser: { enabled: false },
|
||||
@@ -103,7 +103,6 @@ describe("hasBundledWebSearchCredential", () => {
|
||||
env: { OPENROUTER_API_KEY: "sk-or-v1-test" },
|
||||
},
|
||||
] as const)("$name", async ({ config, env }) => {
|
||||
const { hasBundledWebSearchCredential } = await import("./bundled-web-search-registry.js");
|
||||
expect(hasBundledWebSearchCredential({ config, env })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createEmptyPluginRegistry } from "./registry.js";
|
||||
|
||||
@@ -132,8 +132,11 @@ function expectCompatChainApplied(params: {
|
||||
}
|
||||
|
||||
describe("resolvePluginCapabilityProviders", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
beforeAll(async () => {
|
||||
({ resolvePluginCapabilityProviders } = await import("./capability-provider-runtime.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.resolveRuntimePluginRegistry.mockReset();
|
||||
mocks.resolveRuntimePluginRegistry.mockReturnValue(undefined);
|
||||
mocks.loadPluginManifestRegistry.mockReset();
|
||||
@@ -144,7 +147,6 @@ describe("resolvePluginCapabilityProviders", () => {
|
||||
mocks.withBundledPluginEnablementCompat.mockImplementation(({ config }) => config);
|
||||
mocks.withBundledPluginVitestCompat.mockReset();
|
||||
mocks.withBundledPluginVitestCompat.mockImplementation(({ config }) => config);
|
||||
({ resolvePluginCapabilityProviders } = await import("./capability-provider-runtime.js"));
|
||||
});
|
||||
|
||||
it("uses the active registry when capability providers are already loaded", () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { withEnvAsync } from "../test-utils/env.js";
|
||||
|
||||
const installPluginFromPathMock = vi.fn();
|
||||
@@ -20,6 +20,9 @@ const fetchWithSsrFGuardMock = vi.hoisted(() =>
|
||||
}),
|
||||
);
|
||||
const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn());
|
||||
let installPluginFromMarketplace: typeof import("./marketplace.js").installPluginFromMarketplace;
|
||||
let listMarketplacePlugins: typeof import("./marketplace.js").listMarketplacePlugins;
|
||||
let resolveMarketplaceInstallShortcut: typeof import("./marketplace.js").resolveMarketplaceInstallShortcut;
|
||||
|
||||
vi.mock("./install.js", () => ({
|
||||
installPluginFromPath: (...args: unknown[]) => installPluginFromPathMock(...args),
|
||||
@@ -38,6 +41,11 @@ vi.mock("../process/exec.js", () => ({
|
||||
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args),
|
||||
}));
|
||||
|
||||
beforeAll(async () => {
|
||||
({ installPluginFromMarketplace, listMarketplacePlugins, resolveMarketplaceInstallShortcut } =
|
||||
await import("./marketplace.js"));
|
||||
});
|
||||
|
||||
async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-marketplace-test-"));
|
||||
try {
|
||||
@@ -96,7 +104,6 @@ function mockRemoteMarketplaceClone(params: { manifest: unknown; pluginDir?: str
|
||||
async function expectRemoteMarketplaceError(params: { manifest: unknown; expectedError: string }) {
|
||||
mockRemoteMarketplaceClone({ manifest: params.manifest });
|
||||
|
||||
const { listMarketplacePlugins } = await import("./marketplace.js");
|
||||
const result = await listMarketplacePlugins({ marketplace: "owner/repo" });
|
||||
|
||||
expect(result).toEqual({
|
||||
@@ -188,7 +195,6 @@ describe("marketplace plugins", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const { listMarketplacePlugins } = await import("./marketplace.js");
|
||||
expectMarketplaceManifestListing(await listMarketplacePlugins({ marketplace: rootDir }));
|
||||
});
|
||||
});
|
||||
@@ -216,7 +222,6 @@ describe("marketplace plugins", () => {
|
||||
extensions: ["index.ts"],
|
||||
});
|
||||
|
||||
const { installPluginFromMarketplace } = await import("./marketplace.js");
|
||||
const result = await installPluginFromMarketplace({
|
||||
marketplace: manifestPath,
|
||||
plugin: "frontend-design",
|
||||
@@ -248,7 +253,6 @@ describe("marketplace plugins", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const { resolveMarketplaceInstallShortcut } = await import("./marketplace.js");
|
||||
const shortcut = await withEnvAsync(
|
||||
{ HOME: homeDir, OPENCLAW_HOME: openClawHome },
|
||||
async () => await resolveMarketplaceInstallShortcut("superpowers@claude-plugins-official"),
|
||||
@@ -283,7 +287,6 @@ describe("marketplace plugins", () => {
|
||||
extensions: ["index.ts"],
|
||||
});
|
||||
|
||||
const { installPluginFromMarketplace } = await import("./marketplace.js");
|
||||
const result = await installPluginFromMarketplace({
|
||||
marketplace: "owner/repo",
|
||||
plugin: "frontend-design",
|
||||
@@ -307,7 +310,6 @@ describe("marketplace plugins", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const { installPluginFromMarketplace } = await import("./marketplace.js");
|
||||
const result = await installPluginFromMarketplace({
|
||||
marketplace: manifestPath,
|
||||
plugin: "frontend-design",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const resolveRuntimePluginRegistryMock = vi.fn();
|
||||
const applyPluginAutoEnableMock = vi.fn();
|
||||
@@ -97,8 +97,15 @@ async function expectCloseMemoryRuntimeCase(params: {
|
||||
}
|
||||
|
||||
describe("memory runtime auto-enable loading", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
beforeAll(async () => {
|
||||
({
|
||||
getActiveMemorySearchManager,
|
||||
resolveActiveMemoryBackendConfig,
|
||||
closeActiveMemorySearchManagers,
|
||||
} = await import("./memory-runtime.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resolveRuntimePluginRegistryMock.mockReset();
|
||||
applyPluginAutoEnableMock.mockReset();
|
||||
getMemoryRuntimeMock.mockReset();
|
||||
@@ -106,11 +113,6 @@ describe("memory runtime auto-enable loading", () => {
|
||||
config: params.config,
|
||||
changes: [],
|
||||
}));
|
||||
({
|
||||
getActiveMemorySearchManager,
|
||||
resolveActiveMemoryBackendConfig,
|
||||
closeActiveMemorySearchManagers,
|
||||
} = await import("./memory-runtime.js"));
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const loadOpenClawPluginsMock = vi.fn();
|
||||
const loadPluginManifestRegistryMock = vi.fn();
|
||||
@@ -163,8 +163,12 @@ function expectBundledProviderLoad(params?: { config?: unknown; env?: NodeJS.Pro
|
||||
}
|
||||
|
||||
describe("resolvePluginProviders", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
beforeAll(async () => {
|
||||
({ resolveOwningPluginIdsForProvider } = await import("./providers.js"));
|
||||
({ resolvePluginProviders } = await import("./providers.runtime.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
loadOpenClawPluginsMock.mockReset();
|
||||
loadOpenClawPluginsMock.mockReturnValue({
|
||||
providers: [{ pluginId: "google", provider: { id: "demo-provider" } }],
|
||||
@@ -187,8 +191,6 @@ describe("resolvePluginProviders", () => {
|
||||
origin: "workspace",
|
||||
}),
|
||||
]);
|
||||
({ resolveOwningPluginIdsForProvider } = await import("./providers.js"));
|
||||
({ resolvePluginProviders } = await import("./providers.runtime.js"));
|
||||
});
|
||||
|
||||
it("forwards an explicit env to plugin loading", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createCompatibilityNotice,
|
||||
createCustomHook,
|
||||
@@ -214,8 +214,19 @@ function expectBundleInspectState(
|
||||
}
|
||||
|
||||
describe("buildPluginStatusReport", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
beforeAll(async () => {
|
||||
({
|
||||
buildAllPluginInspectReports,
|
||||
buildPluginCompatibilityNotices,
|
||||
buildPluginCompatibilityWarnings,
|
||||
buildPluginInspectReport,
|
||||
buildPluginStatusReport,
|
||||
formatPluginCompatibilityNotice,
|
||||
summarizePluginCompatibility,
|
||||
} = await import("./status.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
loadConfigMock.mockReset();
|
||||
loadOpenClawPluginsMock.mockReset();
|
||||
applyPluginAutoEnableMock.mockReset();
|
||||
@@ -235,15 +246,6 @@ describe("buildPluginStatusReport", () => {
|
||||
(params: { config: unknown }) => params.config,
|
||||
);
|
||||
setPluginLoadResult({ plugins: [] });
|
||||
({
|
||||
buildAllPluginInspectReports,
|
||||
buildPluginCompatibilityNotices,
|
||||
buildPluginCompatibilityWarnings,
|
||||
buildPluginInspectReport,
|
||||
buildPluginStatusReport,
|
||||
formatPluginCompatibilityNotice,
|
||||
summarizePluginCompatibility,
|
||||
} = await import("./status.js"));
|
||||
});
|
||||
|
||||
it("forwards an explicit env to plugin loading", () => {
|
||||
|
||||
Reference in New Issue
Block a user