-
Notifications
You must be signed in to change notification settings - Fork 358
fix(admin): keep canonical-cased Claude identity headers on same-timezone saves #621
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
james-6-23
merged 1 commit into
james-6-23:main
from
ifThink404:fix/claude-timezone-header-case
Sep 4, 2026
+55
−3
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package admin | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/codex2api/database" | ||
| ) | ||
|
|
||
| // A Claude account whose stored identity headers use Go's canonical casing | ||
| // ("X-Stainless-Os") must survive a same-timezone save: the fresh fingerprint | ||
| // is keyed "X-Stainless-OS", and a case-insensitive clash with a different | ||
| // random OS used to fail the whole update with | ||
| // "custom_headers 包含大小写重复且值冲突的请求头: X-Stainless-Os". | ||
| func TestPrepareClaudeTimezoneUpdate_KeepsCanonicalCasedIdentityOnSameTimezone(t *testing.T) { | ||
| stored := map[string]string{ | ||
| "User-Agent": "claude-cli/2.1.259 (external, cli)", "X-App": "cli", | ||
| "X-Stainless-Arch": "x64", "X-Stainless-Lang": "js", "X-Stainless-Os": "Windows", | ||
| "X-Stainless-Package-Version": "0.65.0", "X-Stainless-Runtime": "node", "X-Stainless-Runtime-Version": "v20.18.1", | ||
| } | ||
| for i := 0; i < 30; i++ { // the generated OS is random; every save must succeed | ||
| headersAny := make(map[string]interface{}, len(stored)) | ||
| for k, v := range stored { | ||
| headersAny[k] = v | ||
| } | ||
| row := &database.AccountRow{Platform: "anthropic", Credentials: map[string]interface{}{ | ||
| "upstream_type": "claude", "timezone": "Asia/Shanghai", "custom_headers": headersAny, | ||
| }} | ||
| updates := map[string]interface{}{} | ||
| applied, err := prepareClaudeTimezoneCredentialUpdateWithHeaders(row, "Asia/Shanghai", updates, nil) | ||
| if err != nil { | ||
| t.Fatalf("iteration %d: %v", i, err) | ||
| } | ||
| if !applied { | ||
| t.Fatal("update must apply to a Claude row") | ||
| } | ||
| headers, _ := updates["custom_headers"].(map[string]string) | ||
| if headers["X-Stainless-Os"] != "Windows" { | ||
| t.Fatalf("iteration %d: stored identity must win on same timezone, got %v", i, headers) | ||
| } | ||
| if _, dup := headers["X-Stainless-OS"]; dup { | ||
| t.Fatalf("iteration %d: headers must be canonical-cased only, got %v", i, headers) | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: james-6-23/codex2api
Length of output: 11426
🏁 Script executed:
Repository: james-6-23/codex2api
Length of output: 50376
🤖 get_repo_knowledge executed:
get_repo_knowledge james-6-23/codex2api /tmp/coderabbit-repo-knowledge/james-6-23-codex2api-2f5e5157/architectureLength of output: 24829
🏁 Script executed:
Repository: james-6-23/codex2api
Length of output: 39445
🏁 Script executed:
Repository: james-6-23/codex2api
Length of output: 8514
Preserve duplicate-conflict validation before this merge.
GetCredentialStringMaptrims stored keys but does not canonicalize them. Line 290 then overwrites case variants inmergedbeforenormalizeCustomHeaderscan detect conflicting values. Validate collisions among retainedbaseHeadersfirst. Keep generated-versus-stored identity overwrites separate.🤖 Prompt for AI Agents