refactor: remove redundant config default fallbacks in server and launcher#3032
Merged
refactor: remove redundant config default fallbacks in server and launcher#3032
Conversation
…ncher Add Config.EnsureGatewayDefaults() that guarantees cfg.Gateway is non-nil with all defaults applied. Call it from NewUnified() and launcher.New() to replace the per-field nil-guard + fallback blocks that duplicated defaults already established by the config loading layer. This removes ~20 lines of redundant defensive code across unified.go (3 blocks for PayloadDir, PayloadPathPrefix, PayloadSizeThreshold) and launcher.go (1 block for StartupTimeout). Closes #2983 Closes #2984 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes duplicated “fallback default” logic in server/launcher consumers by introducing a config-level helper that guarantees cfg.Gateway is non-nil and defaulted, then switching call sites to rely on direct field access.
Changes:
- Added
(*config.Config).EnsureGatewayDefaults()to centralizeGatewaynil-safety + default application. - Updated
internal/server/unified.goandinternal/launcher/launcher.goto callEnsureGatewayDefaults()and readcfg.Gateway.*directly. - Adjusted launcher tests/comments to reflect that
launcher.Newnow handles a nilGateway.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/config/config_core.go | Adds exported helper to ensure Gateway exists and applies gateway + feature defaults. |
| internal/server/unified.go | Removes local default fallbacks for payload config; relies on defaulted cfg.Gateway fields. |
| internal/launcher/launcher.go | Removes local startup-timeout fallback; relies on defaulted cfg.Gateway.StartupTimeout. |
| internal/launcher/launcher_test.go | Updates test setup/commentary for nil-gateway defaulting behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Summary
Removes duplicated config default logic identified in #2983 / #2984. Consumer code in
unified.goandlauncher.gore-implemented config field defaults that the config loading layer already guarantees.Changes
New:
Config.EnsureGatewayDefaults()(config_core.go)Exported method that guarantees
cfg.Gatewayis non-nil and all gateway-level + feature defaults are applied. This makes the config loading contract explicit and safe for any consumer — including test code that constructs configs manually without going throughLoadFromFile/LoadFromStdin.Simplified:
internal/server/unified.goBefore (3 nil-guard + fallback blocks, 18 lines):
After (direct field access, 3 lines):
Simplified:
internal/launcher/launcher.goBefore (nil-guard + fallback + branch logging, 8 lines):
After (direct access, 2 lines):
Updated:
launcher_test.goUpdated test name and comment for
TestLauncher_TimeoutWithNilGatewayto document thatEnsureGatewayDefaultsnow handles the nil case.Why EnsureGatewayDefaults instead of just removing nil-guards?
100+ test files construct
config.Config{}without settingGateway. Rather than touching all of them,EnsureGatewayDefaults()provides a single defensive call that makes the contract explicit while keeping existing tests working.Closes #2983
Closes #2984