fix(config): Improve config manager flexibility & test mocks

Refactored `config-manager.js` to handle different execution contexts (CLI vs. MCP) and fixed related Jest tests.

- Modified `readConfig` and `writeConfig` to accept an optional `explicitRoot` parameter, allowing explicit path specification (e.g., from MCP) while retaining automatic project root finding for CLI usage.

- Updated getter/setter functions (`getMainProvider`, `setMainModel`, etc.) to accept and propagate the `explicitRoot`.

- Resolved Jest testing issues for dynamic imports by using `jest.unstable_mockModule` for `fs` and `chalk` dependencies *before* the dynamic `import()`.

- Corrected console error assertions in tests to match exact logged messages.

- Updated `.cursor/rules/tests.mdc` with guidelines for `jest.unstable_mockModule` and precise console assertions.
This commit is contained in:
Eyal Toledano
2025-04-14 19:50:15 -04:00
parent 329839aeb8
commit d84c2486e4
7 changed files with 1004 additions and 92 deletions

View File

@@ -15,11 +15,7 @@ export default {
roots: ['<rootDir>/tests'],
// The glob patterns Jest uses to detect test files
testMatch: [
'**/__tests__/**/*.js',
'**/?(*.)+(spec|test).js',
'**/tests/*.test.js'
],
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
// Transform files
transform: {},