-
Notifications
You must be signed in to change notification settings - Fork 0
FEAT: add Resets view and earliest-expiry redemption #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8012a37
FEAT: add reset inventory and expiry-aware redemption
merefield 5a652b3
FEAT: separate expiry warning navigation and configure lead time
merefield f1ce3bb
FIX: clarify reset trade-offs and incomplete expiry information
merefield 7a3e7f3
FIX: preserve unknown reset expiry and localise warnings
merefield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package codex | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestDecodeResetCreditDetails(t *testing.T) { | ||
| var snapshot Snapshot | ||
| err := json.Unmarshal([]byte(`{"rateLimitResetCredits":{"availableCount":3,"credits":[{"id":"expiring","resetType":"codexRateLimits","status":"available","grantedAt":1700000000,"expiresAt":1800000000,"title":"Weekly reset","description":"Refresh eligible limits"},{"id":"forever","resetType":"codexRateLimits","status":"available","expiresAt":null}]}}`), &snapshot) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| summary := snapshot.RateLimitResetCredits | ||
| if summary == nil || summary.AvailableCount != 3 || len(summary.Credits) != 2 { | ||
| t.Fatalf("partial inventory: %#v", summary) | ||
| } | ||
| first := summary.Credits[0] | ||
| if first.ID != "expiring" || first.ExpiresAt == nil || *first.ExpiresAt != 1800000000 || first.GrantedAt != 1700000000 || first.Title != "Weekly reset" || first.Description == "" { | ||
| t.Fatalf("lost detail: %#v", first) | ||
| } | ||
| if summary.Credits[1].ExpiresAt != nil { | ||
| t.Fatal("invented non-expiring date") | ||
| } | ||
| var countOnly ResetCredits | ||
| err = json.Unmarshal([]byte(`{"availableCount":2}`), &countOnly) | ||
| if err != nil || countOnly.AvailableCount != 2 || countOnly.Credits != nil { | ||
| t.Fatal("count-only compatibility lost") | ||
| } | ||
| } | ||
|
|
||
| func TestResetCreditExpiryPresenceRoundTrip(t *testing.T) { | ||
| for _, input := range []string{`{"id":"credit"}`, `{"id":"credit","expiresAt":null}`, `{"id":"credit","expiresAt":1800000000}`} { | ||
| var raw map[string]json.RawMessage | ||
| if err := json.Unmarshal([]byte(input), &raw); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| var credit ResetCredit | ||
| // Decode again into an existing value to catch retained presence flags. | ||
| for range 2 { | ||
| if err := json.Unmarshal([]byte(input), &credit); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| _, present := raw["expiresAt"] | ||
| if credit.HasKnownExpiry() != present { | ||
| t.Fatalf("%s: wrong presence", input) | ||
| } | ||
| encoded, err := json.Marshal(credit) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| var output map[string]json.RawMessage | ||
| if err := json.Unmarshal(encoded, &output); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if string(output["expiresAt"]) != string(raw["expiresAt"]) { | ||
| t.Fatalf("%s round trip became %s", input, encoded) | ||
| } | ||
| if err := json.Unmarshal([]byte(`{"expiresAt":123}`), &credit); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
| var credit ResetCredit | ||
| if err := json.Unmarshal([]byte(`{"expiresAt":"invalid"}`), &credit); err == nil { | ||
| t.Fatal("accepted malformed expiry") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.