Skip to content

Commit fe6bc63

Browse files
committed
fix: address Bedrock provider review feedback
1 parent 993f16c commit fe6bc63

4 files changed

Lines changed: 35 additions & 33 deletions

File tree

coderd/ai_providers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (api *API) aiProvidersUpdate(rw http.ResponseWriter, r *http.Request) {
405405
}
406406
if errors.Is(err, errAIProviderBedrockTypeMismatch) {
407407
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
408-
Message: "Bedrock settings are only valid for type=anthropic or type=bedrock.",
408+
Message: "Bedrock settings are only valid for type=bedrock.",
409409
})
410410
return
411411
}
@@ -511,9 +511,9 @@ var errCopilotRejectsAPIKeys = xerrors.New("copilot providers do not accept api_
511511

512512
// errAIProviderBedrockTypeMismatch is the sentinel returned from
513513
// inside the update transaction when the post-merge settings carry a
514-
// Bedrock block but the provider is not anthropic- or bedrock-typed;
515-
// the outer handler translates it into a 400.
516-
var errAIProviderBedrockTypeMismatch = xerrors.New("bedrock settings are only valid for type=anthropic or type=bedrock")
514+
// Bedrock block but the provider is not Bedrock-typed; the outer handler
515+
// translates it into a 400.
516+
var errAIProviderBedrockTypeMismatch = xerrors.New("bedrock settings are only valid for type=bedrock")
517517

518518
// errAIProviderBedrockSettingsRequired is returned when a Bedrock provider
519519
// would be stored without enough Bedrock connection settings.

coderd/ai_providers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func TestAIProvidersCRUD(t *testing.T) {
520520
require.NotEmpty(t, sdkErr.Message)
521521
})
522522

523-
t.Run("BedrockSettingsRequireAnthropic", func(t *testing.T) {
523+
t.Run("BedrockSettingsRequireBedrock", func(t *testing.T) {
524524
t.Parallel()
525525
client := coderdtest.New(t, nil)
526526
_ = coderdtest.CreateFirstUser(t, client)
@@ -550,7 +550,7 @@ func TestAIProvidersCRUD(t *testing.T) {
550550
require.Contains(t, sdkErr.Message, "Invalid AI provider request")
551551
require.NotEmpty(t, sdkErr.Validations)
552552
require.Equal(t, "settings", sdkErr.Validations[0].Field)
553-
require.Contains(t, sdkErr.Validations[0].Detail, "bedrock settings are only valid for type=anthropic")
553+
require.Contains(t, sdkErr.Validations[0].Detail, "bedrock settings are only valid for type=bedrock")
554554

555555
// Update: existing OpenAI provider patched with Bedrock settings
556556
// must also be rejected.
@@ -569,7 +569,7 @@ func TestAIProvidersCRUD(t *testing.T) {
569569
require.Error(t, err)
570570
require.ErrorAs(t, err, &sdkErr)
571571
require.Equal(t, http.StatusBadRequest, sdkErr.StatusCode())
572-
require.Contains(t, sdkErr.Message, "Bedrock settings are only valid for type=anthropic")
572+
require.Contains(t, sdkErr.Message, "Bedrock settings are only valid for type=bedrock")
573573
})
574574

575575
t.Run("BedrockSecretsHidden", func(t *testing.T) {

codersdk/aiproviders.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,10 @@ func (req CreateAIProviderRequest) Validate() []ValidationError {
238238
validations = append(validations, validateAIProviderName(req.Name)...)
239239
validations = append(validations, validateRequiredAIProviderBaseURL(req.BaseURL)...)
240240
validations = append(validations, validateAIProviderAPIKeys(req.APIKeys)...)
241-
if req.Settings.Bedrock != nil &&
242-
req.Type != AIProviderTypeAnthropic &&
243-
req.Type != AIProviderTypeBedrock {
241+
if req.Settings.Bedrock != nil && req.Type != AIProviderTypeBedrock {
244242
validations = append(validations, ValidationError{
245243
Field: "settings",
246-
Detail: "bedrock settings are only valid for type=anthropic or type=bedrock",
244+
Detail: "bedrock settings are only valid for type=bedrock",
247245
})
248246
}
249247
if req.Type == AIProviderTypeBedrock && (req.Settings.Bedrock == nil || !IsBedrockConfigured(req.BaseURL, *req.Settings.Bedrock)) {

site/src/api/queries/chats.test.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,33 @@ import {
5757
updateInfiniteChatsCache,
5858
} from "./chats";
5959

60-
vi.mock("#/api/api", () => ({
61-
API: {
62-
experimental: {
63-
updateChat: vi.fn(),
64-
createChat: vi.fn(),
65-
deleteChatQueuedMessage: vi.fn(),
66-
getChats: vi.fn(),
67-
getChatCostSummary: vi.fn(),
68-
getChatCostUsers: vi.fn(),
69-
createChatMessage: vi.fn(),
70-
editChatMessage: vi.fn(),
71-
interruptChat: vi.fn(),
72-
promoteChatQueuedMessage: vi.fn(),
73-
proposeChatTitle: vi.fn(),
74-
regenerateChatTitle: vi.fn(),
75-
getChatAdvisorConfig: vi.fn(),
76-
updateChatAdvisorConfig: vi.fn(),
77-
getChatACL: vi.fn(),
78-
updateChatACL: vi.fn(),
79-
listAIProviders: vi.fn(),
60+
vi.mock("#/api/api", async (importOriginal) => {
61+
const actual = await importOriginal<typeof import("#/api/api")>();
62+
return {
63+
...actual,
64+
API: {
65+
experimental: {
66+
updateChat: vi.fn(),
67+
createChat: vi.fn(),
68+
deleteChatQueuedMessage: vi.fn(),
69+
getChats: vi.fn(),
70+
getChatCostSummary: vi.fn(),
71+
getChatCostUsers: vi.fn(),
72+
createChatMessage: vi.fn(),
73+
editChatMessage: vi.fn(),
74+
interruptChat: vi.fn(),
75+
promoteChatQueuedMessage: vi.fn(),
76+
proposeChatTitle: vi.fn(),
77+
regenerateChatTitle: vi.fn(),
78+
getChatAdvisorConfig: vi.fn(),
79+
updateChatAdvisorConfig: vi.fn(),
80+
getChatACL: vi.fn(),
81+
updateChatACL: vi.fn(),
82+
listAIProviders: vi.fn(),
83+
},
8084
},
81-
},
82-
}));
85+
};
86+
});
8387

8488
type InfiniteChatsTestOptions = Parameters<typeof infiniteChatsKey>[0];
8589

0 commit comments

Comments
 (0)