Skip to content

llm: extract shared OIDC config, move business logic to pkg/llm, add E2E tests - #5049

Merged
yrobla merged 5 commits into
mainfrom
yolanda/llm-followup-cleanups-5048
Apr 24, 2026
Merged

yrobla merged 5 commits into
mainfrom
yolanda/llm-followup-cleanups-5048

Conversation

@yrobla

@yrobla yrobla commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Three follow-up cleanups raised during review of #5029 (#5048). None were blockers for that PR, but they should land before the stack grows further with sibling PRs.

  • Shared OIDC config type: llm.OIDCConfig and config.RegistryOAuthConfig were identical field-for-field, creating drift risk. Both are now type aliases for a new pkg/oidc.ClientConfig type. EffectiveScopes() (and its DefaultScopes constant) moved to pkg/oidc so both aliases share it. All existing field accesses and struct literals compile unchanged.

  • CLI/pkg separation: Per the cli-commands convention, business logic was living in the CLI layer. deleteLLMSecrets, the partial-vs-full validation branch in config set, and the text formatting in config show all moved to pkg/llm as DeleteCachedTokens, SetFields, and Show. The CLI commands are now thin wrappers.

  • E2E tests: Added test/e2e/cli_llm_config_test.go covering the four scenarios from the issue: happy-path round-trip (set + show JSON), HTTPS enforcement rejection, incremental configuration, not-configured message, and post-reset state.

Closes #5048

Type of change

  • Refactoring (no behavior change)

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)

Changes

File Change
pkg/oidc/clientconfig.go New shared ClientConfig type with EffectiveScopes()
pkg/oidc/doc.go Package doc
pkg/config/config.go RegistryOAuthConfig → type alias for oidc.ClientConfig
pkg/llm/config.go OIDCConfig → type alias for oidc.ClientConfig; remove duplicate fields
pkg/llm/manage.go New: SetFields, DeleteCachedTokens, Show business logic
cmd/thv/app/llm.go Thin CLI wrappers delegating to pkg/llm
test/e2e/cli_llm_config_test.go New E2E tests for thv llm config set/show/reset

Implementation plan

Approved implementation plan

Single PR covering all three follow-up items from #5048:

  1. Create pkg/oidc.ClientConfig as the shared type. Use type aliases (not struct embedding) for RegistryOAuthConfig and OIDCConfig so all existing struct literals compile unchanged and methods on the shared type are automatically available.

  2. Move deleteLLMSecrets → llm.DeleteCachedTokens(ctx, provider), config-set mutation → (*Config).SetFields(opts), show formatting → (*Config).Show(w). CLI becomes parse-flags-then-delegate.

  3. Write E2E tests following the cli_secrets_scoped_test.go pattern: isolated temp dir for XDG_CONFIG_HOME/HOME, Ginkgo Describe/It blocks, ExpectSuccess/Run helpers.

Special notes for reviewers

The type-alias approach means config.RegistryOAuthConfig and llm.OIDCConfig are now literally the same type as oidc.ClientConfig. This was chosen over struct embedding because embedding requires updating every struct literal at call sites, while aliases require no changes to callers. The tradeoff is that methods must live on the shared type (pkg/oidc) rather than on the domain aliases — which is appropriate since EffectiveScopes is protocol-level behavior anyway.

Generated with Claude Code

@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Apr 24, 2026
@yrobla
yrobla requested a review from Copilot April 24, 2026 09:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors ToolHive’s LLM and registry OIDC configuration to share a single config type, moves LLM CLI business logic into pkg/llm, and adds E2E coverage for thv llm config commands.

Changes:

  • Introduce pkg/oidc.ClientConfig and alias both llm.OIDCConfig and config.RegistryOAuthConfig to it (including EffectiveScopes()).
  • Move LLM config mutation / token cleanup / text rendering logic into pkg/llm (SetFields, DeleteCachedTokens, Show) and make CLI commands thin wrappers.
  • Add E2E tests for thv llm config set/show/reset scenarios.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/oidc/clientconfig.go Adds shared OIDC client config type and EffectiveScopes() helper.
pkg/oidc/doc.go Adds package-level documentation for pkg/oidc.
pkg/config/config.go Replaces RegistryOAuthConfig struct with alias to shared OIDC config.
pkg/llm/config.go Replaces OIDCConfig struct with alias to shared OIDC config; removes duplicate scope logic.
pkg/llm/manage.go New home for LLM config “set/show/reset” business logic and cached-token deletion.
cmd/thv/app/llm.go Simplifies CLI commands to parse flags and delegate into pkg/llm.
test/e2e/cli_llm_config_test.go Adds E2E coverage for LLM config workflows and HTTPS enforcement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/llm/manage.go Resolved
Comment thread pkg/llm/manage.go Resolved
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed size/L Large PR: 600-999 lines changed and removed size/M Medium PR: 300-599 lines changed labels Apr 24, 2026
@yrobla
yrobla requested a review from Copilot April 24, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.75%. Comparing base (854e0ab) to head (1900bd2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5049      +/-   ##
==========================================
- Coverage   69.77%   69.75%   -0.03%     
==========================================
  Files         558      560       +2     
  Lines       56425    56475      +50     
==========================================
+ Hits        39373    39393      +20     
- Misses      14028    14057      +29     
- Partials     3024     3025       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

taskbot and others added 3 commits April 24, 2026 12:35
…E2E tests

Three follow-up cleanups from the #5029 review (#5048):

1. Extract shared OIDC config type into pkg/oidc.ClientConfig. Both
   config.RegistryOAuthConfig and llm.OIDCConfig are now type aliases for
   this type, so field additions and validation changes apply to both
   authentication flows without drift.

2. Move business logic from the CLI layer into pkg/llm per the cli-commands
   convention. The config-set mutation/validation branch, the config-show
   text formatter, and the cached-token deletion logic all live in pkg/llm
   now. The CLI commands are thin wrappers that parse flags and delegate.

3. Add E2E tests for thv llm config set/show/reset, covering happy-path
   round-trips, HTTPS enforcement, incremental configuration, the
   not-configured message, and post-reset state.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Show now returns an error and uses a writef closure to propagate the
first write failure rather than ignoring io.Writer errors. The CLI
caller is updated to return the error directly.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Providers like the environment provider are read-only and cannot hold
cached tokens, so calling ListSecrets on them would always produce a
spurious warning during thv llm config reset. Check CanList/CanDelete
capabilities first and treat non-capable providers as a no-op.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@yrobla
yrobla force-pushed the yolanda/llm-followup-cleanups-5048 branch from 6d14b82 to 2a29de0 Compare April 24, 2026 10:37
@yrobla
yrobla requested a review from Copilot April 24, 2026 10:37
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 24, 2026
Covers the business logic introduced in manage.go:
- SetFields: field mutation, partial vs full validation branching,
  invalid-value rejection
- DeleteCachedTokens: capability no-ops (no CanList/CanDelete),
  empty-scope no-op, scoped deletion, error propagation
- Show: not-configured message, required-field output, conditional
  audience line, configured-tools section

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@yrobla
yrobla force-pushed the yolanda/llm-followup-cleanups-5048 branch from 2a29de0 to fcb1110 Compare April 24, 2026 10:42
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/config/config.go Resolved
Comment thread test/e2e/cli_llm_config_test.go Resolved
Comment thread pkg/llm/manage_test.go Resolved
Mirrors the pattern from cli_secrets_scoped_test.go to ensure the test
suite never opens the user's real keychain or 1Password. The environment
provider is non-interactive and read-only, so DeleteCachedTokens is a
no-op, keeping the tests fully hermetic.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 24, 2026
@yrobla
yrobla merged commit 68f4c2f into main Apr 24, 2026
46 checks passed
@yrobla
yrobla deleted the yolanda/llm-followup-cleanups-5048 branch April 24, 2026 11:00
@JAORMX JAORMX mentioned this pull request Apr 24, 2026
4 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

llm: follow-up cleanups from #5029 review (shared OIDC config, CLI/pkg separation, E2E tests)

4 participants