mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
fix: prevent Basic/Auto accounts from being promoted to Super when rate-limit endpoints are unavailable
When both auto and fast mode rate-limit endpoints fail but weekly credits succeed, resolveWebTierFromQuota unconditionally returned WebTierSuper for any non-Heavy account. This incorrectly elevated free Basic accounts to Super tier, granting access to premium models (expert, auto) they should not have. Preserve the stored tier for already-confirmed Heavy/Super accounts, and keep the current tier (Basic or Auto) unchanged for unconfirmed accounts — weekly credits alone cannot prove a paid subscription.
This commit is contained in:
1 parent
b0446afe35
commit
56fa0a968e
2 files changed
+20
-5
No files matched your search
@@ -57,12 +57,12 @@ func resolveWebTierFromQuota(current account.WebTier, windows []account.QuotaWin
|
||||
}
|
||||
return tier, weeklyAvailable && tier != account.WebTierBasic
|
||||
}
|
||||
// 周额度是付费账号信号,但无法区分 Super/Heavy。只有已确认的 Heavy
|
||||
// 可以在模式额度暂时不可用时保留,其余账号只授予最低付费等级。
|
||||
if current == account.WebTierHeavy {
|
||||
return account.WebTierHeavy, weeklyAvailable
|
||||
// 周额度是付费账号信号,但无法区分 Super/Heavy。已确认的等级在模式
|
||||
// 额度暂时不可用时保留;未确认(Auto/Basic)的不能凭周额度提权。
|
||||
if current == account.WebTierHeavy || current == account.WebTierSuper {
|
||||
return current, weeklyAvailable
|
||||
}
|
||||
return account.WebTierSuper, weeklyAvailable
|
||||
return current, false
|
||||
}
|
||||
|
||||
// inferWebTierFromQuota 使用 Grok Web /rest/rate-limits 的真实额度形态判级。
|
||||
|
||||
@@ -85,6 +85,21 @@ func TestResolveWebTierUsesFreshWebQuotaOverStoredTier(t *testing.T) {
|
||||
if tier != account.WebTierAuto || useWeekly {
|
||||
t.Fatalf("unknown snapshot resolved to %q, weekly=%v", tier, useWeekly)
|
||||
}
|
||||
|
||||
tier, useWeekly = resolveWebTierFromQuota(account.WebTierSuper, nil, true)
|
||||
if tier != account.WebTierSuper || !useWeekly {
|
||||
t.Fatalf("super weekly fallback resolved to %q, weekly=%v", tier, useWeekly)
|
||||
}
|
||||
|
||||
tier, useWeekly = resolveWebTierFromQuota(account.WebTierBasic, nil, true)
|
||||
if tier != account.WebTierBasic || useWeekly {
|
||||
t.Fatalf("basic should not be promoted when modes unavailable: got %q, weekly=%v", tier, useWeekly)
|
||||
}
|
||||
|
||||
tier, useWeekly = resolveWebTierFromQuota(account.WebTierAuto, nil, true)
|
||||
if tier != account.WebTierAuto || useWeekly {
|
||||
t.Fatalf("auto should not be promoted when modes unavailable: got %q, weekly=%v", tier, useWeekly)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncQuotaCorrectsStoredSuperFromFreshWebQuota(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user