mirror of
https://github.com/coder/coder.git
synced 2026-11-02 21:50:08 +08:00
## Description Separates the aibridge provider configuration from the per-request configuration an interceptor actually needs, and introduces a single `Credential` type that each provider resolves per request. Previously a provider handed its full config to the interceptor (including fields the interceptor didn't use) while other request data was passed as loose arguments, and authentication was spread across config fields and arguments. ## Changes - Add `intercept.Config`: the per-request, provider-agnostic configuration an interceptor needs (`ProviderName`, `BaseURL`, `APIDumpDir`, `SendActorHeaders`). - Introduce a single `Credential` interface (`BYOK` and `Centralized`) that each provider resolves per request in `resolveCredential`, and have interceptors route on the credential kind. - Fail fast with `ErrNoCredential` when a request is neither BYOK nor backed by a centralized key pool. - Remove unused provider config fields (`Key`, `BYOKBearerToken`, `ExtraHeaders`). Closes: coder/aibridge#266 Closes: https://linear.app/codercom/issue/AIGOV-221/refactor-separate-provider-and-interceptor-configs > [!NOTE] > Initially generated by Claude Opus 4.7, modified and reviewed by @ssncferreira
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package integrationtest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"cdr.dev/slog/v3"
|
|
"cdr.dev/slog/v3/sloggers/slogtest"
|
|
"github.com/coder/coder/v2/aibridge/config"
|
|
"github.com/coder/coder/v2/aibridge/internal/testutil"
|
|
"github.com/coder/coder/v2/aibridge/recorder"
|
|
)
|
|
|
|
// anthropicCfg creates a minimal Anthropic config for testing.
|
|
func anthropicCfg(url string, key string) config.Anthropic {
|
|
return config.Anthropic{
|
|
BaseURL: url,
|
|
KeyPool: testutil.SingleKeyPool(config.ProviderAnthropic, key),
|
|
}
|
|
}
|
|
|
|
func anthropicCfgWithAPIDump(url string, key string, dumpDir string) config.Anthropic {
|
|
cfg := anthropicCfg(url, key)
|
|
cfg.APIDumpDir = dumpDir
|
|
return cfg
|
|
}
|
|
|
|
// bedrockCfg returns a test AWS Bedrock config pointing at the given URL.
|
|
func bedrockCfg(url string) *config.AWSBedrock {
|
|
return &config.AWSBedrock{
|
|
Region: "us-west-2",
|
|
AccessKey: "test-access-key",
|
|
AccessKeySecret: "test-secret-key",
|
|
Model: "beddel", // This model should override the request's given one.
|
|
SmallFastModel: "modrock", // Unused but needed for validation.
|
|
BaseURL: url,
|
|
}
|
|
}
|
|
|
|
// openAICfg creates a minimal OpenAI config for testing.
|
|
func openAICfg(url string, key string) config.OpenAI {
|
|
return config.OpenAI{
|
|
BaseURL: url,
|
|
KeyPool: testutil.SingleKeyPool(config.ProviderOpenAI, key),
|
|
}
|
|
}
|
|
|
|
func openaiCfgWithAPIDump(url string, key string, dumpDir string) config.OpenAI {
|
|
cfg := openAICfg(url, key)
|
|
cfg.APIDumpDir = dumpDir
|
|
return cfg
|
|
}
|
|
|
|
// newLogger creates a test logger at Debug level.
|
|
func newLogger(t *testing.T) slog.Logger {
|
|
t.Helper()
|
|
return slogtest.Make(t, &slogtest.Options{}).Leveled(slog.LevelDebug)
|
|
}
|
|
|
|
func newModelThought(content, source string) recorder.ModelThoughtRecord {
|
|
return recorder.ModelThoughtRecord{
|
|
Content: content,
|
|
Metadata: recorder.Metadata{
|
|
"source": source,
|
|
},
|
|
}
|
|
}
|