Skip to content

Bump toolhive-core to v0.0.21 and use shared redis client#5318

Merged
rdimitrov merged 3 commits into
mainfrom
worktree-bumpt-toolhive-core-auth-server-use-shared-redis-client
May 19, 2026
Merged

Bump toolhive-core to v0.0.21 and use shared redis client#5318
rdimitrov merged 3 commits into
mainfrom
worktree-bumpt-toolhive-core-auth-server-use-shared-redis-client

Conversation

@reyortiz3
Copy link
Copy Markdown
Contributor

Summary

toolhive-core v0.0.21 ships a shared redis/ package (introduced in toolhive-core#108) that consolidates the Redis connection layer — config types, TLS dialer, per-mode client construction, topology validation, and timeout defaults — that the auth-server's storage package and pkg/transport/session had each been carrying as a near-duplicate copy. Without this migration the next consumer (stacklok-llm-gateway) would have to land another copy and we'd keep paying the drift cost.

This PR migrates the auth-server half of that consolidation. pkg/transport/session is intentionally out of scope and will land in a follow-up.

What changed

  • Bumped github.com/stacklok/toolhive-core to v0.0.21 (transitive bumps: go-redis/v9 → v9.19.0, miniredis/v2 → v2.38.0).
  • pkg/authserver/storage/redis.go: removed local RedisConfig, SentinelConfig, RedisTLSConfig, ACLUserConfig, the Default*Timeout constants, and the buildTLSConfig / newTLSDialer / configureTLSDialer / validateConfig helpers. NewRedisStorage now takes tcredis.Config plus keyPrefix and delegates topology validation, defaults, TLS plumbing, and Ping verification to the shared package. Auth-server-specific invariants (ACL password required, key prefix required) stay in the constructor.
  • pkg/authserver/runner/embeddedauthserver.go: convertRedisRunConfig produces a tcredis.Config; topology checks that duplicated tcredis's Validate were dropped — those errors now surface from the shared package.
  • Tests: deleted pkg/authserver/storage/redis_tls_test.go (now exercising dependency code per the testing rule), trimmed the validation table down to the two auth-server-specific cases, table-drove the three connection-failure tests, removed runner-side topology validation subtests, and updated env-var subtests to the new field layout (cfg.Username / cfg.Password / cfg.DB).

Net: +146 / -805 lines.

Type of change

  • Refactor

Test plan

  • `go build ./...` — clean
  • `go vet ./...` — clean
  • `task lint-fix` — 0 issues
  • `go test ./pkg/authserver/... -race -count=1` — all packages pass

Does this introduce a user-facing change?

No. Connection-mode behavior, TLS behavior, and configuration schema (`RedisRunConfig` JSON/YAML fields) are unchanged. Error messages for topology misconfiguration now come from the shared package (`redis: invalid configuration: ...`) instead of the auth-server's local validator.

Special notes for reviewers

  • The shared package validates topology, applies timeout defaults, and Pings before returning. NewRedisStorage no longer wraps the tcredis error — the `redis: ...` prefix already makes its origin clear.
  • Two test cases were removed because they tested topology validation that's now owned by toolhive-core (and exercised in its own tests). One createStorage subtest that asserted on the same topology error path was also removed — re-asserting it here would have required either t.Setenv inside a t.Parallel() parent or duplicating tcredis's test surface.
  • Pre-existing unused write and `rangeint` diagnostics in the touched test files are unrelated to this refactor.

Generated with Claude Code

The auth-server's storage package carried its own copy of the Redis
connection layer (config types, TLS dialer, per-mode client construction,
topology validation, timeout defaults). toolhive-core v0.0.21 ships a
shared redis package designed to replace those duplicates so the next
consumer migration can move stacklok-llm-gateway onto the same library
without further drift.

Replace the local RedisConfig/SentinelConfig/RedisTLSConfig/ACLUserConfig
types and the buildTLSConfig/newTLSDialer/configureTLSDialer/validateConfig
helpers with toolhive-core/redis.Config and NewClient. NewRedisStorage now
takes a tcredis.Config plus the auth-server-specific keyPrefix; the
constructor keeps the auth-server invariants (ACL password required, key
prefix required) and delegates topology validation, defaults, TLS plumbing,
and Ping verification to the shared package.

The runner's convertRedisRunConfig now produces a tcredis.Config (ACL
credentials resolved from env vars, durations parsed, CA cert file read).
Topology checks that duplicated tcredis's Validate were dropped — those
errors now surface from the shared package.

Tests: delete the storage-side TLS helper tests (now exercising dependency
code), trim the validation table down to the auth-server-specific cases,
table-drive the three connection-failure tests, remove runner-side
topology validation subtests, and update the env-var subtests to the new
field layout.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label May 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.40%. Comparing base (4bc4624) to head (b9c3d1b).

Files with missing lines Patch % Lines
pkg/authserver/runner/embeddedauthserver.go 81.81% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5318      +/-   ##
==========================================
+ Coverage   68.38%   68.40%   +0.01%     
==========================================
  Files         620      620              
  Lines       63432    63316     -116     
==========================================
- Hits        43378    43309      -69     
+ Misses      16819    16774      -45     
+ Partials     3235     3233       -2     

☔ 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.

Returning (username, password string, error) made it possible to swap
the two same-typed values silently at the call site. Introduce an
unexported redisACLCredentials struct so the role of each field is
visible at the assignment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@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 May 18, 2026
@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 May 18, 2026
@rdimitrov rdimitrov merged commit 0a741f7 into main May 19, 2026
45 checks passed
@rdimitrov rdimitrov deleted the worktree-bumpt-toolhive-core-auth-server-use-shared-redis-client branch May 19, 2026 08:13
reyortiz3 added a commit that referenced this pull request May 19, 2026
pkg/transport/session carried its own Redis connection layer (RedisConfig,
SentinelConfig, RedisTLSConfig, validateRedisConfig, buildRedisClient,
buildRedisTLSConfig, timeout defaults). The auth-server migration in
#5318 demonstrated the pattern for replacing that duplicated code with
toolhive-core/redis; vmcp session storage and the proxy-runner session
storage are the remaining consumers in this repo.

Replace the local RedisConfig/SentinelConfig/RedisTLSConfig types and the
validate/build helpers with tcredis.Config and tcredis.NewClient.
NewRedisStorage and NewRedisSessionDataStorage now take
(ctx, tcredis.Config, keyPrefix, ttl); the constructors keep the
session-specific invariants (key prefix required, must end with ':',
ttl > 0) and delegate connection-mode validation, timeout defaults, TLS
plumbing, and Ping verification to the shared package.

NewManagerWithRedis grows the same keyPrefix parameter so the wrapper
matches the underlying storage signature. The vmcp server and proxy
runner call sites build tcredis.Config in place (Addr, Password, DB) and
pass keyPrefix separately; RedisPasswordEnvVar stays in the session
package because pkg/runner reads it.

Tests: TestValidateRedisConfig is removed (topology checks now live in
tcredis); TestNewRedisStorageInvariants replaces it with the
session-specific cases (key-prefix and ttl). TestNewRedisStorageACLAuth
keeps its coverage but uses the new signature. The "invalid TLS CA cert"
manager subtest is dropped (now exercising tcredis code).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants