mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:50:45 +00:00
fix(plugins): use registry for setup cli fallback
This commit is contained in:
@@ -1,33 +1,43 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const loadPluginManifestRegistryMock = vi.hoisted(() => vi.fn());
|
||||
const loadPluginRegistrySnapshotMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("./manifest-registry.js", () => ({
|
||||
loadPluginManifestRegistry: loadPluginManifestRegistryMock,
|
||||
vi.mock("./plugin-registry.js", () => ({
|
||||
loadPluginRegistrySnapshot: loadPluginRegistrySnapshotMock,
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
loadPluginManifestRegistryMock.mockReset();
|
||||
loadPluginRegistrySnapshotMock.mockReset();
|
||||
});
|
||||
|
||||
describe("setup-registry runtime fallback", () => {
|
||||
it("uses bundled manifest cliBackends when the setup-registry runtime is unavailable", async () => {
|
||||
loadPluginManifestRegistryMock.mockReturnValue({
|
||||
it("uses bundled registry cliBackends when the setup-registry runtime is unavailable", async () => {
|
||||
loadPluginRegistrySnapshotMock.mockReturnValue({
|
||||
diagnostics: [],
|
||||
plugins: [
|
||||
{
|
||||
id: "openai",
|
||||
pluginId: "openai",
|
||||
origin: "bundled",
|
||||
cliBackends: ["legacy-openai-cli"],
|
||||
setup: {
|
||||
cliBackends: ["Codex-CLI"],
|
||||
requiresRuntime: true,
|
||||
enabled: true,
|
||||
contributions: {
|
||||
cliBackends: ["Codex-CLI", "legacy-openai-cli"],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "local",
|
||||
pluginId: "disabled",
|
||||
origin: "bundled",
|
||||
enabled: false,
|
||||
contributions: {
|
||||
cliBackends: ["disabled-cli"],
|
||||
},
|
||||
},
|
||||
{
|
||||
pluginId: "local",
|
||||
origin: "workspace",
|
||||
cliBackends: ["local-cli"],
|
||||
enabled: true,
|
||||
contributions: {
|
||||
cliBackends: ["local-cli"],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -42,21 +52,21 @@ describe("setup-registry runtime fallback", () => {
|
||||
backend: { id: "Codex-CLI" },
|
||||
});
|
||||
expect(resolvePluginSetupCliBackendRuntime({ backend: "local-cli" })).toBeUndefined();
|
||||
expect(loadPluginManifestRegistryMock).toHaveBeenCalledTimes(1);
|
||||
expect(loadPluginManifestRegistryMock).toHaveBeenCalledWith({ cache: true });
|
||||
expect(resolvePluginSetupCliBackendRuntime({ backend: "disabled-cli" })).toBeUndefined();
|
||||
expect(loadPluginRegistrySnapshotMock).toHaveBeenCalledTimes(1);
|
||||
expect(loadPluginRegistrySnapshotMock).toHaveBeenCalledWith({ cache: true });
|
||||
});
|
||||
|
||||
it("preserves fail-closed setup lookup when the runtime module explicitly declines to resolve", async () => {
|
||||
loadPluginManifestRegistryMock.mockReturnValue({
|
||||
loadPluginRegistrySnapshotMock.mockReturnValue({
|
||||
diagnostics: [],
|
||||
plugins: [
|
||||
{
|
||||
id: "openai",
|
||||
pluginId: "openai",
|
||||
origin: "bundled",
|
||||
cliBackends: ["legacy-openai-cli"],
|
||||
setup: {
|
||||
cliBackends: ["Codex-CLI"],
|
||||
requiresRuntime: true,
|
||||
enabled: true,
|
||||
contributions: {
|
||||
cliBackends: ["Codex-CLI", "legacy-openai-cli"],
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -70,6 +80,6 @@ describe("setup-registry runtime fallback", () => {
|
||||
});
|
||||
|
||||
expect(resolvePluginSetupCliBackendRuntime({ backend: "codex-cli" })).toBeUndefined();
|
||||
expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled();
|
||||
expect(loadPluginRegistrySnapshotMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { normalizeProviderId } from "../agents/provider-id.js";
|
||||
import { loadPluginManifestRegistry } from "./manifest-registry.js";
|
||||
import { listSetupCliBackendIds } from "./setup-descriptors.js";
|
||||
import { loadPluginRegistrySnapshot } from "./plugin-registry.js";
|
||||
|
||||
type SetupRegistryRuntimeModule = Pick<
|
||||
typeof import("./setup-registry.js"),
|
||||
@@ -35,19 +34,15 @@ function resolveBundledSetupCliBackends(): SetupCliBackendRuntimeEntry[] {
|
||||
if (bundledSetupCliBackendsCache) {
|
||||
return bundledSetupCliBackendsCache;
|
||||
}
|
||||
bundledSetupCliBackendsCache = loadPluginManifestRegistry({ cache: true }).plugins.flatMap(
|
||||
bundledSetupCliBackendsCache = loadPluginRegistrySnapshot({ cache: true }).plugins.flatMap(
|
||||
(plugin) => {
|
||||
if (plugin.origin !== "bundled") {
|
||||
if (plugin.origin !== "bundled" || plugin.enabled === false) {
|
||||
return [];
|
||||
}
|
||||
const backendIds = listSetupCliBackendIds(plugin);
|
||||
if (backendIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return backendIds.map(
|
||||
return plugin.contributions.cliBackends.map(
|
||||
(backendId) =>
|
||||
({
|
||||
pluginId: plugin.id,
|
||||
pluginId: plugin.pluginId,
|
||||
backend: { id: backendId },
|
||||
}) satisfies SetupCliBackendRuntimeEntry,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user