mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
Plugins: narrow loader testing helper surface
This commit is contained in:
@@ -11,10 +11,8 @@ import { createHookRunner } from "./hooks.js";
|
||||
import {
|
||||
__testing,
|
||||
clearPluginLoaderCache,
|
||||
getCompatibleActivePluginRegistry,
|
||||
loadOpenClawPlugins,
|
||||
resolveRuntimePluginRegistry,
|
||||
resolvePluginLoadCacheContext,
|
||||
} from "./loader.js";
|
||||
import { clearPluginManifestRegistryCache } from "./manifest-registry.js";
|
||||
import {
|
||||
@@ -3563,24 +3561,24 @@ describe("getCompatibleActivePluginRegistry", () => {
|
||||
allowGatewaySubagentBinding: true,
|
||||
},
|
||||
};
|
||||
const { cacheKey } = resolvePluginLoadCacheContext(loadOptions);
|
||||
const { cacheKey } = __testing.resolvePluginLoadCacheContext(loadOptions);
|
||||
setActivePluginRegistry(registry, cacheKey);
|
||||
|
||||
expect(getCompatibleActivePluginRegistry(loadOptions)).toBe(registry);
|
||||
expect(__testing.getCompatibleActivePluginRegistry(loadOptions)).toBe(registry);
|
||||
expect(
|
||||
getCompatibleActivePluginRegistry({
|
||||
__testing.getCompatibleActivePluginRegistry({
|
||||
...loadOptions,
|
||||
workspaceDir: "/tmp/workspace-b",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
getCompatibleActivePluginRegistry({
|
||||
__testing.getCompatibleActivePluginRegistry({
|
||||
...loadOptions,
|
||||
onlyPluginIds: ["demo"],
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
getCompatibleActivePluginRegistry({
|
||||
__testing.getCompatibleActivePluginRegistry({
|
||||
...loadOptions,
|
||||
runtimeOptions: undefined,
|
||||
}),
|
||||
@@ -3591,7 +3589,7 @@ describe("getCompatibleActivePluginRegistry", () => {
|
||||
const registry = createEmptyPluginRegistry();
|
||||
setActivePluginRegistry(registry, "startup-registry");
|
||||
|
||||
expect(getCompatibleActivePluginRegistry()).toBe(registry);
|
||||
expect(__testing.getCompatibleActivePluginRegistry()).toBe(registry);
|
||||
});
|
||||
|
||||
it("does not reuse the active registry when core gateway method names differ", () => {
|
||||
@@ -3635,7 +3633,7 @@ describe("resolveRuntimePluginRegistry", () => {
|
||||
},
|
||||
workspaceDir: "/tmp/workspace-a",
|
||||
};
|
||||
const { cacheKey } = resolvePluginLoadCacheContext(loadOptions);
|
||||
const { cacheKey } = __testing.resolvePluginLoadCacheContext(loadOptions);
|
||||
setActivePluginRegistry(registry, cacheKey);
|
||||
|
||||
expect(resolveRuntimePluginRegistry(loadOptions)).toBe(registry);
|
||||
|
||||
@@ -156,6 +156,8 @@ export const __testing = {
|
||||
resolvePluginSdkAliasFile,
|
||||
resolvePluginRuntimeModulePath,
|
||||
shouldPreferNativeJiti,
|
||||
getCompatibleActivePluginRegistry,
|
||||
resolvePluginLoadCacheContext,
|
||||
get maxPluginRegistryCacheEntries() {
|
||||
return pluginRegistryCacheEntryCap;
|
||||
},
|
||||
@@ -271,7 +273,7 @@ function hasExplicitCompatibilityInputs(options: PluginLoadOptions): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function resolvePluginLoadCacheContext(options: PluginLoadOptions = {}) {
|
||||
function resolvePluginLoadCacheContext(options: PluginLoadOptions = {}) {
|
||||
const env = options.env ?? process.env;
|
||||
const cfg = applyTestPluginDefaults(options.config ?? {}, env);
|
||||
const normalized = normalizePluginsConfig(cfg.plugins);
|
||||
@@ -303,7 +305,7 @@ export function resolvePluginLoadCacheContext(options: PluginLoadOptions = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export function getCompatibleActivePluginRegistry(
|
||||
function getCompatibleActivePluginRegistry(
|
||||
options: PluginLoadOptions = {},
|
||||
): PluginRegistry | undefined {
|
||||
const activeRegistry = getActivePluginRegistry() ?? undefined;
|
||||
|
||||
@@ -428,7 +428,7 @@ describe("resolvePluginWebSearchProviders", () => {
|
||||
bundledAllowlistCompat: true,
|
||||
env,
|
||||
});
|
||||
const { cacheKey } = loaderModule.resolvePluginLoadCacheContext({
|
||||
const { cacheKey } = loaderModule.__testing.resolvePluginLoadCacheContext({
|
||||
config,
|
||||
workspaceDir: DEFAULT_WEB_SEARCH_WORKSPACE,
|
||||
env,
|
||||
|
||||
Reference in New Issue
Block a user