mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-15 23:22:59 +08:00
Grok 分组里若有账号的自定义 base_url 只实现 /v1/chat/completions,对 /v1/responses 固定返回 405,会话 sticky 到该账号后就永久锁死: 1. shouldFailoverUpstreamError 不含 405,请求不进换号循环 2. handleGrokAccountUpstreamError 的 switch 不含 405,账号不进临时不可调度 3. 账号仍可调度,sticky 不清理,客户端自动重连继续绑同一个坏号 改动两处: - shouldFailoverUpstreamError 增加 405,让请求可换号,sticky 随之更新 - handleGrokAccountUpstreamError 增加 405 → 30 分钟冷却,与 403 同级 Fixes #4668
30 lines
894 B
Go
30 lines
894 B
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestShouldFailoverUpstreamError_405IsFailoverEligible(t *testing.T) {
|
|
svc := &OpenAIGatewayService{}
|
|
|
|
assert.True(t, svc.shouldFailoverUpstreamError(http.StatusMethodNotAllowed),
|
|
"405 should trigger failover so sticky sessions can escape to healthy accounts")
|
|
}
|
|
|
|
func TestShouldFailoverUpstreamError_ExistingCodesStillWork(t *testing.T) {
|
|
svc := &OpenAIGatewayService{}
|
|
|
|
failoverCodes := []int{401, 402, 403, 405, 429, 529, 500, 502, 503, 504}
|
|
for _, code := range failoverCodes {
|
|
assert.True(t, svc.shouldFailoverUpstreamError(code), "status %d should trigger failover", code)
|
|
}
|
|
|
|
nonFailoverCodes := []int{200, 201, 400, 404, 408, 422}
|
|
for _, code := range nonFailoverCodes {
|
|
assert.False(t, svc.shouldFailoverUpstreamError(code), "status %d should NOT trigger failover", code)
|
|
}
|
|
}
|