Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestApplyMonitorUpdate_ProviderOnlySwitchToGrokUsesDefaultModel(t *testing.T) {
|
||||
grok := MonitorProviderGrok
|
||||
existing := &ChannelMonitor{
|
||||
Provider: MonitorProviderOpenAI,
|
||||
APIMode: MonitorAPIModeResponses,
|
||||
Endpoint: "https://api.openai.com/v1",
|
||||
PrimaryModel: "gpt-5",
|
||||
IntervalSeconds: 60,
|
||||
}
|
||||
|
||||
err := applyMonitorUpdate(existing, ChannelMonitorUpdateParams{Provider: &grok})
|
||||
if err != nil {
|
||||
t.Fatalf("provider-only switch to Grok failed: %v", err)
|
||||
}
|
||||
if existing.PrimaryModel != MonitorDefaultGrokModel {
|
||||
t.Fatalf("expected Grok default model %q, got %q", MonitorDefaultGrokModel, existing.PrimaryModel)
|
||||
}
|
||||
if existing.APIMode != MonitorAPIModeChatCompletions {
|
||||
t.Fatalf("expected Grok API mode %q, got %q", MonitorAPIModeChatCompletions, existing.APIMode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyMonitorUpdate_SwitchToGrokPreservesExplicitModel(t *testing.T) {
|
||||
grok := MonitorProviderGrok
|
||||
explicitModel := "grok-4.3"
|
||||
existing := &ChannelMonitor{
|
||||
Provider: MonitorProviderOpenAI,
|
||||
APIMode: MonitorAPIModeChatCompletions,
|
||||
Endpoint: "https://api.openai.com/v1",
|
||||
PrimaryModel: "gpt-5",
|
||||
IntervalSeconds: 60,
|
||||
}
|
||||
|
||||
err := applyMonitorUpdate(existing, ChannelMonitorUpdateParams{
|
||||
Provider: &grok,
|
||||
PrimaryModel: &explicitModel,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("switch to Grok with explicit model failed: %v", err)
|
||||
}
|
||||
if existing.PrimaryModel != explicitModel {
|
||||
t.Fatalf("expected explicit model %q, got %q", explicitModel, existing.PrimaryModel)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyMonitorUpdate_SameGrokProviderDoesNotResetExistingModel(t *testing.T) {
|
||||
grok := MonitorProviderGrok
|
||||
existing := &ChannelMonitor{
|
||||
Provider: MonitorProviderGrok,
|
||||
APIMode: MonitorAPIModeChatCompletions,
|
||||
Endpoint: "https://api.x.ai",
|
||||
PrimaryModel: "grok-4.3",
|
||||
IntervalSeconds: 60,
|
||||
}
|
||||
|
||||
err := applyMonitorUpdate(existing, ChannelMonitorUpdateParams{Provider: &grok})
|
||||
if err != nil {
|
||||
t.Fatalf("same-provider Grok update failed: %v", err)
|
||||
}
|
||||
if existing.PrimaryModel != "grok-4.3" {
|
||||
t.Fatalf("same-provider update reset existing model to %q", existing.PrimaryModel)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyMonitorUpdate_SwitchToGrokRejectsResponsesMode(t *testing.T) {
|
||||
grok := MonitorProviderGrok
|
||||
responses := MonitorAPIModeResponses
|
||||
existing := &ChannelMonitor{
|
||||
Provider: MonitorProviderOpenAI,
|
||||
APIMode: MonitorAPIModeChatCompletions,
|
||||
PrimaryModel: "gpt-5",
|
||||
IntervalSeconds: 60,
|
||||
}
|
||||
|
||||
err := applyMonitorUpdate(existing, ChannelMonitorUpdateParams{
|
||||
Provider: &grok,
|
||||
APIMode: &responses,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("Grok responses mode should remain unsupported")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user