Files
openclaw/src/plugins/provider-setup-availability.test.ts
T
Peter Steinberger e74be5d41d refactor: eliminate final wrapper-shadowing hazards (#122157)
* refactor: disambiguate wrapper-shadowed exports

* test: align renamed session and facade boundaries

* test: cover renamed runtime mock exports

* refactor: align remaining wrapper owner call sites

* test: align overlap-rebased runtime mocks

* refactor: preserve public SDK names after overlap rebase

* chore: regenerate wrapper shadowing baselines

* test: align cron model selection mocks
2026-08-11 13:34:24 -07:00

87 lines
2.4 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { detectAvailableSetupProviderIds } from "./provider-setup-availability.js";
const resolveManifestProviderAuthChoices = vi.hoisted(() => vi.fn());
const enablePluginInConfig = vi.hoisted(() => vi.fn());
const resolvePluginProvidersCore = vi.hoisted(() => vi.fn());
const debug = vi.hoisted(() => vi.fn());
vi.mock("./provider-auth-choices.js", () => ({
resolveManifestProviderAuthChoices,
}));
vi.mock("./enable.js", () => ({
enablePluginInConfig,
}));
vi.mock("./providers.runtime.js", () => ({
resolvePluginProvidersCore,
}));
vi.mock("../logging/subsystem.js", () => ({
createSubsystemLogger: () => ({ debug }),
}));
describe("detectAvailableSetupProviderIds", () => {
beforeEach(() => {
vi.clearAllMocks();
resolveManifestProviderAuthChoices.mockReturnValue([
{
pluginId: "ollama",
providerId: "ollama",
methodId: "local",
choiceId: "ollama",
choiceLabel: "Ollama",
appGuidedDiscovery: true,
},
]);
enablePluginInConfig.mockImplementation((config: unknown) => ({
config,
enabled: true,
pluginId: "ollama",
}));
});
it("returns the provider id when its read-only availability probe succeeds", async () => {
const detectAvailability = vi.fn(async () => true);
resolvePluginProvidersCore.mockReturnValue([
{
pluginId: "ollama",
id: "ollama",
auth: [{ id: "local", appGuidedSetup: { detectAvailability } }],
},
]);
await expect(detectAvailableSetupProviderIds({ config: {} })).resolves.toEqual(
new Set(["ollama"]),
);
expect(detectAvailability).toHaveBeenCalledWith({
config: {},
env: process.env,
workspaceDir: undefined,
});
});
it("treats failed availability probes as an intentional non-match", async () => {
resolvePluginProvidersCore.mockReturnValue([
{
pluginId: "ollama",
id: "ollama",
auth: [
{
id: "local",
appGuidedSetup: {
detectAvailability: vi.fn(async () => {
throw new Error("offline");
}),
},
},
],
},
]);
await expect(detectAvailableSetupProviderIds({ config: {} })).resolves.toEqual(new Set());
expect(debug).toHaveBeenCalledWith(expect.stringContaining("offline"));
});
});