test(#495): 28 unit tests for config-commands.js (upsertCommand, removeCommandsByNamespace, showConfig)#333
test(#495): 28 unit tests for config-commands.js (upsertCommand, removeCommandsByNamespace, showConfig)#333javimosch wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…veCommandsByNamespace, showConfig) Directly tests config-commands.js by mocking config-core and plugins-store. Covers: null-cache fallback to emptyConfig, insert, update-in-place by key, multi-command append/update, null-entry tolerance, non-array commands guard, namespace removal counts, ISO date conversion, cacheFilePath forwarding. All 28 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughTwo Jest test files are added. ChangesCLI Test Coverage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
__tests__/execute-handler.test.js (2)
318-320: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert the JSON header on the server plan request.
These tests lock down the URL/body, but not the
Content-Type: application/jsonheader thatcli/execute-handler.js:49-54currently sends. A regression there would still pass here while breaking the server contract.Suggested test tightening
expect(global.fetch).toHaveBeenCalledWith( "https://srv.io/api/plans", - expect.objectContaining({ method: "POST" }) + expect.objectContaining({ + method: "POST", + headers: { "Content-Type": "application/json" }, + }) );Also applies to: 352-356
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@__tests__/execute-handler.test.js` around lines 318 - 320, Tighten the execute-handler tests so they also verify the server plan request sends Content-Type: application/json in addition to the URL and POST method. Update the fetch expectation in execute-handler.test.js for the request asserted around the plan submission path, using the existing global.fetch check to validate the headers object as well; mirror the same assertion in the other plan-request case referenced by the review so both paths are covered.
259-267: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRestore the original
fetchinstead of deleting itBoth hooks delete Node 18’s built-in
global.fetch. Save the original value once and restore it inafterEachso later tests in the same process don’t inherit a missingfetch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@__tests__/execute-handler.test.js` around lines 259 - 267, The test hooks are removing Node 18’s built-in global.fetch instead of restoring it, which can leak state into later tests. In __tests__/execute-handler.test.js, update the beforeEach/afterEach setup to save the original global.fetch once, mock or clear it during the test, and restore that saved value in afterEach rather than deleting it. Use the existing beforeEach/afterEach hooks and the global.fetch reference to locate the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@__tests__/execute-handler.test.js`:
- Around line 318-320: Tighten the execute-handler tests so they also verify the
server plan request sends Content-Type: application/json in addition to the URL
and POST method. Update the fetch expectation in execute-handler.test.js for the
request asserted around the plan submission path, using the existing
global.fetch check to validate the headers object as well; mirror the same
assertion in the other plan-request case referenced by the review so both paths
are covered.
- Around line 259-267: The test hooks are removing Node 18’s built-in
global.fetch instead of restoring it, which can leak state into later tests. In
__tests__/execute-handler.test.js, update the beforeEach/afterEach setup to save
the original global.fetch once, mock or clear it during the test, and restore
that saved value in afterEach rather than deleting it. Use the existing
beforeEach/afterEach hooks and the global.fetch reference to locate the fix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: df97cc4f-6db8-476d-a4cc-8bc3669bb257
📒 Files selected for processing (2)
__tests__/config-commands.test.js__tests__/execute-handler.test.js
|
Review — Head of Org Engineering: The diff adds new test files for config-commands and execute-handler modules, which aligns with the company's focus on unit/integration tests for CLI modules. The tests are syntactically valid, scoped only to new test files, and contain no secrets, destructive changes, or out-of-scope edits. (approved — review-only mode; merge when ready.) |
What
Direct unit test suite for
cli/config-commands.js— the module that owns command upsert and removal logic in the local config cache.Why
config.test.jsexercises these functions via theconfig.jsre-export but shares mocks with config-core tests, limiting isolation. A dedicated file mocksconfig-coreandplugins-storedirectly so each exported function can be exercised independently with precise assertions.Tests (28 assertions, all green)
upsertCommandemptyConfig, pushes new commandcommandsfield → treated as emptywriteCachecalled exactly onceremoveCommandsByNamespacewriteCachecalled exactly oncenamespace === ""showConfig{cached: false, message: ...}fetchedAtconverted to ISO stringserver_pluginscounts keys frominstalledsub-objectinstalledabsent →server_pluginsis 0cacheFilePath()return value forwarded ascacheFilepluginscount matcheslistInstalledPluginslengthVerification
Closes #495 (mago task #495)
Summary by CodeRabbit