mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-21 14:19:18 +08:00
fix(ci): unblock main after recent merges
Three independent CI blockers landed on main from concurrent PR merges: - openai_quota_service.go (introduced byb8169492): const block spacing not gofmt-compliant + trailing blank line. golangci-lint v2.9 flagged it on every push after the merge. - openai_images_failover_test.go (introduced by PR #3155,da30c599): NewOpenAIGatewayHandler call missing the opsService argument added by PR #3230 (b62b573f). Test was authored before #3230 and merged without rebase, causing "not enough arguments" compile error. - account_quota_reset_test.go: TestIsFixedDailyPeriodExpired_NotExpired and TestIsFixedWeeklyPeriodExpired_NotExpired used time.Now()-1min as periodStart, which crosses the 09:00 UTC reset boundary when CI runs in the 09:00:00-09:00:59 window. Anchoring periodStart to today's 12:00 UTC removes the race.
This commit is contained in:
@@ -148,6 +148,7 @@ func TestOpenAIGatewayHandlerImages_ServerErrorFailsOverAndReturnsClearErrorWhen
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
cfg,
|
||||
)
|
||||
handler.maxAccountSwitches = 10
|
||||
|
||||
@@ -210,9 +210,11 @@ func TestIsFixedDailyPeriodExpired_NotExpired(t *testing.T) {
|
||||
"quota_daily_reset_hour": float64(9),
|
||||
"quota_reset_timezone": "UTC",
|
||||
}}
|
||||
// Period started after the most recent reset → not expired
|
||||
// (This test uses a time very close to "now", which is after the last reset)
|
||||
periodStart := time.Now().Add(-1 * time.Minute)
|
||||
// Anchor periodStart to today's 12:00 UTC: always strictly after today's
|
||||
// 09:00 UTC reset (and yesterday's). Using time.Now().Add(-1*time.Minute)
|
||||
// is flaky inside the 09:00-09:01 UTC reset window.
|
||||
now := time.Now().UTC()
|
||||
periodStart := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, time.UTC)
|
||||
assert.False(t, a.isFixedDailyPeriodExpired(periodStart))
|
||||
}
|
||||
|
||||
@@ -259,8 +261,12 @@ func TestIsFixedWeeklyPeriodExpired_NotExpired(t *testing.T) {
|
||||
"quota_weekly_reset_hour": float64(9),
|
||||
"quota_reset_timezone": "UTC",
|
||||
}}
|
||||
// Period started 1 minute ago → not expired
|
||||
periodStart := time.Now().Add(-1 * time.Minute)
|
||||
// Anchor periodStart to today's 12:00 UTC: always strictly after the most
|
||||
// recent Monday 09:00 UTC reset, regardless of which weekday/hour the test
|
||||
// runs. Using time.Now().Add(-1*time.Minute) is flaky inside the
|
||||
// Monday 09:00-09:01 UTC reset window.
|
||||
now := time.Now().UTC()
|
||||
periodStart := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, time.UTC)
|
||||
assert.False(t, a.isFixedWeeklyPeriodExpired(periodStart))
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ import (
|
||||
|
||||
// Endpoints used by the OpenAI/ChatGPT/Codex quota query and reset feature.
|
||||
const (
|
||||
chatGPTUsageURL = "https://chatgpt.com/backend-api/wham/usage"
|
||||
chatGPTRateLimitResetURL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits/consume"
|
||||
openaiQuotaUpstreamTimeout = 20 * time.Second
|
||||
openaiQuotaCodexOriginator = "Codex Desktop"
|
||||
openaiQuotaCodexLanguageTag = "zh-CN"
|
||||
openaiQuotaSecFetchSite = "none"
|
||||
openaiQuotaSecFetchMode = "no-cors"
|
||||
openaiQuotaSecFetchDest = "empty"
|
||||
chatGPTUsageURL = "https://chatgpt.com/backend-api/wham/usage"
|
||||
chatGPTRateLimitResetURL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits/consume"
|
||||
openaiQuotaUpstreamTimeout = 20 * time.Second
|
||||
openaiQuotaCodexOriginator = "Codex Desktop"
|
||||
openaiQuotaCodexLanguageTag = "zh-CN"
|
||||
openaiQuotaSecFetchSite = "none"
|
||||
openaiQuotaSecFetchMode = "no-cors"
|
||||
openaiQuotaSecFetchDest = "empty"
|
||||
)
|
||||
|
||||
// OpenAIRateLimitWindow describes a single rate-limit window returned by
|
||||
@@ -311,4 +311,3 @@ func mapUpstreamStatus(status int) int {
|
||||
return http.StatusBadGateway
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user