fix: 修复 CI 检查失败
- gofmt: 修复 error_passthrough_service.go 格式问题 - errcheck: 修复 error_passthrough_runtime_test.go 类型断言未检查 - staticcheck: if-else 改为 switch (gateway_service.go) - test: 修复两个测试用例错误使用 MODEL_CAPACITY_EXHAUSTED 导致走错路径
This commit is contained in:
@@ -153,13 +153,14 @@ func TestHandleSmartRetry_503_LongDelay_NoSingleAccountRetry_StillSwitches(t *te
|
|||||||
Platform: PlatformAntigravity,
|
Platform: PlatformAntigravity,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 503 + 39s >= 7s 阈值
|
// 503 + 39s >= 7s 阈值(使用 RATE_LIMIT_EXCEEDED 而非 MODEL_CAPACITY_EXHAUSTED,
|
||||||
|
// 因为 MODEL_CAPACITY_EXHAUSTED 走独立的重试路径,不触发 shouldRateLimitModel)
|
||||||
respBody := []byte(`{
|
respBody := []byte(`{
|
||||||
"error": {
|
"error": {
|
||||||
"code": 503,
|
"code": 503,
|
||||||
"status": "UNAVAILABLE",
|
"status": "RESOURCE_EXHAUSTED",
|
||||||
"details": [
|
"details": [
|
||||||
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-pro-high"}, "reason": "MODEL_CAPACITY_EXHAUSTED"},
|
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-pro-high"}, "reason": "RATE_LIMIT_EXCEEDED"},
|
||||||
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "39s"}
|
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "39s"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -339,13 +340,14 @@ func TestHandleSmartRetry_503_ShortDelay_SingleAccountRetry_NoRateLimit(t *testi
|
|||||||
|
|
||||||
// TestHandleSmartRetry_503_ShortDelay_NoSingleAccountRetry_SetsRateLimit
|
// TestHandleSmartRetry_503_ShortDelay_NoSingleAccountRetry_SetsRateLimit
|
||||||
// 对照组:503 + retryDelay < 7s + 无 SingleAccountRetry → 智能重试耗尽后照常设限流
|
// 对照组:503 + retryDelay < 7s + 无 SingleAccountRetry → 智能重试耗尽后照常设限流
|
||||||
|
// 使用 RATE_LIMIT_EXCEEDED 而非 MODEL_CAPACITY_EXHAUSTED,因为后者走独立的 60 次重试路径
|
||||||
func TestHandleSmartRetry_503_ShortDelay_NoSingleAccountRetry_SetsRateLimit(t *testing.T) {
|
func TestHandleSmartRetry_503_ShortDelay_NoSingleAccountRetry_SetsRateLimit(t *testing.T) {
|
||||||
failRespBody := `{
|
failRespBody := `{
|
||||||
"error": {
|
"error": {
|
||||||
"code": 503,
|
"code": 503,
|
||||||
"status": "UNAVAILABLE",
|
"status": "RESOURCE_EXHAUSTED",
|
||||||
"details": [
|
"details": [
|
||||||
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-flash"}, "reason": "MODEL_CAPACITY_EXHAUSTED"},
|
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-flash"}, "reason": "RATE_LIMIT_EXCEEDED"},
|
||||||
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "0.1s"}
|
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "0.1s"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -371,9 +373,9 @@ func TestHandleSmartRetry_503_ShortDelay_NoSingleAccountRetry_SetsRateLimit(t *t
|
|||||||
respBody := []byte(`{
|
respBody := []byte(`{
|
||||||
"error": {
|
"error": {
|
||||||
"code": 503,
|
"code": 503,
|
||||||
"status": "UNAVAILABLE",
|
"status": "RESOURCE_EXHAUSTED",
|
||||||
"details": [
|
"details": [
|
||||||
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-flash"}, "reason": "MODEL_CAPACITY_EXHAUSTED"},
|
{"@type": "type.googleapis.com/google.rpc.ErrorInfo", "metadata": {"model": "gemini-3-flash"}, "reason": "RATE_LIMIT_EXCEEDED"},
|
||||||
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "0.1s"}
|
{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "0.1s"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,7 +219,9 @@ func TestApplyErrorPassthroughRule_SkipMonitoringSetsContextKey(t *testing.T) {
|
|||||||
assert.True(t, matched)
|
assert.True(t, matched)
|
||||||
v, exists := c.Get(OpsSkipPassthroughKey)
|
v, exists := c.Get(OpsSkipPassthroughKey)
|
||||||
assert.True(t, exists, "OpsSkipPassthroughKey should be set when skip_monitoring=true")
|
assert.True(t, exists, "OpsSkipPassthroughKey should be set when skip_monitoring=true")
|
||||||
assert.True(t, v.(bool))
|
boolVal, ok := v.(bool)
|
||||||
|
assert.True(t, ok, "value should be bool")
|
||||||
|
assert.True(t, boolVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApplyErrorPassthroughRule_NoSkipMonitoringDoesNotSetContextKey(t *testing.T) {
|
func TestApplyErrorPassthroughRule_NoSkipMonitoringDoesNotSetContextKey(t *testing.T) {
|
||||||
|
|||||||
@@ -385,9 +385,10 @@ func (s *GatewayService) TempUnscheduleRetryableError(ctx context.Context, accou
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 根据状态码选择封禁策略
|
// 根据状态码选择封禁策略
|
||||||
if failoverErr.StatusCode == http.StatusBadRequest {
|
switch failoverErr.StatusCode {
|
||||||
|
case http.StatusBadRequest:
|
||||||
tempUnscheduleGoogleConfigError(ctx, s.accountRepo, accountID, "[handler]")
|
tempUnscheduleGoogleConfigError(ctx, s.accountRepo, accountID, "[handler]")
|
||||||
} else if failoverErr.StatusCode == http.StatusBadGateway {
|
case http.StatusBadGateway:
|
||||||
tempUnscheduleEmptyResponse(ctx, s.accountRepo, accountID, "[handler]")
|
tempUnscheduleEmptyResponse(ctx, s.accountRepo, accountID, "[handler]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user