test: CLI error formatting + YAML frontmatter sanitization#423
test: CLI error formatting + YAML frontmatter sanitization#423anandgupta42 wants to merge 1 commit intomainfrom
Conversation
…sts) Cover two zero-test-coverage areas that produce user-facing output: FormatError/FormatUnknownError (error messages) and ConfigMarkdown.fallbackSanitization (messy YAML from other AI tools). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_01KYDdfMxVRzntwFi66wMnEr
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo new test suites were added to the opencode package: one for CLI error-formatting utilities covering multiple error types and fallback behavior, and another for Markdown/YAML frontmatter sanitization functionality. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
Superseded by #439 which consolidates all 12 test PRs into one, deduplicates overlapping tests, and fixes bugs found during review. |
What does this PR do?
Adds 31 new tests across two completely untested areas that produce user-facing output. Both modules had zero test coverage prior to this PR.
1.
FormatError+FormatUnknownError—src/cli/error.ts(21 new tests)These are the only functions that format error messages shown to CLI users. When a user hits a provider misconfiguration, broken config JSON, MCP server failure, or model-not-found error, these functions produce the human-readable message. Zero tests existed, meaning any refactoring of NamedError names or addition of new error types could silently break user-facing output.
New coverage includes:
MCPFailed,ProviderModelNotFoundError,ProviderInitError,ConfigJsonError,ConfigDirectoryTypoError,ConfigFrontmatterError,ConfigInvalidError,UICancelledError)ModelNotFoundErrorwith and without suggestions (different output paths)InvalidErrorwith issues list and with the special"config"path that suppresses location displayFormatUnknownErroredge cases: Error with/without stack, plain objects, circular objects (unserializable fallback), primitives (string, number, undefined, null)undefined(fallthrough to caller)2.
ConfigMarkdown.fallbackSanitization—src/config/markdown.ts(10 new tests, added to existing file)This function is the safety net for users importing
CLAUDE.md,.cursorrules, or other config files from other AI tools that contain messy YAML frontmatter (unquoted colons in URLs, model IDs likeorg/repo:tag). It converts problematic values to YAML block scalars so gray-matter can parse them. Previously only tested indirectly throughparse()with fixture files — edge cases in the sanitizer itself were uncovered.New coverage includes:
---is never modified by the sanitizerType of change
Issue for this PR
N/A — proactive test coverage for zero-coverage user-facing code
How did you verify your code works?
All tests validated by a critic agent before commit. Three error name mismatches (
McpFailed→MCPFailed,ModelNotFoundError→ProviderModelNotFoundError) were caught and fixed during review.Checklist
https://claude.ai/code/session_01KYDdfMxVRzntwFi66wMnEr
Summary by CodeRabbit