Skip to content

test: MCP config CRUD + Locale utility coverage#369

Merged
anandgupta42 merged 2 commits intomainfrom
claude/test-mcp-config-locale-20260322-session_0144wYQpTz6tEZgSYUnzns2A
Mar 22, 2026
Merged

test: MCP config CRUD + Locale utility coverage#369
anandgupta42 merged 2 commits intomainfrom
claude/test-mcp-config-locale-20260322-session_0144wYQpTz6tEZgSYUnzns2A

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 22, 2026

What does this PR do?

Adds first-ever test coverage for two previously untested modules, and discovers a real bug in Locale.duration.

1. resolveConfigPath, addMcpToConfig, removeMcpFromConfig, listMcpInConfig, findAllConfigPathssrc/mcp/config.ts (16 new tests)

These functions power all MCP server management via the CLI (mcp add, mcp remove, mcp list) and the datamate tool integration. Zero tests existed despite being actively used. New coverage includes:

  • Config path resolution priority: .altimate-code/ > .opencode/ > root-level
  • global=true flag correctly skips subdirectory configs
  • Default path returned when no config file exists
  • Add server to empty config file (creates file from scratch)
  • Add server to existing config preserving other fields (non-destructive JSON editing)
  • Remove returns false for missing file or missing server name
  • Full add → list → remove → list round-trip
  • listMcpInConfig handles missing file, missing mcp key, and multiple servers
  • findAllConfigPaths returns paths from both project and global dirs
  • findAllConfigPaths includes project subdirs (.altimate-code/, .opencode/) but NOT global subdirs

2. Locale.number, Locale.duration, Locale.truncateMiddle, Locale.pluralizesrc/util/locale.ts (13 new tests, 1 skipped)

These utilities are used across the TUI for session duration display, token count formatting, and text truncation. Zero direct tests existed. New coverage includes:

  • number(): millions formatting, thousands formatting, boundary at 999999, small numbers
  • duration(): ms, seconds, minutes+seconds, hours+minutes ranges
  • truncateMiddle(): short string passthrough, long string with ellipsis placement
  • pluralize(): singular (count=1) vs plural (count≠1) template substitution

Bug discovered: Locale.duration() has a real bug in the ≥24h branch — days and hours calculations are swapped. days = Math.floor((input % 3600000) / 86400000) always yields 0 because the hour remainder is always less than one day. For example, 25 hours displays as "0d 25h" instead of "1d 1h". Filed as #368. A skipped test documents the correct expected behavior.

Type of change

  • New feature (non-breaking change which adds functionality)

Issue for this PR

How did you verify your code works?

bun test test/mcp/config.test.ts    # 16 pass, 0 fail
bun test test/util/locale.test.ts   # 12 pass, 1 skip, 0 fail

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_0144wYQpTz6tEZgSYUnzns2A

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for configuration management functionality.
    • Expanded test coverage for locale formatting utilities.

… bug

Add 16 tests for MCP config operations (resolveConfigPath, addMcpToConfig,
removeMcpFromConfig, listMcpInConfig, findAllConfigPaths) — all previously
untested. Add 13 tests for Locale utilities (number, duration, truncateMiddle,
pluralize). Discovered and filed #368: Locale.duration >=24h branch has
days/hours swapped, always showing "0d Xh".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

https://claude.ai/code/session_0144wYQpTz6tEZgSYUnzns2A
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3e3c10f9-9b67-4805-a489-2852bac72ee7

📥 Commits

Reviewing files that changed from the base of the PR and between 87ceda2 and 841a0f7.

📒 Files selected for processing (2)
  • packages/opencode/test/mcp/config.test.ts
  • packages/opencode/test/util/locale.test.ts

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

Added two new test files covering MCP configuration utilities and Locale formatting functions. The tests validate configuration path resolution, server discovery, configuration mutation operations, and utility functions for numeric/duration formatting, string truncation, and pluralization logic.

Changes

Cohort / File(s) Summary
MCP Configuration Tests
packages/opencode/test/mcp/config.test.ts
Comprehensive test suite for configuration utilities including path resolution (precedence: .altimate-code/altimate-code.json > .opencode/opencode.json > root opencode.json), add/remove MCP server operations with preservation of unrelated config fields, server listing from config objects, and discovery logic aggregating paths from project/global directories with proper subdirectory handling.
Locale Utility Tests
packages/opencode/test/util/locale.test.ts
Test coverage for Locale utility functions: numeric formatting with thousand/million thresholds, duration formatting (ms/sec/min/hour), string truncation with middle ellipsis, and pluralization logic. Includes documentation of a known issue for durations ≥ 24 hours.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops of joy for tests so true,
Config paths and Locales too,
Numbers formatted, strings truncated right,
Coverage grows through day and night!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/test-mcp-config-locale-20260322-session_0144wYQpTz6tEZgSYUnzns2A

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.

@anandgupta42 anandgupta42 merged commit d10303c into main Mar 22, 2026
9 of 10 checks passed
@anandgupta42 anandgupta42 deleted the claude/test-mcp-config-locale-20260322-session_0144wYQpTz6tEZgSYUnzns2A branch March 22, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant