-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: robust provider handling when credentials are misconfigured #10080
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11297e4
fix: fix providers with wrong credentials
catrielmuller ff31c68
fix: add failed field to provider story fixture
catrielmuller b961ed3
refactor: address the comments
catrielmuller 7106765
fix: address PR review feedback on provider failed-state filtering an…
catrielmuller cd67db9
fix: kilocode markers
catrielmuller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Verifies fetchKiloModels typed result and 401 fallback behaviour. | ||
|
|
||
| import { test, expect } from "bun:test" | ||
| import { fetchKiloModels } from "../../src/api/models.js" | ||
|
|
||
| const VALID_RESPONSE = JSON.stringify({ | ||
| data: [ | ||
| { | ||
| id: "test/model-a", | ||
| name: "Test Model A", | ||
| context_length: 128000, | ||
| max_completion_tokens: 16384, | ||
| architecture: { | ||
| input_modalities: ["text"], | ||
| output_modalities: ["text"], | ||
| }, | ||
| supported_parameters: ["tools", "temperature"], | ||
| }, | ||
| ], | ||
| }) | ||
|
|
||
| function stubFetch(fn: (input: string | URL | Request, init?: RequestInit) => Promise<Response>) { | ||
| ;(globalThis as any).fetch = fn | ||
| } | ||
|
|
||
| test("returns empty models and error when both auth and public requests return 401", async () => { | ||
| const orig = globalThis.fetch | ||
| stubFetch(async () => new Response("Unauthorized", { status: 401, statusText: "Unauthorized" })) | ||
|
|
||
| const result = await fetchKiloModels({ kilocodeToken: "bad-token" }) | ||
|
|
||
| ;(globalThis as any).fetch = orig | ||
|
|
||
| expect(result.models).toEqual({}) | ||
| expect(result.error).toBeDefined() | ||
| }) | ||
|
|
||
| test("falls back to public endpoint on 401 and returns models", async () => { | ||
| const orig = globalThis.fetch | ||
| let callCount = 0 | ||
|
|
||
| stubFetch(async () => { | ||
| callCount++ | ||
| if (callCount === 1) { | ||
| return new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }) | ||
| } | ||
| return new Response(VALID_RESPONSE, { | ||
| status: 200, | ||
| headers: { "content-type": "application/json" }, | ||
| }) | ||
| }) | ||
|
|
||
| const result = await fetchKiloModels({ | ||
| kilocodeToken: "expired-token", | ||
| kilocodeOrganizationId: "org-123", | ||
| }) | ||
|
|
||
| ;(globalThis as any).fetch = orig | ||
|
|
||
| expect(callCount).toBe(2) | ||
| expect(result.error).toBeUndefined() | ||
| expect(Object.keys(result.models).length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| test("returns error with kind=network on fetch exception", async () => { | ||
| const orig = globalThis.fetch | ||
| stubFetch(async () => { | ||
| throw new Error("network error") | ||
| }) | ||
|
|
||
| const result = await fetchKiloModels({}) | ||
|
|
||
| ;(globalThis as any).fetch = orig | ||
|
|
||
| expect(result.models).toEqual({}) | ||
| expect(result.error?.kind).toBe("network") | ||
| }) | ||
|
|
||
| test("returns error with kind=unauthorized on non-401 HTTP error without auth", async () => { | ||
| const orig = globalThis.fetch | ||
| stubFetch(async () => new Response("Server Error", { status: 500, statusText: "Internal Server Error" })) | ||
|
|
||
| const result = await fetchKiloModels({}) | ||
|
|
||
| ;(globalThis as any).fetch = orig | ||
|
|
||
| expect(result.models).toEqual({}) | ||
| expect(result.error?.kind).toBe("unauthorized") | ||
| expect(result.error?.status).toBe(500) | ||
| }) | ||
|
|
||
| test("returns models without error on success", async () => { | ||
| const orig = globalThis.fetch | ||
| stubFetch(async () => | ||
| new Response(VALID_RESPONSE, { | ||
| status: 200, | ||
| headers: { "content-type": "application/json" }, | ||
| }), | ||
| ) | ||
|
|
||
| const result = await fetchKiloModels({}) | ||
|
|
||
| ;(globalThis as any).fetch = orig | ||
|
|
||
| expect(result.error).toBeUndefined() | ||
| expect(Object.keys(result.models).length).toBeGreaterThan(0) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
|
|
||
| import { EOL } from "os" | ||
| import { Effect } from "effect" | ||
| import { Provider } from "@/provider/provider" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.