test: make models-list tests hermetic and parallelizable#3388
Merged
Conversation
Inject an in-memory env provider and a stub models.dev store via a new modelsCmdOption seam, replacing t.Setenv + paths.SetConfigDir hacks.
Sayt-0
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Make the
TestModelsListCommand_*tests hermetic and parallelizable.Why
Each of the five
TestModelsListCommand_*tests rannewModelsCmd().Execute()against the real environment, which made them slow (~2–3s each, ~12–16s for
the whole
cmd/rootpackage):config.AvailableProvidersprobes ~19 providers × several env vars. For everymissing API key, the default env-provider chain shells out to the macOS
securitykeychain (pluspass/op/Docker-Desktop socket). Measured at~1.48s for 20 lookups.
models.devstore fetcheshttps://models.dev/api.json(30s timeout)on a cold cache — a network dependency in a unit test.
t.Setenv+paths.SetConfigDir, so they could not run in parallel.How
modelsCmdOptionvariadic seam tonewModelsCmd/newModelsListCmd.Production calls
newModelsCmd()with no args, so behavior is unchanged.Tests inject a hermetic env provider (
environment.NewMapEnvProvider) and anin-memory models.dev store (
modelsdev.NewDatabaseStore) via the existingRuntimeConfig.EnvProviderForTests/RuntimeConfig.ModelsDevStoreOverridefields.
models_test.go: dropt.Setenv/paths.SetConfigDir, addt.Parallel()to every test, and add a tiny in-memorytestCatalog()database.injected store is read (not just the per-provider defaults); the default-marker
test now asserts exactly one default row matching the auto-selected model; and
the canceled-context test asserts the server is never reached.
Result
cmd/rootpackage: ~12–16s → ~1.7s (~3.7s with-race)golangci-lint0 issues,go test -race ./cmd/root/green,full suite passes with no regressions.