From 68cfd33685483fe9e50a4772fd9a2a0a1174b33f Mon Sep 17 00:00:00 2001 From: Finessse Date: Mon, 12 Jan 2026 02:05:01 +0700 Subject: [PATCH] refactor(auth): remove unused GeminiCLI token aliases - Remove dead code: GeminiCLIToken type alias, LoadGeminiCLIToken, LoadGeminiCLITokenFromPath (no callers found) - Add tests for gemini auth (CredentialFileName, SaveTokenToFile) --- internal/auth/antigravity/token.go | 16 ---- internal/auth/gemini/gemini_token_test.go | 106 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 internal/auth/gemini/gemini_token_test.go diff --git a/internal/auth/antigravity/token.go b/internal/auth/antigravity/token.go index 9b99c06e..2353cbf2 100644 --- a/internal/auth/antigravity/token.go +++ b/internal/auth/antigravity/token.go @@ -224,19 +224,3 @@ func LoadAntigravityTokenFromPath(path string) (*AntigravityToken, error) { return &token, nil } - -// Backwards compatibility aliases for existing code -// TODO: Remove these after updating all callers - -// GeminiCLIToken is an alias for AntigravityToken for backwards compatibility. -type GeminiCLIToken = AntigravityToken - -// LoadGeminiCLIToken is an alias for LoadAntigravityToken for backwards compatibility. -func LoadGeminiCLIToken() (*AntigravityToken, error) { - return LoadAntigravityToken() -} - -// LoadGeminiCLITokenFromPath is an alias for LoadAntigravityTokenFromPath for backwards compatibility. -func LoadGeminiCLITokenFromPath(path string) (*AntigravityToken, error) { - return LoadAntigravityTokenFromPath(path) -} diff --git a/internal/auth/gemini/gemini_token_test.go b/internal/auth/gemini/gemini_token_test.go new file mode 100644 index 00000000..af3af253 --- /dev/null +++ b/internal/auth/gemini/gemini_token_test.go @@ -0,0 +1,106 @@ +package gemini + +import ( + "os" + "path/filepath" + "testing" +) + +func TestCredentialFileName(t *testing.T) { + tests := []struct { + name string + email string + projectID string + includePrefix bool + want string + }{ + { + name: "single project without prefix", + email: "user@example.com", + projectID: "my-project-123", + includePrefix: false, + want: "user@example.com-my-project-123.json", + }, + { + name: "single project with prefix", + email: "user@example.com", + projectID: "my-project-123", + includePrefix: true, + want: "gemini-user@example.com-my-project-123.json", + }, + { + name: "all projects literal", + email: "user@example.com", + projectID: "all", + includePrefix: false, + want: "gemini-user@example.com-all.json", + }, + { + name: "all projects uppercase", + email: "user@example.com", + projectID: "ALL", + includePrefix: true, + want: "gemini-user@example.com-all.json", + }, + { + name: "comma-separated projects", + email: "user@example.com", + projectID: "project-1,project-2,project-3", + includePrefix: false, + want: "gemini-user@example.com-all.json", + }, + { + name: "whitespace trimmed", + email: " user@example.com ", + projectID: " my-project ", + includePrefix: true, + want: "gemini-user@example.com-my-project.json", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := CredentialFileName(tt.email, tt.projectID, tt.includePrefix) + if got != tt.want { + t.Errorf("CredentialFileName() = %q, want %q", got, tt.want) + } + }) + } +} + +func TestGeminiTokenStorage_SaveTokenToFile(t *testing.T) { + tmpDir := t.TempDir() + authPath := filepath.Join(tmpDir, "subdir", "token.json") + + ts := &GeminiTokenStorage{ + Token: map[string]string{"access_token": "test-token"}, + ProjectID: "test-project", + Email: "test@example.com", + Auto: true, + Checked: true, + } + + err := ts.SaveTokenToFile(authPath) + if err != nil { + t.Fatalf("SaveTokenToFile() error = %v", err) + } + + // Verify file exists + if _, err := os.Stat(authPath); os.IsNotExist(err) { + t.Fatal("token file was not created") + } + + // Verify type was set + if ts.Type != "gemini" { + t.Errorf("Type = %q, want %q", ts.Type, "gemini") + } + + // Verify content is valid JSON + data, err := os.ReadFile(authPath) + if err != nil { + t.Fatalf("failed to read token file: %v", err) + } + if len(data) == 0 { + t.Fatal("token file is empty") + } +}