Repository navigation
llm: extract shared OIDC config, move business logic to pkg/llm, add E2E tests - #5049
Conversation
There was a problem hiding this comment.
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.ClientConfigand alias bothllm.OIDCConfigandconfig.RegistryOAuthConfigto it (includingEffectiveScopes()). - 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/resetscenarios.
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.
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…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]>
6d14b82 to
2a29de0
Compare
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]>
2a29de0 to
fcb1110
Compare
There was a problem hiding this comment.
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.
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]>
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.OIDCConfigandconfig.RegistryOAuthConfigwere identical field-for-field, creating drift risk. Both are now type aliases for a newpkg/oidc.ClientConfigtype.EffectiveScopes()(and itsDefaultScopesconstant) moved topkg/oidcso both aliases share it. All existing field accesses and struct literals compile unchanged.CLI/pkg separation: Per the
cli-commandsconvention, business logic was living in the CLI layer.deleteLLMSecrets, the partial-vs-full validation branch inconfig set, and the text formatting inconfig showall moved topkg/llmasDeleteCachedTokens,SetFields, andShow. The CLI commands are now thin wrappers.E2E tests: Added
test/e2e/cli_llm_config_test.gocovering 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
Test plan
task test)task test-e2e)Changes
pkg/oidc/clientconfig.goClientConfigtype withEffectiveScopes()pkg/oidc/doc.gopkg/config/config.goRegistryOAuthConfig→ type alias foroidc.ClientConfigpkg/llm/config.goOIDCConfig→ type alias foroidc.ClientConfig; remove duplicate fieldspkg/llm/manage.goSetFields,DeleteCachedTokens,Showbusiness logiccmd/thv/app/llm.gopkg/llmtest/e2e/cli_llm_config_test.gothv llm config set/show/resetImplementation plan
Approved implementation plan
Single PR covering all three follow-up items from #5048:
Create
pkg/oidc.ClientConfigas the shared type. Use type aliases (not struct embedding) forRegistryOAuthConfigandOIDCConfigso all existing struct literals compile unchanged and methods on the shared type are automatically available.Move
deleteLLMSecrets→llm.DeleteCachedTokens(ctx, provider), config-set mutation →(*Config).SetFields(opts), show formatting →(*Config).Show(w). CLI becomes parse-flags-then-delegate.Write E2E tests following the
cli_secrets_scoped_test.gopattern: isolated temp dir forXDG_CONFIG_HOME/HOME, GinkgoDescribe/Itblocks,ExpectSuccess/Runhelpers.Special notes for reviewers
The type-alias approach means
config.RegistryOAuthConfigandllm.OIDCConfigare now literally the same type asoidc.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 sinceEffectiveScopesis protocol-level behavior anyway.Generated with Claude Code