Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package aiprovider
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/descrybe/descrybe-v2/apps/api/internal/platformsettings"
|
|
)
|
|
|
|
func TestResolvePlatformOpenAI_envOnly(t *testing.T) {
|
|
svc := &Service{
|
|
Env: EnvConfig{
|
|
OpenAIAPIKey: "sk-env-fallback",
|
|
OpenAIBaseURL: "https://api.openai.com/v1",
|
|
OpenAIModel: "gpt-4o-mini",
|
|
},
|
|
}
|
|
oi, err := svc.resolvePlatformOpenAI(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if oi.APIKey != "sk-env-fallback" || oi.Source != platformsettings.SourceEnv {
|
|
t.Fatalf("got key=%q source=%q", oi.APIKey, oi.Source)
|
|
}
|
|
ok, err := svc.platformConfigured(context.Background())
|
|
if err != nil || !ok {
|
|
t.Fatalf("configured=%v err=%v", ok, err)
|
|
}
|
|
}
|
|
|
|
func TestResolvePlatformOpenAI_unset(t *testing.T) {
|
|
svc := &Service{Env: EnvConfig{}}
|
|
oi, err := svc.resolvePlatformOpenAI(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if oi.APIKey != "" || oi.Source != platformsettings.SourceNone {
|
|
t.Fatalf("got key=%q source=%q", oi.APIKey, oi.Source)
|
|
}
|
|
ok, err := svc.platformConfigured(context.Background())
|
|
if err != nil || ok {
|
|
t.Fatalf("configured=%v err=%v", ok, err)
|
|
}
|
|
}
|
|
|
|
func TestResolvePlatformOpenAI_viaPlatformService(t *testing.T) {
|
|
plat := platformsettings.NewService(nil, platformsettings.EnvConfig{
|
|
OpenAIAPIKey: "sk-from-plat-env",
|
|
OpenAIBaseURL: "http://127.0.0.1:8767/v1",
|
|
OpenAIModel: "local-model",
|
|
})
|
|
svc := &Service{Platform: plat, Env: EnvConfig{OpenAIAPIKey: "sk-should-not-win"}}
|
|
oi, err := svc.resolvePlatformOpenAI(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if oi.APIKey != "sk-from-plat-env" {
|
|
t.Fatalf("key=%q", oi.APIKey)
|
|
}
|
|
if oi.Source != platformsettings.SourceEnv {
|
|
t.Fatalf("source=%q", oi.Source)
|
|
}
|
|
}
|