diff --git a/backend/internal/handler/openai_images_failover_test.go b/backend/internal/handler/openai_images_failover_test.go index 79392d31d1..40773eac43 100644 --- a/backend/internal/handler/openai_images_failover_test.go +++ b/backend/internal/handler/openai_images_failover_test.go @@ -148,6 +148,7 @@ func TestOpenAIGatewayHandlerImages_ServerErrorFailsOverAndReturnsClearErrorWhen nil, nil, nil, + nil, cfg, ) handler.maxAccountSwitches = 10 diff --git a/backend/internal/service/account_quota_reset_test.go b/backend/internal/service/account_quota_reset_test.go index fe0900c04e..233bdbe1ea 100644 --- a/backend/internal/service/account_quota_reset_test.go +++ b/backend/internal/service/account_quota_reset_test.go @@ -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)) } diff --git a/backend/internal/service/openai_quota_service.go b/backend/internal/service/openai_quota_service.go index 7d68d18386..1ca91b7a47 100644 --- a/backend/internal/service/openai_quota_service.go +++ b/backend/internal/service/openai_quota_service.go @@ -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 } } -