Skip to content

refactor(providers): export HasResolvedProviderValue and drop duplicate copies#329

Merged
SantiagoDePolonia merged 1 commit into
mainfrom
refactor/dedup-has-resolved-provider-value
May 12, 2026
Merged

refactor(providers): export HasResolvedProviderValue and drop duplicate copies#329
SantiagoDePolonia merged 1 commit into
mainfrom
refactor/dedup-has-resolved-provider-value

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented May 12, 2026

Summary

The unresolved-${VAR} placeholder check was defined three times byte-for-byte (MD5-verified):

  • internal/providers/config.go — used in buildProviderConfig validation
  • internal/providers/vertex/vertex.go — used in validateConfig
  • internal/providers/gemini/gemini.go — same shape

The function isn't GCP-specific. It just looks for a literal ${ substring that would indicate the YAML env-substitution pass left a placeholder unresolved (e.g. ${OPENAI_API_KEY} when the env var wasn't set).

This PR exports the parent-package copy as HasResolvedProviderValue, deletes the two duplicates in vertex/ and gemini/, and rewrites the 6 child-package call sites to use providers.HasResolvedProviderValue. Both child packages already import gomodel/internal/providers, so no new dependencies.

Added a doc comment to the now-exported function explaining the ${VAR}-placeholder semantics so future readers don't have to infer them from the implementation.

Risk

  • Function gains export visibility: HasResolvedProviderValue is now public on the providers package. Anyone outside this repo who needs the same check could call it. No downside — the function is small, well-defined, and the semantics are stable.
  • Call sites in vertex.go and gemini.go are 1 token longer (providers.HasResolvedProviderValue vs hasResolvedProviderValue). Trivial.
  • No behavior change. The deleted definitions were byte-identical to the kept one.

Out of scope

The name HasResolvedProviderValue carries the "Provider" qualifier purely for continuity with the existing usage. If a future caller outside provider config wants this check, a follow-up cosmetic rename (HasResolvedConfigValue or similar) is fine — not chasing it here.

Test plan

  • Full go test ./... clean across the module.
  • go test -race clean on ./internal/providers/....
  • Pre-commit hooks: make test-race, make lint, go mod tidy all green.

Net diff: -4 lines (16 inserted, including the new 6-line doc comment; 20 removed across 3 files).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Consolidated provider configuration validation logic by centralizing a shared validation helper function across internal modules, reducing code duplication.

Review Change Stack

…te copies

The unresolved-${VAR} placeholder check was defined three times byte-for-byte:
in internal/providers/config.go (used by buildProviderConfig validation), in
internal/providers/vertex/vertex.go (used in validateConfig), and in
internal/providers/gemini/gemini.go (same shape). The function isn't
GCP-specific — it just looks for a literal `${` substring that would indicate
the YAML env-substitution pass left a placeholder unresolved.

Export the parent-package copy as `HasResolvedProviderValue`, delete the two
duplicates in vertex/ and gemini/, and rewrite the 6 child-package call sites
to use `providers.HasResolvedProviderValue`. Both child packages already
import `gomodel/internal/providers`, so no new dependencies.

Added a doc comment to the now-exported function explaining the
${VAR}-placeholder semantics so future readers don't have to infer them from
the implementation.

Test plan:
- Full `go test ./...` clean.
- `go test -race ./internal/providers/...` clean across providers,
  providers/vertex, providers/gemini.
- Pre-commit hooks (test-race, lint, mod-tidy) pass.

Out of scope: the function is named `HasResolvedProviderValue` for continuity
with the existing usage; if a future caller outside provider config also wants
this check, renaming to something more generic (`HasResolvedConfigValue`?) is
a separate cosmetic change.

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: 6884e20b-7c6e-4e67-a2fc-ae2a00185911

📥 Commits

Reviewing files that changed from the base of the PR and between 11941bf and 96ba7fa.

📒 Files selected for processing (3)
  • internal/providers/config.go
  • internal/providers/gemini/gemini.go
  • internal/providers/vertex/vertex.go

📝 Walkthrough

Walkthrough

Three provider implementations consolidate credential-resolution validation by exporting a shared helper from config.go and replacing duplicate local validators in Gemini and Vertex providers with calls to the new HasResolvedProviderValue function.

Changes

Resolved-Value Validation Consolidation

Layer / File(s) Summary
Export resolved-value validation helper
internal/providers/config.go
HasResolvedProviderValue is exported with enhanced documentation and integrated into validVertexProviderConfig to validate BaseURL and service-account credential resolution.
Migrate Gemini and Vertex providers to shared helper
internal/providers/gemini/gemini.go, internal/providers/vertex/vertex.go
Gemini and Vertex validateConfig functions switch from local hasResolvedProviderValue helpers to providers.HasResolvedProviderValue, eliminating duplicate logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A helper hops out to play,
Shared with friends along the way,
No more duplication's pain,
One true path for all to gain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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 'refactor(providers): export HasResolvedProviderValue and drop duplicate copies' accurately and specifically describes the main change: exporting a helper function and removing duplicate implementations across multiple files.
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/dedup-has-resolved-provider-value

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 consolidates three byte-identical copies of a hasResolvedProviderValue helper into a single exported HasResolvedProviderValue on the providers package, adding a doc comment and updating all six call sites in vertex and gemini.

  • internal/providers/config.go: hasResolvedProviderValue is renamed to HasResolvedProviderValue, a 6-line doc comment is added, and the 5 internal call sites are updated.
  • internal/providers/gemini/gemini.go and internal/providers/vertex/vertex.go: their private copies are deleted (4 lines each) and 2 call sites per file are rewritten to providers.HasResolvedProviderValue; no new import is needed since both packages already import providers.

Confidence Score: 5/5

Safe to merge — pure deduplication with no behavior change and no new dependencies introduced.

All three deleted functions were byte-identical to the kept one. The six rewritten call sites are mechanical one-token substitutions. Both child packages already imported the parent providers package, so the import graph is unchanged. The new export simply makes an internal utility accessible to future callers without altering any logic path.

No files require special attention.

Important Files Changed

Filename Overview
internal/providers/config.go Exports hasResolvedProviderValue as HasResolvedProviderValue with a doc comment; updates 5 internal call sites — no behavior change.
internal/providers/gemini/gemini.go Removes duplicate hasResolvedProviderValue definition and rewrites 2 call sites to providers.HasResolvedProviderValue — identical semantics.
internal/providers/vertex/vertex.go Removes duplicate hasResolvedProviderValue definition and rewrites 2 call sites to providers.HasResolvedProviderValue — identical semantics.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph Before
        A1["config.go\nhasResolvedProviderValue()"]
        A2["gemini/gemini.go\nhasResolvedProviderValue()"]
        A3["vertex/vertex.go\nhasResolvedProviderValue()"]
    end

    subgraph After
        B["providers.HasResolvedProviderValue()\n(exported, documented)"]
        C1["config.go\n5 call sites"]
        C2["gemini/gemini.go\n2 call sites"]
        C3["vertex/vertex.go\n2 call sites"]
        C1 --> B
        C2 --> B
        C3 --> B
    end
Loading

Reviews (1): Last reviewed commit: "refactor(providers): export HasResolvedP..." | 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 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/gemini/gemini.go 50.00% 0 Missing and 1 partial ⚠️
internal/providers/vertex/vertex.go 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@SantiagoDePolonia SantiagoDePolonia merged commit 555b7ad into main May 12, 2026
18 of 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