Skip to content

refactor(providers): rename googleauth to googlecommon and dedup Vertex URL helpers#328

Merged
SantiagoDePolonia merged 1 commit into
mainfrom
refactor/googlecommon-dedup
May 12, 2026
Merged

refactor(providers): rename googleauth to googlecommon and dedup Vertex URL helpers#328
SantiagoDePolonia merged 1 commit into
mainfrom
refactor/googlecommon-dedup

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented May 12, 2026

Summary

The googleauth package had outgrown its name. After the recent quota-project work (#325) it already held HTTP transport concerns (X-Goog-User-Project injection) that aren't strictly about auth. And the existing TODO at vertex/vertex.go:350 noted that Vertex's URL transformation helpers were copy-pasted into both vertex/vertex.go and gemini/gemini.go — byte-identical code waiting for a shared home (MD5-verified before changes).

This PR:

  • Renames internal/providers/googleauthinternal/providers/googlecommon, files googleauth.goauth.go to match.
  • Extracts the three Vertex URL helpers (VertexBaseURLs, VertexNativeBaseURLFromOpenAICompatibleBaseURL, VertexOpenAICompatibleBaseURLFromNativeBaseURL) into googlecommon/urls.go, exported. The signatures take plain strings rather than the provider config struct so the helpers stay pure and avoid a cross-package type dependency.
  • Removes the duplicated function definitions from vertex/vertex.go and gemini/gemini.go, plus the TODO that flagged the duplication.
  • Drops the dead TokenSource public function from auth.go. An audit showed zero external callers — both providers migrated to FindCredentials after the quota-project change.

Audit before renaming

Confirmed every truly-shared symbol in the old googleauth is used by both providers, so the rename to googlecommon is justified:

Symbol vertex gemini Verdict
Config shared
Credentials (via field access) shared
NormalizeAuthType shared
HasServiceAccount shared
FindCredentials shared
HTTPClient shared
TokenSource dead — removed in this PR

Out of scope (follow-up candidate)

hasResolvedProviderValue is still defined three times (providers/config.go, vertex/vertex.go, gemini/gemini.go). It's a generic ${VAR}-placeholder check that doesn't fit a GCP-specific package — deferring to a follow-up that picks a generic config-helper home for it.

Risk

  • Rename touches 4 caller files (vertex/gemini × prod+test). Mechanical perl replace of import path + package qualifier. Anyone with external code referencing gomodel/internal/providers/googleauth must update; since this is an internal/ package, that should be rare.
  • VertexBaseURLs signature changed from (providers.ProviderConfig) to (baseURL, project, location string). Pure refactor; the only callers (in this repo) are updated in the same PR.
  • TokenSource removed. The function had zero external callers — verified via grep across the whole repo before deletion. The package's own test that exercised the auth path was rewritten to use FindCredentials (which has always been the modern entry point).

Test plan

  • make test-race, make lint, go mod tidy — all green via pre-commit hooks.
  • Full go test ./... clean across the module.
  • Existing TestVertexBaseURLs test (now calling the exported googlecommon.VertexBaseURLs) still passes with all 5 table cases.

Net diff: -90 lines (29 inserted, 119 removed) across 7 files.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Consolidated shared Google authentication utilities across providers, improving code organization and reducing duplication. Authentication credential resolution and endpoint configuration now use centralized helpers for consistency across Gemini and Vertex AI providers.

Review Change Stack

…ex URL helpers

The googleauth package had outgrown its name. After the recent quota-project
work it already held HTTP transport concerns (X-Goog-User-Project injection)
that aren't strictly about auth. And there was an existing TODO at
vertex/vertex.go:350 noting that Vertex's URL transformation helpers were
copy-pasted into both vertex/vertex.go and gemini/gemini.go — three files'
worth of byte-identical code waiting for a shared home.

This PR:
- Renames internal/providers/googleauth → internal/providers/googlecommon,
  files googleauth.go → auth.go to match. Updated import paths and package
  qualifiers in vertex/ and gemini/ (the only callers).
- Extracts the three Vertex URL helpers (VertexBaseURLs,
  VertexNativeBaseURLFromOpenAICompatibleBaseURL,
  VertexOpenAICompatibleBaseURLFromNativeBaseURL) into
  googlecommon/urls.go, exported. The signatures take plain strings rather
  than the provider config struct so the helpers stay pure and avoid a
  cross-package type dependency. Callers in vertex.go and gemini.go now call
  googlecommon.VertexBaseURLs(cfg.BaseURL, cfg.VertexProject, cfg.VertexLocation).
- Removes the duplicated function definitions from vertex/vertex.go and
  gemini/gemini.go, plus the TODO that flagged the duplication.
- Drops the dead `TokenSource` public function from auth.go. An audit showed
  zero external callers — both providers migrated to FindCredentials after
  the quota-project change.

Audit of remaining googlecommon exports (every one is shared by both
providers, confirming the package name fits):

  Config            vertex + gemini
  Credentials       vertex + gemini (via field access)
  NormalizeAuthType vertex + gemini
  HasServiceAccount vertex + gemini
  FindCredentials   vertex + gemini
  HTTPClient        vertex + gemini

Out of scope: hasResolvedProviderValue is still triple-defined (providers/config.go,
vertex/vertex.go, gemini/gemini.go). It's a generic ${VAR}-placeholder check
that doesn't fit a GCP-specific package; deferring to a follow-up.

Test plan: full `go test ./...` clean, including the three new VertexBaseURLs
tests already present in vertex_test.go. Pre-commit hooks (test-race, lint,
mod-tidy) pass. Net diff: -90 lines (29 added, 119 removed).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7fe283b6-0294-4845-a9ef-cb7124f97a33

📥 Commits

Reviewing files that changed from the base of the PR and between 2f13f68 and 096faeb.

📒 Files selected for processing (7)
  • internal/providers/gemini/gemini.go
  • internal/providers/gemini/gemini_test.go
  • internal/providers/googlecommon/auth.go
  • internal/providers/googlecommon/auth_test.go
  • internal/providers/googlecommon/urls.go
  • internal/providers/vertex/vertex.go
  • internal/providers/vertex/vertex_test.go

📝 Walkthrough

Walkthrough

This PR consolidates Google authentication and Vertex AI URL utilities from separate local implementations into a shared googlecommon package, then updates Gemini and Vertex providers to use these centralized helpers, reducing duplication and improving maintainability.

Changes

Google Auth and Vertex URL Consolidation

Layer / File(s) Summary
Shared googlecommon package foundation
internal/providers/googlecommon/urls.go, internal/providers/googlecommon/auth.go, internal/providers/googlecommon/auth_test.go
Introduces googlecommon/urls.go with VertexBaseURLs and bidirectional URL conversion functions for Vertex AI endpoints. Renames auth.go package from googleauth to googlecommon, removes the exported TokenSource wrapper, and updates auth tests to call FindCredentials instead.
Gemini provider migration to googlecommon
internal/providers/gemini/gemini.go, internal/providers/gemini/gemini_test.go
Switches Gemini imports and auth/URL logic to use googlecommon.FindCredentials, googlecommon.HTTPClient, googlecommon.NormalizeAuthType, googlecommon.HasServiceAccount, and googlecommon.VertexBaseURLs. Removes local Vertex URL conversion helpers. Tests updated to construct authenticated clients via googlecommon.HTTPClient.
Vertex provider migration to googlecommon
internal/providers/vertex/vertex.go, internal/providers/vertex/vertex_test.go
Switches Vertex imports and auth/URL logic to use googlecommon utilities for credential resolution, HTTP client construction, auth-type normalization, and Vertex base URL derivation. Removes local URL conversion helpers. Tests updated to use googlecommon.VertexBaseURLs and googlecommon.HTTPClient.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • ENTERPILOT/GoModel#302: Introduces the foundation of googlecommon utilities that this PR refactors providers to use.
  • ENTERPILOT/GoModel#325: Modifies credential resolution and HTTP client wiring in related provider files with overlapping auth patterns.

Poem

🐰 From scattered auth helpers, a commons is born,
Gemini and Vertex, their duplicates sworn,
One shared googlecommon to guide them aright,
URL conversions and tokens, all unified bright!
🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main changes: renaming googleauth to googlecommon and deduplicating Vertex URL helpers, which aligns with the primary objectives of this refactoring PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/googlecommon-dedup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR renames internal/providers/googleauth to internal/providers/googlecommon and extracts the three Vertex URL helper functions that were duplicated verbatim in both vertex/vertex.go and gemini/gemini.go into a new googlecommon/urls.go. The dead TokenSource wrapper (zero callers repo-wide) is also removed.

  • Package rename: all four caller files (vertex + gemini, prod + test) updated mechanically; the internal/ boundary means no external breakage.
  • URL helper extraction: VertexBaseURLs, VertexNativeBaseURLFromOpenAICompatibleBaseURL, and VertexOpenAICompatibleBaseURLFromNativeBaseURL are now exported from googlecommon with plain-string parameters instead of a ProviderConfig struct, keeping them pure and avoiding cross-package type coupling.
  • Dead code removal: TokenSource is deleted; tests rewritten to use FindCredentials directly, which is the correct modern entry point.

Confidence Score: 5/5

Mechanical rename and deduplication with no logic changes; safe to merge.

Every changed line is either an import path swap (googleauth to googlecommon), a removal of a byte-identical duplicate, or the deletion of a confirmed-dead function. The extracted URL helpers carry the same logic as both originals; the existing TestVertexBaseURLs table still covers all five URL derivation cases. No behaviour is altered.

No files require special attention. googlecommon/urls.go holds the only net-new code and it is a straight copy of the removed originals.

Important Files Changed

Filename Overview
internal/providers/googlecommon/auth.go Renamed from googleauth/googleauth.go; dead TokenSource wrapper removed; package doc added — all other logic unchanged.
internal/providers/googlecommon/urls.go New file extracting three Vertex URL helper functions from vertex.go and gemini.go; logic is byte-identical to the removed originals and is well-commented.
internal/providers/googlecommon/auth_test.go Renamed test file; TestTokenSourceAndHTTPClientAuthSelection updated to use FindCredentials directly — equivalent coverage preserved.
internal/providers/vertex/vertex.go Import updated to googlecommon; three URL helper functions and the TODO comment removed; all call sites updated to the shared googlecommon equivalents.
internal/providers/gemini/gemini.go Import updated to googlecommon; three duplicate URL helper functions removed; geminiBaseURLs now delegates to googlecommon.VertexBaseURLs for the Vertex backend path.
internal/providers/vertex/vertex_test.go Updated to call googlecommon.VertexBaseURLs and googlecommon.HTTPClient; all 5 existing table cases for URL derivation still exercised.
internal/providers/gemini/gemini_test.go Single line updated from googleauth to googlecommon; no other test changes needed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph Before
        GA[googleauth/googleauth.go\nConfig, Credentials, NormalizeAuthType\nHasServiceAccount, FindCredentials\nHTTPClient, TokenSource dead]
        VV1[vertex/vertex.go\n+ vertexBaseURLs\n+ vertexNativeBaseURLFrom...\n+ vertexOpenAICompatibleFrom...]
        GG1[gemini/gemini.go\n+ vertexBaseURLs copy\n+ vertexNativeBaseURLFrom... copy\n+ vertexOpenAICompatibleFrom... copy]
        VV1 -->|imports| GA
        GG1 -->|imports| GA
    end
    subgraph After
        AUTH[googlecommon/auth.go\nConfig, Credentials, NormalizeAuthType\nHasServiceAccount, FindCredentials\nHTTPClient]
        URLS[googlecommon/urls.go\nVertexBaseURLs\nVertexNativeBaseURLFrom...\nVertexOpenAICompatibleFrom...]
        VV2[vertex/vertex.go\nno local URL helpers]
        GG2[gemini/gemini.go\nno local URL helpers]
        VV2 -->|imports| AUTH
        VV2 -->|imports| URLS
        GG2 -->|imports| AUTH
        GG2 -->|imports| URLS
    end
Loading

Reviews (1): Last reviewed commit: "refactor(providers): rename googleauth t..." | Re-trigger Greptile

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 20.51282% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/googlecommon/urls.go 0.00% 28 Missing ⚠️
internal/providers/gemini/gemini.go 25.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@SantiagoDePolonia SantiagoDePolonia merged commit 11941bf into main May 12, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants