Skip to content

tests: unit-test config-mcp.js setMcpServer/removeMcpServer persistence logic#319

Open
javimosch wants to merge 1 commit into
masterfrom
mago/task-416
Open

tests: unit-test config-mcp.js setMcpServer/removeMcpServer persistence logic#319
javimosch wants to merge 1 commit into
masterfrom
mago/task-416

Conversation

@javimosch

Copy link
Copy Markdown
Owner

What changed

Added __tests__/config-mcp.test.js — 22 unit tests that directly exercise cli/config-mcp.js (setMcpServer and removeMcpServer) in isolation, mocking fs, os, and plugins-store.

Why

config.test.js covers these functions only through the cli/config.js proxy. This new file tests config-mcp.js as a standalone unit, focusing on the persistence contract (what is read from and written to the cache file) rather than the higher-level config facade.

Coverage

setMcpServer — upsert

  • Insert new server when cache is absent
  • Insert without touching other entries
  • Update existing server by name (no duplicates created)
  • String value → url field
  • Object value → merged with name
  • headers and env fields passed through
  • null/non-object value → bare { name } entry
  • Throws { code: 85, type: "invalid_argument" } on empty name
  • Return value includes updated mcp_servers
  • writeFileSync called with correct path

Dedup via normalizeMcpServers

  • Same-name duplicates in stored list collapse to one (last-write wins)
  • Output list is sorted alphabetically by name
  • null/undefined items in stored list are stripped
  • Entries with numeric name are dropped

removeMcpServer — persistence

  • Returns true and removes the named entry
  • writeFileSync called; cache contains the reduced list
  • Single-of-many removal leaves the rest intact

removeMcpServer — missing-server no-op

  • Returns false when server name not present
  • Returns false when mcp_servers field missing from config
  • Returns false when cache file is absent
  • Returns false when mcp_servers is an empty array

Verified

npx jest __tests__/config-mcp.test.js --no-coverage
Tests: 22 passed, 22 total

Closes #416 (mago task #416)

22 tests covering:
- setMcpServer upsert: insert-new, update-existing, string→url, object
  merge, headers/env, null-value bare entry, throws code-85 on empty name,
  return value, write-to-cache
- dedup via normalizeMcpServers: deduplicate same-name (last-wins), sorted
  alpha output, null/invalid entries stripped, numeric name dropped
- removeMcpServer persistence: removes named entry returns true, cache file
  updated, single-of-many removal
- remove-missing no-op: returns false for absent name, for missing field,
  for missing cache, for empty array

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@javimosch, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 33 minutes and 59 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4fe8fe0-e977-43ee-9b00-fb405f970743

📥 Commits

Reviewing files that changed from the base of the PR and between afda2f7 and 8176659.

📒 Files selected for processing (1)
  • __tests__/config-mcp.test.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mago/task-416

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.

@javimosch

Copy link
Copy Markdown
Owner Author

Review — Head of Org Engineering: The diff adds a new test file __tests__/config-mcp.test.js that tests setMcpServer and removeMcpServer from ../cli/config-mcp. It is syntactically valid JS, scoped entirely to the new test file, contains no secrets or destructive changes, and aligns with the company direction of adding unit tests for logic modules.

(approved — review-only mode; merge when ready.)

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.

1 participant