test(config): cover CLI flag precedence - #931
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ece4fc05de
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| keyParts := append(parts, tv) | ||
| key := strings.Join(keyParts, ".") | ||
| envName := "BURRITO_" + strings.ToUpper(strings.Join(keyParts, "_")) | ||
| if value, exists := os.LookupEnv(envName); exists { |
There was a problem hiding this comment.
Keep empty env vars from overriding config
When a BURRITO_* variable is present but empty, this branch now promotes it into Viper's Set override layer, so it beats both flags and config files. Viper's normal env handling ignores empty values unless AllowEmptyEnv is enabled, so an empty key from something like envFrom can now silently erase a configured value or decode an empty boolean as false; preserve the previous non-empty check before calling Set.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks for catching this. I fixed it in f05d957 by only promoting non-empty environment values into Viper's override layer, preserving the previous empty-variable behavior. I also added a regression test confirming that an empty BURRITO_SERVER_ADDR does not override an explicitly set flag. The focused tests, race test, and vet all pass.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #931 +/- ##
==========================================
+ Coverage 42.39% 42.55% +0.15%
==========================================
Files 97 97
Lines 5859 5868 +9
==========================================
+ Hits 2484 2497 +13
+ Misses 3160 3157 -3
+ Partials 215 214 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f05d957 to
8a89670
Compare
8a89670 to
5f84233
Compare
Summary
Fix configuration precedence so explicitly supplied CLI flags override configuration files while environment variables continue to take priority over CLI flags.
Root cause
The CLI exposes flat flag names such as
--addr, but Viper was binding those names directly while the corresponding configuration keys are nested, such asserver.addr. Viper's default precedence also places flags above environment variables, contrary to Burrito's documented precedence.Changes
BURRITO_*environment variables above bound flags.Validation
go test ./internal/burrito/configgo test -race ./internal/burrito/configgo test ./cmd/... ./internal/burrito/configgo vet ./internal/burrito/config ./cmd/...git diff --checkFixes #146