Skip to content

Commit 28d3db9

Browse files
committed
test(code-index): cover missing OpenRouter API key and simplify defensive-branch access
1 parent c17050f commit 28d3db9

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎src/services/code-index/__tests__/config-manager.spec.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,18 @@ describe("CodeIndexConfigManager", () => {
22042204
configManager = new CodeIndexConfigManager(mockContextProxy)
22052205
expect(configManager.isConfigured()).toBe(false)
22062206
})
2207+
2208+
it("should return false from isConfigured for OpenRouter when the API key is missing", () => {
2209+
mockContextProxy.getGlobalState.mockReturnValue({
2210+
codebaseIndexEnabled: true,
2211+
codebaseIndexQdrantUrl: "http://qdrant.local",
2212+
codebaseIndexEmbedderProvider: providerIdentifiers.openrouter,
2213+
})
2214+
mockContextProxy.getSecret.mockReturnValue(undefined)
2215+
2216+
configManager = new CodeIndexConfigManager(mockContextProxy)
2217+
expect(configManager.isConfigured()).toBe(false)
2218+
})
22072219
})
22082220

22092221
describe("isConfigured defensive fallback", () => {
@@ -2219,9 +2231,13 @@ describe("CodeIndexConfigManager", () => {
22192231
mockContextProxy.getSecret.mockReturnValue(undefined)
22202232

22212233
configManager = new CodeIndexConfigManager(mockContextProxy)
2222-
// The private `embedderProvider` field has no public setter; the cast is the
2223-
// only way to reach the defensive branch without changing source logic.
2224-
Object.defineProperty(configManager, "embedderProvider", { value: "not-a-provider" })
2234+
// The defensive `return false` is unreachable through the public API because
2235+
// EmbedderProvider is a closed union, so exercise it by forcing the private field
2236+
// to a value outside the union. `embedderProvider` is TypeScript `private`, not
2237+
// `#`-private, so a runtime property write reaches it. The double assertion is a
2238+
// last resort: the private field is not part of the public type surface, and
2239+
// `as any` is avoided to keep the file's no-explicit-any suppression budget flat.
2240+
;(configManager as unknown as Record<string, unknown>)["embedderProvider"] = "not-a-provider"
22252241
expect(configManager.isConfigured()).toBe(false)
22262242
})
22272243
})

0 commit comments

Comments
 (0)