test: cover provider plugin boundaries

This commit is contained in:
Peter Steinberger
2026-03-12 22:43:55 +00:00
parent 300a093121
commit 2c8f31135b
3 changed files with 296 additions and 1 deletions

View File

@@ -2,7 +2,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ProviderPlugin } from "../plugins/types.js";
import type { ProviderAuthMethod } from "../plugins/types.js";
import type { ApplyAuthChoiceParams } from "./auth-choice.apply.js";
import { applyAuthChoiceLoadedPluginProvider } from "./auth-choice.apply.plugin-provider.js";
import {
applyAuthChoiceLoadedPluginProvider,
applyAuthChoicePluginProvider,
runProviderPluginAuthMethod,
} from "./auth-choice.apply.plugin-provider.js";
const resolvePluginProviders = vi.hoisted(() => vi.fn<() => ProviderPlugin[]>(() => []));
vi.mock("../plugins/providers.js", () => ({
@@ -105,6 +109,7 @@ function buildParams(overrides: Partial<ApplyAuthChoiceParams> = {}): ApplyAuthC
describe("applyAuthChoiceLoadedPluginProvider", () => {
beforeEach(() => {
vi.clearAllMocks();
applyAuthProfileConfig.mockImplementation((config) => config);
});
it("returns an agent model override when default model application is deferred", async () => {
@@ -158,4 +163,159 @@ describe("applyAuthChoiceLoadedPluginProvider", () => {
workspaceDir: "/tmp/workspace",
});
});
it("merges provider config patches and emits provider notes", async () => {
applyAuthProfileConfig.mockImplementation(((
config: {
auth?: {
profiles?: Record<string, { provider: string; mode: string }>;
};
},
profile: { profileId: string; provider: string; mode: string },
) => ({
...config,
auth: {
profiles: {
...config.auth?.profiles,
[profile.profileId]: {
provider: profile.provider,
mode: profile.mode,
},
},
},
})) as never);
const note = vi.fn(async () => {});
const method: ProviderAuthMethod = {
id: "local",
label: "Local",
kind: "custom",
run: async () => ({
profiles: [
{
profileId: "ollama:default",
credential: {
type: "api_key",
provider: "ollama",
key: "ollama-local",
},
},
],
configPatch: {
models: {
providers: {
ollama: {
api: "ollama",
baseUrl: "http://127.0.0.1:11434",
models: [],
},
},
},
},
defaultModel: "ollama/qwen3:4b",
notes: ["Detected local Ollama runtime.", "Pulled model metadata."],
}),
};
const result = await runProviderPluginAuthMethod({
config: {
agents: {
defaults: {
model: { primary: "anthropic/claude-sonnet-4-5" },
},
},
},
runtime: {} as ApplyAuthChoiceParams["runtime"],
prompter: {
note,
} as unknown as ApplyAuthChoiceParams["prompter"],
method,
});
expect(result.defaultModel).toBe("ollama/qwen3:4b");
expect(result.config.models?.providers?.ollama).toEqual({
api: "ollama",
baseUrl: "http://127.0.0.1:11434",
models: [],
});
expect(result.config.auth?.profiles?.["ollama:default"]).toEqual({
provider: "ollama",
mode: "api_key",
});
expect(note).toHaveBeenCalledWith(
"Detected local Ollama runtime.\nPulled model metadata.",
"Provider notes",
);
});
it("returns an agent-scoped override for plugin auth choices when default model application is deferred", async () => {
const provider = buildProvider();
resolvePluginProviders.mockReturnValue([provider]);
const note = vi.fn(async () => {});
const result = await applyAuthChoicePluginProvider(
buildParams({
authChoice: "provider-plugin:ollama:local",
agentId: "worker",
setDefaultModel: false,
prompter: {
note,
} as unknown as ApplyAuthChoiceParams["prompter"],
}),
{
authChoice: "provider-plugin:ollama:local",
pluginId: "ollama",
providerId: "ollama",
methodId: "local",
label: "Ollama",
},
);
expect(result?.agentModelOverride).toBe("ollama/qwen3:4b");
expect(result?.config.plugins).toEqual({
entries: {
ollama: {
enabled: true,
},
},
});
expect(runProviderModelSelectedHook).not.toHaveBeenCalled();
expect(note).toHaveBeenCalledWith(
'Default model set to ollama/qwen3:4b for agent "worker".',
"Model configured",
);
});
it("stops early when the plugin is disabled in config", async () => {
const note = vi.fn(async () => {});
const result = await applyAuthChoicePluginProvider(
buildParams({
config: {
plugins: {
enabled: false,
},
},
prompter: {
note,
} as unknown as ApplyAuthChoiceParams["prompter"],
}),
{
authChoice: "ollama",
pluginId: "ollama",
providerId: "ollama",
label: "Ollama",
},
);
expect(result).toEqual({
config: {
plugins: {
enabled: false,
},
},
});
expect(resolvePluginProviders).not.toHaveBeenCalled();
expect(note).toHaveBeenCalledWith("Ollama plugin is disabled (plugins disabled).", "Ollama");
});
});