Align console behavior with operator routing and image workflow expectations

Constraint: Must preserve current exchange-rate logic, same-group routing boundary, and temporary image-file behavior while fixing UX-visible inconsistencies.
Rejected: Large frontend chunk refactor | introduced risky circular chunking and did not improve deliverability for this rollout.
Confidence: medium
Scope-risk: moderate
Directive: Keep channel failover constrained to the selected group and preserve Beijing-day semantics for user cache dashboard metrics.
Tested: go test ./controller ./model ./service ./common -count=1; npm run build; remote smoke on source deployment at http://38.76.218.56:18081/ plus /api/status and /api/image-studio/settings.
Not-tested: Browser-driven end-to-end verification of every console page interaction.
This commit is contained in:
ikmkj
2026-05-05 15:27:51 +08:00
parent 92ee465a41
commit 8ee89478a9
46 changed files with 1341 additions and 289 deletions

View File

@@ -0,0 +1,57 @@
package model
import (
"testing"
"github.com/QuantumNous/new-api/common"
)
func TestGetRandomSatisfiedChannelOrderedByPriorityThenWeight(t *testing.T) {
origMemoryCacheEnabled := common.MemoryCacheEnabled
origCacheEnabled := group2model2channels
origChannels := channelsIDM
defer func() {
common.MemoryCacheEnabled = origMemoryCacheEnabled
group2model2channels = origCacheEnabled
channelsIDM = origChannels
}()
common.MemoryCacheEnabled = true
group2model2channels = map[string]map[string][]int{
"image": {
"gpt-image-2": {1, 2, 3},
},
}
channelsIDM = map[int]*Channel{
1: {Id: 1, Priority: int64Ptr(10), Weight: uintPtr(50)},
2: {Id: 2, Priority: int64Ptr(10), Weight: uintPtr(20)},
3: {Id: 3, Priority: int64Ptr(5), Weight: uintPtr(99)},
}
first, err := GetRandomSatisfiedChannel("image", "gpt-image-2", 0)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if first == nil || first.Id != 1 {
t.Fatalf("expected first channel id 1, got %+v", first)
}
second, err := GetRandomSatisfiedChannel("image", "gpt-image-2", 1)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if second == nil || second.Id != 2 {
t.Fatalf("expected second channel id 2, got %+v", second)
}
third, err := GetRandomSatisfiedChannel("image", "gpt-image-2", 2)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if third == nil || third.Id != 3 {
t.Fatalf("expected third channel id 3, got %+v", third)
}
}
func int64Ptr(v int64) *int64 { return &v }
func uintPtr(v uint) *uint { return &v }