mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-15 17:30:45 +00:00
fix(plugins): reuse config alias scans
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import * as bundledPluginMetadata from "./bundled-plugin-metadata.js";
|
||||
import {
|
||||
createPluginActivationSource,
|
||||
normalizePluginsConfig,
|
||||
@@ -154,6 +155,25 @@ describe("normalizePluginsConfig", () => {
|
||||
expect(result.entries.google?.enabled).toBe(true);
|
||||
expect(result.entries.minimax?.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("reuses the bundled alias scan during one config normalization", () => {
|
||||
const listBundledMetadata = vi.spyOn(bundledPluginMetadata, "listBundledPluginMetadata");
|
||||
|
||||
const result = normalizePluginsConfig({
|
||||
allow: ["unknown-plugin-one", "unknown-plugin-two"],
|
||||
deny: ["unknown-plugin-three"],
|
||||
entries: {
|
||||
"unknown-plugin-four": {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.allow).toEqual(["unknown-plugin-one", "unknown-plugin-two"]);
|
||||
expect(result.deny).toEqual(["unknown-plugin-three"]);
|
||||
expect(result.entries["unknown-plugin-four"]?.enabled).toBe(true);
|
||||
expect(listBundledMetadata).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveEffectiveEnableState", () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
hasExplicitPluginConfig as hasExplicitPluginConfigShared,
|
||||
isBundledChannelEnabledByChannelConfig as isBundledChannelEnabledByChannelConfigShared,
|
||||
normalizePluginsConfigWithResolver,
|
||||
type NormalizePluginId,
|
||||
type NormalizedPluginsConfig as SharedNormalizedPluginsConfig,
|
||||
} from "./config-normalization-shared.js";
|
||||
import type { PluginOrigin } from "./plugin-origin.types.js";
|
||||
@@ -76,20 +77,36 @@ function getBundledPluginAliasLookup(): ReadonlyMap<string, string> {
|
||||
return bundledPluginAliasLookup;
|
||||
}
|
||||
|
||||
export function normalizePluginId(id: string): string {
|
||||
function normalizePluginIdWithLookup(
|
||||
id: string,
|
||||
getAliasLookup: () => ReadonlyMap<string, string>,
|
||||
): string {
|
||||
const trimmed = normalizeOptionalString(id) ?? "";
|
||||
const normalized = normalizeOptionalLowercaseString(trimmed) ?? "";
|
||||
const builtInAlias = BUILT_IN_PLUGIN_ALIAS_LOOKUP.get(normalized);
|
||||
if (builtInAlias) {
|
||||
return builtInAlias;
|
||||
}
|
||||
return getBundledPluginAliasLookup().get(normalized) ?? trimmed;
|
||||
return getAliasLookup().get(normalized) ?? trimmed;
|
||||
}
|
||||
|
||||
function createScopedPluginIdNormalizer(): NormalizePluginId {
|
||||
let lookup: ReadonlyMap<string, string> | undefined;
|
||||
return (id) =>
|
||||
normalizePluginIdWithLookup(id, () => {
|
||||
lookup ??= getBundledPluginAliasLookup();
|
||||
return lookup;
|
||||
});
|
||||
}
|
||||
|
||||
export function normalizePluginId(id: string): string {
|
||||
return normalizePluginIdWithLookup(id, getBundledPluginAliasLookup);
|
||||
}
|
||||
|
||||
export const normalizePluginsConfig = (
|
||||
config?: OpenClawConfig["plugins"],
|
||||
): NormalizedPluginsConfig => {
|
||||
return normalizePluginsConfigWithResolver(config, normalizePluginId);
|
||||
return normalizePluginsConfigWithResolver(config, createScopedPluginIdNormalizer());
|
||||
};
|
||||
|
||||
export function createPluginActivationSource(params: {
|
||||
|
||||
Reference in New Issue
Block a user