Commit 46d13a3
fix: restore config import override behavior while maintaining Windows fix (#1489)
* fix: remove redundant MergeInConfig call that broke Windows tests
The tempViper.MergeInConfig() call was attempting to merge the config into itself,
which was causing YAML template functions to return null values on Windows.
This bug was introduced in PR #1447 and caused test failures in:
- TestYamlFuncTerraformOutput
- TestProcessCustomYamlTags
The fix removes this unnecessary call since we're already processing the config
correctly by marshaling tempViper to YAML and then merging it into the main
Viper instance.
* fix: restore config import override behavior while maintaining Windows fix
- Re-merge original config content after processing imports to ensure main config takes precedence
- This fixes TestInitCliConfig/valid_import_custom_override while keeping Windows tests passing
- Imports now correctly serve as base configuration that can be overridden by the main config
The fix ensures proper config precedence: imports are processed first as a base layer,
then the main config is applied on top as an override layer.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: clarify config merging comments for better understanding
- Changed "original config" to "current config file's content" to be more precise
- Clarified that we're re-applying the current file's settings on top of imported configs
- Makes it clearer that the file being processed (which contains the imports) takes precedence
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: add comprehensive tests for config import override behavior
- Added TestMergeConfig_ImportOverrideBehavior to verify main config overrides imports
- Added TestMergeConfig_ImportDeepMerge to document section replacement behavior
- Added TestMergeConfig_ProcessImportsWithInvalidYAML for error handling coverage
- These tests increase coverage of the config merging logic and document expected behavior
The tests confirm that:
- Main config sections completely replace imported sections (not deep merge)
- Invalid imports are logged but don't cause failures
- The fix correctly prioritizes main config over imports
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* chore: add trim_trailing_whitespace to .editorconfig
- Added trim_trailing_whitespace = true to the global [*] section
- Added trim_trailing_whitespace = false for binary files to prevent corruption
- Added explicit Go file configuration with tab indentation
- This aligns .editorconfig with pre-commit hooks that already trim whitespace
This ensures consistency between editor behavior and CI checks, reducing
pre-commit hook failures caused by trailing whitespace.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: clarify config import precedence hierarchy in comments
- Removed confusing "main config" terminology
- Clearly explain that each config file's settings override its imports
- Added concrete example: if A imports B, and B imports C, then B overrides C, and A overrides both
- Updated function comment to explain the precedence hierarchy
The comments now clearly convey that imports create a hierarchy where
the importing file always takes precedence over imported files.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: improve config import tests with stronger assertions and godot compliance
- Added periods to all test comments to satisfy godot linter
- Strengthened command override assertion to verify replacement (not append):
- Assert commands slice has exactly 1 element
- Verify the single command is "main-command" from main config
- Ensures imported commands were replaced, not merged
- Replaced fragile empty string checks with v.IsSet() assertions:
- Use assert.False(t, v.IsSet(...)) for absent keys
- More reliable than checking for empty strings
- Fixed all comment punctuation in test functions
These changes make tests more robust and comply with Go linting standards.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: add tests to improve config merge coverage
- Added TestMergeConfig_ReadFileError to test file read error handling
- Tests the error path when os.ReadFile fails (lines 285-287)
- Uses chmod to make file unreadable after initial load
- Added TestMergeConfig_WithoutImports to test processImports=false path
- Ensures code coverage when imports are not processed
- Verifies config loads correctly without import processing
These tests improve coverage of the mergeConfig function from ~45% to 83.3%.
The remaining uncovered lines are edge cases difficult to simulate in tests.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: replace Windows-incompatible test with cross-platform coverage tests
- Removed TestMergeConfig_ReadFileError which used chmod (fails on Windows)
- Added TestMergeConfig_EmptyConfig to test edge case of empty config files
- Added TestMergeConfig_ComplexImportHierarchy to test multi-level import chains
- Tests A imports B, B imports C hierarchy
- Verifies proper override precedence through import chains
- Improves coverage of import processing paths
These tests are cross-platform compatible and provide better coverage
of the import processing logic without relying on OS-specific permissions.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: break mergeConfig into smaller testable functions for better coverage
- Extracted loadConfigFile() for loading config files into Viper
- Extracted readConfigFileContent() for reading file contents
- Extracted processConfigImportsAndReapply() for import processing logic
- Extracted marshalViperToYAML() for YAML marshaling
- Extracted mergeYAMLIntoViper() for merging YAML into Viper
- Simplified mergeConfig() to orchestrate these smaller functions
Added comprehensive tests for each new function:
- 100% coverage for loadConfigFile, readConfigFileContent, mergeYAMLIntoViper
- 85.7% coverage for processConfigImportsAndReapply
- 80% coverage for marshalViperToYAML
- 81.2% coverage for mergeConfig (up from 45%)
This refactoring improves:
- Code maintainability through smaller, focused functions
- Test coverage from 67.6% to 68.0% overall
- Makes error paths more testable
- Keeps all existing functionality intact
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: add Windows file locking resilience for Terraform state operations
- Add retry logic with exponential backoff for Windows file operations
- Add small delays between Terraform workspace and output operations on Windows
- Wrap os.Remove calls with retry logic to handle locked files
- Use build tags to apply Windows-specific fixes only on Windows platform
This addresses intermittent 'The process cannot access the file because another
process has locked a portion of the file' errors when running multiple Terraform
output operations in quick succession on Windows.
* test: add comprehensive tests for Windows file locking resilience
- Add platform-specific tests for retry logic on Windows
- Add tests verifying no-op behavior on non-Windows platforms
- Add integration tests for file operation scenarios
- Test retry with exponential backoff timing
- Test successful operations, retries, and failure scenarios
Ensures the Windows file locking fixes are properly tested and
maintain expected behavior across platforms.
* fix: improve error wrapping in config load functions
- Wrap preprocessAtmosYamlFunc error with 'preprocess YAML functions' context
- Wrap tempViper.MergeConfig error with 'merge temp config' context
- Wrap os.ReadFile error with file path context in readConfigFileContent
- Handle viper.ConfigFileNotFoundError sentinel properly in loadConfigFile
- Return sentinel unwrapped for type checking compatibility
- Wrap other errors with descriptive context
This ensures consistent error handling throughout the config loading process
while preserving sentinel errors for proper error checking with errors.Is().
* fix: resolve test issues for better code quality
- Fix variable shadowing in terraform_output_utils_windows_test.go
- Renamed 'errors' slice to 'errList' to avoid shadowing errors package
- Ensures errors.New() calls resolve correctly to the package
- Use t.Skipf instead of t.Skip per project conventions
- Updated terraform_output_utils_integration_test.go
- Follows mandatory test skipping conventions requiring t.Skipf
These fixes improve code clarity and maintain consistency with project guidelines.
* refactor: reorganize config tests for better maintainability
- Split large config_test.go (974 lines) into smaller, focused files
- Create config_merge_test.go for merge-related tests (302 lines)
- Create config_import_test.go for import-related tests (205 lines)
- Reduce main config_test.go to 487 lines (~50% reduction)
- Remove duplicate load_test.go that was causing compilation errors
- Remove unused viper import from config_test.go
This improves test organization, makes tests easier to find and maintain,
and follows Go best practices of keeping test files focused and manageable.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3e2ed8a commit 46d13a3
12 files changed
Lines changed: 958 additions & 104 deletions
File tree
- internal/exec
- pkg/config
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
| |||
260 | 263 | | |
261 | 264 | | |
262 | 265 | | |
263 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
264 | 277 | | |
265 | 278 | | |
266 | 279 | | |
| 280 | + | |
267 | 281 | | |
268 | 282 | | |
269 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
0 commit comments