From d2b041e848712a53cebe2313a13ba5944be7d941 Mon Sep 17 00:00:00 2001 From: anupamchugh <8416306+anupamchugh@users.noreply.github.com> Date: Sun, 23 Aug 2026 17:13:22 +0530 Subject: [PATCH] Preserve unknown Grok period usage --- .../Providers/Grok/GrokCreditsProxyFetcher.swift | 2 +- Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift | 10 +++++----- docs/grok.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift b/Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift index 74ce605f5a..25c5204778 100644 --- a/Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift +++ b/Sources/CodexBarCore/Providers/Grok/GrokCreditsProxyFetcher.swift @@ -80,7 +80,7 @@ public enum GrokCreditsProxyFetcher { if resetsAt != nil { return GrokWebBillingSnapshot( - usedPercent: 0, + usedPercent: nil, resetsAt: resetsAt, subscriptionTier: subscriptionTier) } diff --git a/Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift b/Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift index af7098a513..d188900f76 100644 --- a/Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift +++ b/Tests/CodexBarTests/GrokCreditsProxyFetcherTests.swift @@ -96,7 +96,7 @@ struct GrokCreditsProxyFetcherTests { } @Test - func `treats a period without usage as zero percent`() throws { + func `treats a period without usage as unknown`() throws { let snapshot = try GrokCreditsProxyFetcher.parseSnapshot( Data( """ @@ -109,7 +109,7 @@ struct GrokCreditsProxyFetcherTests { """.utf8)) let expectedReset = try Self.date("2026-08-13T00:00:00.123Z") - #expect(snapshot.usedPercent == 0) + #expect(snapshot.usedPercent == nil) #expect(snapshot.resetsAt == expectedReset) #expect(snapshot.subscriptionTier == nil) } @@ -134,7 +134,7 @@ struct GrokCreditsProxyFetcherTests { let expectedReset = try Self.date("2026-08-23T18:42:45.537749+00:00") #expect(snapshot.subscriptionTier == "SuperGrok Heavy") - #expect(snapshot.usedPercent == 0) + #expect(snapshot.usedPercent == nil) #expect(snapshot.resetsAt == expectedReset) } @@ -184,7 +184,7 @@ struct GrokCreditsProxyFetcherTests { """.utf8)) let expectedReset = try Self.date("2026-08-13T00:00:00Z") - #expect(snapshot.usedPercent == 0) + #expect(snapshot.usedPercent == nil) #expect(snapshot.subscriptionTier == "SuperGrok Heavy") #expect(snapshot.resetsAt == expectedReset) } @@ -231,7 +231,7 @@ struct GrokCreditsProxyFetcherTests { """.utf8)) let expectedReset = try Self.date("2026-08-13T00:00:00Z") - #expect(snapshot.usedPercent == 0) + #expect(snapshot.usedPercent == nil) #expect(snapshot.resetsAt == expectedReset) } diff --git a/docs/grok.md b/docs/grok.md index 348d1c8186..7c24d28a94 100644 --- a/docs/grok.md +++ b/docs/grok.md @@ -55,7 +55,7 @@ The grok.com billing gRPC-web endpoint remains a best-effort fallback. `Accept: application/json`. - Reads `config.creditUsagePercent`, falling back to `onDemandUsed.val / onDemandCap.val * 100`. A parseable current period - without either value represents zero usage. The reset timestamp comes from + without either value represents unknown usage. The reset timestamp comes from `config.currentPeriod.end`, then `config.billingPeriodEnd`. - Plan name does not come from the credits payload. After a successful auth-file or SuperGrok OAuth web billing result (CLI-proxy) or the team