From 49f94db5d46b90b5b878ff0c1b091971e367c84d Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Wed, 29 Apr 2026 17:32:51 +0530 Subject: [PATCH] test(auth): cover manifest provider plugin enabling --- src/commands/auth-choice.test.ts | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/commands/auth-choice.test.ts b/src/commands/auth-choice.test.ts index d6043e21f73..07023227848 100644 --- a/src/commands/auth-choice.test.ts +++ b/src/commands/auth-choice.test.ts @@ -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 => ({ + 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