feat: add root-level config merging

Add merge_configs function that performs root-level merging of custom
config into default config. Custom config sections completely replace
default sections. Implementation does not mutate input dictionaries.

Includes comprehensive tests for:
- Empty custom config
- Section override behavior
- Adding new sections
- Non-mutating behavior

All 7 tests pass.
This commit is contained in:
2025-11-01 16:59:02 -04:00
parent 03f81b3b5c
commit 7e95ce356b
2 changed files with 64 additions and 1 deletions

View File

@@ -34,3 +34,25 @@ def load_config(path: str) -> Dict[str, Any]:
return json.load(f)
except json.JSONDecodeError as e:
raise ConfigValidationError(f"Invalid JSON in {path}: {e}")
def merge_configs(default: Dict[str, Any], custom: Dict[str, Any]) -> Dict[str, Any]:
"""
Merge custom config into default config (root-level override).
Custom config sections completely replace default sections.
Does not mutate input dictionaries.
Args:
default: Default configuration dict
custom: Custom configuration dict (overrides)
Returns:
Merged configuration dict
"""
merged = dict(default) # Shallow copy
for key, value in custom.items():
merged[key] = value
return merged