test(auth): cover manifest provider plugin enabling

This commit is contained in:
Ayaan Zaidi
2026-04-29 17:32:51 +05:30
parent 9bf7b6bfca
commit 49f94db5d4

View File

@@ -1046,6 +1046,81 @@ describe("applyAuthChoice", () => {
);
});
it("enables the owning plugin for manifest provider auth choices", async () => {
await setupTempState();
const provider = createFixedChoiceProvider({
providerId: "github-copilot",
label: "GitHub Copilot",
choiceId: "github-copilot-github",
method: {
id: "github",
label: "GitHub Copilot",
kind: "token",
run: vi.fn(
async (): Promise<ProviderAuthResult> => ({
profiles: [
{
profileId: "github-copilot:github",
credential: {
type: "token",
provider: "github-copilot",
token: "gho_copilot_test",
},
},
],
defaultModel: "github-copilot/claude-opus-4.7",
}),
),
},
});
const manifestSpy = vi
.spyOn(providerAuthChoices, "resolveManifestProviderAuthChoice")
.mockReturnValue({
pluginId: "github-copilot",
providerId: "github-copilot",
methodId: "github",
choiceId: "github-copilot-github",
choiceLabel: "GitHub Copilot",
});
providerAuthChoiceTesting.setDepsForTest({
loadPluginProviderRuntime: async () => ({
resolvePluginProviders,
resolvePluginSetupProvider: () => provider,
resolveProviderPluginChoice,
runProviderModelSelectedHook,
}),
});
try {
const result = await applyAuthChoice({
authChoice: "github-copilot-github",
config: { plugins: { entries: { "github-copilot": { enabled: false } } } },
prompter: createPrompter({}),
runtime: createExitThrowingRuntime(),
setDefaultModel: true,
preserveExistingDefaultModel: true,
});
expect(result.config.plugins?.entries?.["github-copilot"]).toEqual({ enabled: true });
expect(result.config.auth?.profiles?.["github-copilot:github"]).toMatchObject({
provider: "github-copilot",
mode: "token",
});
expect(resolveAgentModelPrimaryValue(result.config.agents?.defaults?.model)).toBe(
"github-copilot/claude-opus-4.7",
);
} finally {
manifestSpy.mockRestore();
providerAuthChoiceTesting.setDepsForTest({
loadPluginProviderRuntime: async () => ({
resolvePluginProviders,
resolvePluginSetupProvider: () => undefined,
resolveProviderPluginChoice,
runProviderModelSelectedHook,
}),
});
}
});
it("uses explicit env for plugin auth resolution instead of host env", async () => {
await setupTempState();
process.env.OPENAI_API_KEY = "sk-openai-host"; // pragma: allowlist secret