♻️ Refactor ConfigService into functional decomposition#130
Conversation
Extract pure functions and operations from ConfigService following the established pattern from auth-service and api-service refactors. ## New module structure - `src/config/core.js` - Pure functions (no I/O): - CONFIG_DEFAULTS, deepMerge, buildMergedConfig - Serialization: serializeToJavaScript, serializeToJson, stringifyWithIndent - Validation: validateReadScope, validateWriteScope - Result builders: buildProjectConfigResult, buildGlobalConfigResult, etc. - `src/config/operations.js` - Operations with dependency injection: - getProjectConfig, getGlobalConfig, getMergedConfig, getConfig - updateProjectConfig, updateGlobalConfig, updateConfig - validateConfig, getConfigSource, writeProjectConfigFile - `src/config/index.js` - Public exports ## Test improvements - 91 new tests added (57 core + 34 operations) - No vi.mock usage - pure input/output assertions - In-memory test helpers for dependency injection - All 1078 tests pass ## Backwards compatibility ConfigService class now delegates to new modules, marked as @deprecated. New code should import from src/config/ directly.
Code Review - PR #130This is an excellent refactoring that follows established patterns from previous PRs. The functional decomposition is well-executed with clean separation of concerns. Here is my detailed feedback: ✅ StrengthsArchitecture & Design:
Code Quality:
Testing:
🔍 Issues & Concerns1. Potential Bug in
|
- Fix prototype pollution: use Object.keys() instead of for...in in deepMerge
- Add JSON.parse error handling in writeProjectConfigFile for malformed package.json
- Add input validation in buildMergedConfig (handles null, non-object inputs)
- Make serializeConfig return consistent shape { content, format, error }
- Add 4 new tests for these edge cases
Summary
ConfigServiceintosrc/config/core.js(deepMerge, serialization, validation, config building)src/config/operations.jswith dependency-injected I/O operations (getConfig, updateConfig, etc.)ConfigServiceclass as thin backwards-compatible wrapper, marked@deprecatedThis follows the established pattern from #125 (TddService), #127 (ApiService), and #129 (auth-service).
Test plan
vi.mockin new tests