Plugins: narrow loader testing helper surface

This commit is contained in:
Gustavo Madeira Santana 2026-03-28 00:23:17 -04:00
parent 742e0c8597
commit cdf19111e5
No known key found for this signature in database
3 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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,