fix(antigravity): isolate OAuth token cache key by account ID to prevent collision

This commit is contained in:
郭兰鑫
2026-09-13 03:40:47 +08:00
parent bdb42e22f8
commit bc8da78150
2 changed files with 13 additions and 32 deletions
@@ -231,9 +231,5 @@ func (p *AntigravityTokenProvider) markBackfillAttempted(accountID int64) {
}
func AntigravityTokenCacheKey(account *Account) string {
projectID := strings.TrimSpace(account.GetCredential("project_id"))
if projectID != "" {
return "ag:" + projectID
}
return "ag:account:" + strconv.FormatInt(account.ID, 10)
}
@@ -87,60 +87,45 @@ func TestAntigravityTokenCacheKey(t *testing.T) {
expected string
}{
{
name: "with_project_id",
name: "basic_account",
account: &Account{
ID: 200,
Credentials: map[string]any{
"project_id": "ag-project-456",
},
},
expected: "ag:ag-project-456",
expected: "ag:account:200",
},
{
name: "project_id_with_whitespace",
name: "account_with_project_id_still_uses_account_id",
account: &Account{
ID: 201,
Credentials: map[string]any{
"project_id": " ag-project-spaces ",
"project_id": "aicode-consumers",
},
},
expected: "ag:ag-project-spaces",
expected: "ag:account:201",
},
{
name: "empty_project_id_fallback_to_account_id",
name: "account_with_credentials",
account: &Account{
ID: 202,
Credentials: map[string]any{
"project_id": "",
"access_token": "test-token",
},
},
expected: "ag:account:202",
},
{
name: "whitespace_only_project_id_fallback_to_account_id",
name: "account_id_zero",
account: &Account{
ID: 203,
Credentials: map[string]any{
"project_id": " ",
},
ID: 0,
},
expected: "ag:account:203",
expected: "ag:account:0",
},
{
name: "no_project_id_key_fallback_to_account_id",
name: "large_account_id",
account: &Account{
ID: 204,
Credentials: map[string]any{},
ID: 9999999999,
},
expected: "ag:account:204",
},
{
name: "nil_credentials_fallback_to_account_id",
account: &Account{
ID: 205,
Credentials: nil,
},
expected: "ag:account:205",
expected: "ag:account:9999999999",
},
}