-
Notifications
You must be signed in to change notification settings - Fork 269
test(code-index,tools): cover lines left uncovered by #1297 #1317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63dd593
a36cf86
10e9997
2a4634a
c17050f
28d3db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2055,4 +2055,190 @@ describe("CodeIndexConfigManager", () => { | |
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe("mistral, vercel-ai-gateway, bedrock and openrouter provider configuration", () => { | ||
| it("should load Mistral provider configuration and mark it configured", async () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.mistral, | ||
| }) | ||
| mockContextProxy.getSecret.mockImplementation((key: string) => { | ||
| if (key === "codebaseIndexMistralApiKey") return "test-mistral-key" | ||
| return undefined | ||
| }) | ||
|
|
||
| const result = await configManager.loadConfiguration() | ||
|
|
||
| expect(result.currentConfig.embedderProvider).toBe(providerIdentifiers.mistral) | ||
| expect(result.currentConfig.mistralOptions).toEqual({ apiKey: "test-mistral-key" }) | ||
| expect(result.currentConfig.isConfigured).toBe(true) | ||
| expect(configManager.currentEmbedderProvider).toBe("mistral") | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for Mistral when the API key is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.mistral, | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for Mistral when the Qdrant URL is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.mistral, | ||
| }) | ||
| mockContextProxy.getSecret.mockImplementation((key: string) => { | ||
| if (key === "codebaseIndexMistralApiKey") return "test-mistral-key" | ||
| return undefined | ||
| }) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
|
||
| it("should load Vercel AI Gateway provider configuration and mark it configured", async () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.vercelAiGateway, | ||
| }) | ||
| mockContextProxy.getSecret.mockImplementation((key: string) => { | ||
| if (key === "codebaseIndexVercelAiGatewayApiKey") return "test-vercel-key" | ||
| return undefined | ||
| }) | ||
|
|
||
| const result = await configManager.loadConfiguration() | ||
|
|
||
| expect(result.currentConfig.embedderProvider).toBe(providerIdentifiers.vercelAiGateway) | ||
| expect(result.currentConfig.vercelAiGatewayOptions).toEqual({ apiKey: "test-vercel-key" }) | ||
| expect(result.currentConfig.isConfigured).toBe(true) | ||
| expect(configManager.currentEmbedderProvider).toBe("vercel-ai-gateway") | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for Vercel AI Gateway when the API key is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.vercelAiGateway, | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for Vercel AI Gateway when the Qdrant URL is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.vercelAiGateway, | ||
| }) | ||
| mockContextProxy.getSecret.mockImplementation((key: string) => { | ||
| if (key === "codebaseIndexVercelAiGatewayApiKey") return "test-vercel-key" | ||
| return undefined | ||
| }) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
|
||
| it("should load Bedrock provider configuration with region and profile and mark it configured", async () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.bedrock, | ||
| codebaseIndexBedrockRegion: "eu-west-1", | ||
| codebaseIndexBedrockProfile: "test-profile", | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| const result = await configManager.loadConfiguration() | ||
|
|
||
| expect(result.currentConfig.embedderProvider).toBe(providerIdentifiers.bedrock) | ||
| expect(result.currentConfig.bedrockOptions).toEqual({ region: "eu-west-1", profile: "test-profile" }) | ||
| expect(result.currentConfig.isConfigured).toBe(true) | ||
| expect(configManager.currentEmbedderProvider).toBe("bedrock") | ||
| }) | ||
|
|
||
| it("should default Bedrock region to us-east-1 when no region is configured", async () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.bedrock, | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| const result = await configManager.loadConfiguration() | ||
|
|
||
| expect(result.currentConfig.bedrockOptions).toEqual({ region: "us-east-1", profile: undefined }) | ||
| expect(result.currentConfig.isConfigured).toBe(true) | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for Bedrock when the Qdrant URL is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.bedrock, | ||
| codebaseIndexBedrockRegion: "us-east-1", | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
|
||
| it("should return false from isConfigured for OpenRouter when the Qdrant URL is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.openrouter, | ||
| }) | ||
| mockContextProxy.getSecret.mockImplementation((key: string) => { | ||
| if (key === "codebaseIndexOpenRouterApiKey") return "test-openrouter-key" | ||
| return undefined | ||
| }) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a symmetric case where |
||
|
|
||
| it("should return false from isConfigured for OpenRouter when the API key is missing", () => { | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| codebaseIndexQdrantUrl: "http://qdrant.local", | ||
| codebaseIndexEmbedderProvider: providerIdentifiers.openrouter, | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe("isConfigured defensive fallback", () => { | ||
| it("should return false when the provider is not a recognized embedder provider", () => { | ||
| // The isConfigured() switch lists every EmbedderProvider member explicitly and | ||
| // ends in a defensive `return false` ("Should not happen if embedderProvider is | ||
| // always set correctly"). That fallback is unreachable through the public API | ||
| // because EmbedderProvider is a closed union, so exercise it by forcing the | ||
| // private field to a value outside the union. | ||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| }) | ||
| mockContextProxy.getSecret.mockReturnValue(undefined) | ||
|
|
||
| configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| // The defensive `return false` is unreachable through the public API because | ||
| // EmbedderProvider is a closed union, so exercise it by forcing the private field | ||
| // to a value outside the union. `embedderProvider` is TypeScript `private`, not | ||
| // `#`-private, so a runtime property write reaches it. The double assertion is a | ||
| // last resort: the private field is not part of the public type surface, and | ||
| // `as any` is avoided to keep the file's no-explicit-any suppression budget flat. | ||
| ;(configManager as unknown as Record<string, unknown>)["embedderProvider"] = "not-a-provider" | ||
| expect(configManager.isConfigured()).toBe(false) | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.