mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:30:43 +00:00
fix(plugins): resolve runtime metadata fallbacks cold
This commit is contained in:
@@ -4,7 +4,8 @@ import {
|
||||
type PluginManifestCommandAliasRegistry,
|
||||
type PluginManifestCommandAliasRecord,
|
||||
} from "./manifest-command-aliases.js";
|
||||
import { loadPluginManifestRegistry } from "./manifest-registry.js";
|
||||
import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js";
|
||||
import { loadPluginRegistrySnapshot } from "./plugin-registry.js";
|
||||
|
||||
export function resolveManifestCommandAliasOwner(params: {
|
||||
command: string | undefined;
|
||||
@@ -15,11 +16,20 @@ export function resolveManifestCommandAliasOwner(params: {
|
||||
}): PluginManifestCommandAliasRecord | undefined {
|
||||
const registry =
|
||||
params.registry ??
|
||||
loadPluginManifestRegistry({
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
env: params.env,
|
||||
});
|
||||
(() => {
|
||||
const index = loadPluginRegistrySnapshot({
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
env: params.env,
|
||||
});
|
||||
return loadPluginManifestRegistryForInstalledIndex({
|
||||
index,
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
env: params.env,
|
||||
includeDisabled: true,
|
||||
});
|
||||
})();
|
||||
return resolveManifestCommandAliasOwnerInRegistry({
|
||||
command: params.command,
|
||||
registry,
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const getPluginRegistryState = vi.hoisted(() => vi.fn());
|
||||
const loadPluginManifestRegistry = vi.hoisted(() => vi.fn());
|
||||
const pluginRegistryMocks = vi.hoisted(() => ({
|
||||
loadPluginManifestRegistryForInstalledIndex: vi.fn(),
|
||||
loadPluginRegistrySnapshot: vi.fn(() => ({ plugins: [] })),
|
||||
}));
|
||||
|
||||
vi.mock("./runtime-state.js", () => ({
|
||||
getPluginRegistryState,
|
||||
}));
|
||||
|
||||
vi.mock("./manifest-registry.js", () => ({
|
||||
loadPluginManifestRegistry,
|
||||
vi.mock("./manifest-registry-installed.js", () => ({
|
||||
loadPluginManifestRegistryForInstalledIndex:
|
||||
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex,
|
||||
}));
|
||||
|
||||
vi.mock("./plugin-registry.js", () => ({
|
||||
loadPluginRegistrySnapshot: pluginRegistryMocks.loadPluginRegistrySnapshot,
|
||||
}));
|
||||
|
||||
import { resolveRuntimeSyntheticAuthProviderRefs } from "./synthetic-auth.runtime.js";
|
||||
@@ -16,11 +24,14 @@ import { resolveRuntimeSyntheticAuthProviderRefs } from "./synthetic-auth.runtim
|
||||
describe("synthetic auth runtime refs", () => {
|
||||
beforeEach(() => {
|
||||
getPluginRegistryState.mockReset();
|
||||
loadPluginManifestRegistry.mockReset().mockReturnValue({ plugins: [] });
|
||||
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex
|
||||
.mockReset()
|
||||
.mockReturnValue({ plugins: [] });
|
||||
pluginRegistryMocks.loadPluginRegistrySnapshot.mockReset().mockReturnValue({ plugins: [] });
|
||||
});
|
||||
|
||||
it("uses manifest-owned synthetic auth refs before the runtime registry exists", () => {
|
||||
loadPluginManifestRegistry.mockReturnValue({
|
||||
pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex.mockReturnValue({
|
||||
plugins: [
|
||||
{ syntheticAuthRefs: [" local-provider ", "local-provider", "local-cli"] },
|
||||
{ syntheticAuthRefs: ["remote-provider"] },
|
||||
@@ -33,7 +44,11 @@ describe("synthetic auth runtime refs", () => {
|
||||
"local-cli",
|
||||
"remote-provider",
|
||||
]);
|
||||
expect(loadPluginManifestRegistry).toHaveBeenCalledWith({ cache: true });
|
||||
expect(pluginRegistryMocks.loadPluginRegistrySnapshot).toHaveBeenCalledWith({ cache: true });
|
||||
expect(pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex).toHaveBeenCalledWith({
|
||||
index: expect.anything(),
|
||||
includeDisabled: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers the active runtime registry when plugins are already loaded", () => {
|
||||
@@ -64,6 +79,7 @@ describe("synthetic auth runtime refs", () => {
|
||||
});
|
||||
|
||||
expect(resolveRuntimeSyntheticAuthProviderRefs()).toEqual(["runtime-provider", "runtime-cli"]);
|
||||
expect(loadPluginManifestRegistry).not.toHaveBeenCalled();
|
||||
expect(pluginRegistryMocks.loadPluginManifestRegistryForInstalledIndex).not.toHaveBeenCalled();
|
||||
expect(pluginRegistryMocks.loadPluginRegistrySnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { normalizeProviderId } from "../agents/provider-id.js";
|
||||
import { loadPluginManifestRegistry } from "./manifest-registry.js";
|
||||
import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js";
|
||||
import { loadPluginRegistrySnapshot } from "./plugin-registry.js";
|
||||
import { getPluginRegistryState } from "./runtime-state.js";
|
||||
|
||||
function uniqueProviderRefs(values: readonly string[]): string[] {
|
||||
@@ -18,10 +19,12 @@ function uniqueProviderRefs(values: readonly string[]): string[] {
|
||||
}
|
||||
|
||||
function resolveManifestSyntheticAuthProviderRefs(): string[] {
|
||||
const index = loadPluginRegistrySnapshot({ cache: true });
|
||||
return uniqueProviderRefs(
|
||||
loadPluginManifestRegistry({ cache: true }).plugins.flatMap(
|
||||
(plugin) => plugin.syntheticAuthRefs ?? [],
|
||||
),
|
||||
loadPluginManifestRegistryForInstalledIndex({
|
||||
index,
|
||||
includeDisabled: true,
|
||||
}).plugins.flatMap((plugin) => plugin.syntheticAuthRefs ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user