Skip to content

test: add unit tests for config-loader module#277

Closed
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/config-loader-coverage
Closed

test: add unit tests for config-loader module#277
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/config-loader-coverage

Conversation

@nikolasdehor
Copy link
Contributor

Summary

  • Add 23 unit tests for core/config/config-loader module
  • Cover constants, lazy loading, caching, agent-specific section loading, validation, and performance metrics
  • Verify cache hit/miss behavior and error handling

Test Coverage

Function Tests
Constants (ALWAYS_LOADED, agentRequirements) 4
loadFullConfig 3
loadConfigSections 3
loadAgentConfig 3
loadMinimalConfig 1
preloadConfig 1
clearCache 1
getPerformanceMetrics 2
validateAgentConfig 3
getConfigSection 2
Total 23

Test Plan

  • All 23 tests passing
  • Cache behavior verified
  • Agent-specific loading validated
  • Error handling coverage

Closes #276

Copilot AI review requested due to automatic review settings February 18, 2026 20:10
@vercel
Copy link

vercel bot commented Feb 18, 2026

@nikolasdehor is attempting to deploy a commit to the Pedro Valério Lopez's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Warning

Rate limit exceeded

@nikolasdehor has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Jest unit test coverage for the legacy core/config/config-loader module, focusing on its lazy-loading behavior, caching, agent-specific section selection, validation, and performance metrics (per Issue #276).

Changes:

  • Added a new test suite covering exported constants and all exported loader/utility functions.
  • Added coverage for cache hit/miss behavior, unknown-agent fallbacks, and error logging/throwing paths.
  • Added basic assertions around performance metrics shape/format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +42
describe('config-loader', () => {
beforeEach(() => {
jest.resetAllMocks();
jest.spyOn(console, 'log').mockImplementation();
jest.spyOn(console, 'error').mockImplementation();
// Clear cache between tests
clearCache();
});

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log/console.error are spied in beforeEach but never restored. Even though Jest isolates test files, leaving spies active for the whole suite can cause confusing interactions within this file (and is inconsistent with other tests that call jest.restoreAllMocks() / mockRestore() in afterEach). Add an afterEach to restore mocks/spies (or store the spies and call mockRestore() on them).

Suggested change
describe('config-loader', () => {
beforeEach(() => {
jest.resetAllMocks();
jest.spyOn(console, 'log').mockImplementation();
jest.spyOn(console, 'error').mockImplementation();
// Clear cache between tests
clearCache();
});
let consoleLogSpy;
let consoleErrorSpy;
describe('config-loader', () => {
beforeEach(() => {
jest.resetAllMocks();
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
// Clear cache between tests
clearCache();
});
afterEach(() => {
if (consoleLogSpy && typeof consoleLogSpy.mockRestore === 'function') {
consoleLogSpy.mockRestore();
}
if (consoleErrorSpy && typeof consoleErrorSpy.mockRestore === 'function') {
consoleErrorSpy.mockRestore();
}
});

Copilot uses AI. Check for mistakes.
test('logs error message on failure', async () => {
fs.readFile.mockRejectedValue(new Error('ENOENT'));

try { await loadFullConfig(); } catch {}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the empty catch {} block here: it triggers the ESLint no-empty rule and can hide unexpected failures. You can keep the intent (assert logging) by using await expect(loadFullConfig()).rejects.toThrow(...) and then asserting console.error was called, or by providing a non-empty catch handler.

Suggested change
try { await loadFullConfig(); } catch {}
await expect(loadFullConfig()).rejects.toThrow('Config load failed');

Copilot uses AI. Check for mistakes.
@nikolasdehor
Copy link
Contributor Author

Consolidated into #424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for config-loader module

2 participants