Skip to content

test(skill,mcp): improve test coverage for writeSkillOutput and fileSystemReadFileTool#1008

Merged
yamadashy merged 2 commits intomainfrom
test/improve-coverage-for-skill-and-mcp
Dec 14, 2025
Merged

test(skill,mcp): improve test coverage for writeSkillOutput and fileSystemReadFileTool#1008
yamadashy merged 2 commits intomainfrom
test/improve-coverage-for-skill-and-mcp

Conversation

@yamadashy
Copy link
Copy Markdown
Owner

Add comprehensive tests to improve code coverage from 89.81% to 90.28%.

Changes

writeSkillOutput.ts (63.88% → 100%):

  • Add test for techStack file writing
  • Add tests for EPERM/EACCES error handling
  • Add test for generic error handling
  • Add test for non-Error object handling

fileSystemReadFileTool.ts (62.5% → 100%):

  • Add test for directory path error
  • Add test for successful file reading
  • Add test for security check failure
  • Add test for general errors during file reading
  • Add test for non-Error object handling

Checklist

  • Run npm run test
  • Run npm run lint

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 14, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Two test files are expanded with enhanced error handling validation and improved mock configuration. Tests for writeSkillOutput verify RepomixError handling for permission and I/O errors, while tests for FileSystemReadFileTool add security checks, fs/promises integration, and comprehensive error scenarios.

Changes

Cohort / File(s) Summary
writeSkillOutput tests
tests/core/skill/writeSkillOutput.test.ts
Added RepomixError import and expanded test coverage to validate error handling for permission errors (EPERM, EACCES), generic rejections, and I/O errors; verifies tech-stack.md file writes and directory creation.
FileSystemReadFileTool tests
tests/mcp/tools/fileSystemReadFileTool.test.ts
Updated fs/promises import and mock configuration; added security check worker mocks; replaced vi.resetAllMocks() with vi.clearAllMocks(); expanded test cases for directory path errors, successful file reads with metadata, security check failures, I/O errors, and non-Error catch blocks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Mock setup complexity across two test files (fs/promises, securityCheckWorker, path mocking)
  • Multiple error scenario test cases require understanding of expected RepomixError behavior
  • Import and mock configuration changes need verification for consistency

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving test coverage for two specific modules (writeSkillOutput and fileSystemReadFileTool) with comprehensive new tests.
Description check ✅ Passed The description is comprehensive and includes all required template sections: detailed changes with coverage improvements for both modules and a completed checklist verifying npm run test and npm run lint were executed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yamadashy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on bolstering the test suite for critical file system interaction functions, specifically writeSkillOutput and fileSystemReadFileTool. By introducing a wide array of new test cases, it ensures that these utilities correctly handle various scenarios, including successful operations, permission issues, and other error conditions, thereby enhancing the overall stability and reliability of the system.

Highlights

  • Enhanced Test Coverage for writeSkillOutput: New tests have been added to cover the writing of techStack files and robust error handling for EPERM, EACCES, generic errors, and non-Error objects, significantly improving the reliability of skill output operations.
  • Improved Test Coverage for fileSystemReadFileTool: Comprehensive tests now validate the handling of directory paths, successful file reads, security check failures, general file reading errors, and non-Error object errors, making the file reading tool more resilient.
  • Overall Code Coverage Increase: This pull request boosts the overall code coverage from 89.81% to 90.28%, contributing to a more stable and thoroughly tested codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves test coverage for writeSkillOutput and fileSystemReadFileTool, which is a great addition. The new tests cover a good range of success and error scenarios. My review includes a few suggestions to enhance the new tests for better efficiency and robustness. I've identified some redundant function calls within the tests and a potential test-pollution issue that could affect test reliability. Addressing these points will further strengthen your test suite.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.36%. Comparing base (20ed7b3) to head (fa68654).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1008      +/-   ##
==========================================
+ Coverage   89.90%   90.36%   +0.46%     
==========================================
  Files         120      120              
  Lines        9241     9241              
  Branches     1685     1698      +13     
==========================================
+ Hits         8308     8351      +43     
+ Misses        933      890      -43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Dec 14, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: fa68654
Status: ✅  Deploy successful!
Preview URL: https://07aa74cf.repomix.pages.dev
Branch Preview URL: https://test-improve-coverage-for-sk.repomix.pages.dev

View logs

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Dec 14, 2025

PR Review: test(skill,mcp): improve test coverage for writeSkillOutput and fileSystemReadFileTool

Summary

This PR improves test coverage from 89.81% to 90.28% by adding comprehensive tests for writeSkillOutput.ts and fileSystemReadFileTool.ts. Overall, this is a well-structured PR that follows project conventions.


Code Quality

Positive observations:

  • Tests follow the project's dependency injection pattern for testability
  • Error scenarios are well-covered (EPERM, EACCES, generic errors, non-Error objects)
  • Tests are organized logically and are self-documenting
Minor Suggestions

1. fileSystemReadFileTool.test.ts - Mock import pattern

The current approach imports after vi.mock():

vi.mock('../../../src/core/security/workers/securityCheckWorker.js', () => ({...}));
import { runSecretLint } from '../../../src/core/security/workers/securityCheckWorker.js';

This works due to hoisting, but for clarity, consider grouping all imports at the top with explicit vi.mocked() usage in tests (which is already done). The current pattern is functional but could confuse readers.

2. writeSkillOutput.test.ts - Duplicate assertions in error tests

Tests for EPERM and generic errors call writeSkillOutput twice to verify different aspects:

await expect(writeSkillOutput(...)).rejects.toThrow(RepomixError);
await expect(writeSkillOutput(...)).rejects.toThrow(/Permission denied/);

Consider combining into a single call with a try-catch for more efficient testing:

await expect(writeSkillOutput(...)).rejects.toThrow(
  expect.objectContaining({
    message: expect.stringMatching(/Permission denied/)
  })
);

However, the current approach is clearer about what's being tested, so this is a stylistic preference.


Potential Issues

No critical issues found.

The tests correctly mock dependencies and verify expected behaviors.


Premortem Analysis

Potential failure scenarios and mitigations
Scenario Risk Mitigation
Mock module hoisting issues Low ✅ Already handled - vi.mock() is hoisted properly
Test flakiness from shared state Low vi.clearAllMocks() in beforeEach
Import path changes breaking tests Low Tests use relative imports matching src structure
Security check mock bypassing real validation Low Acceptable for unit tests; integration tests should cover real security checks

Edge cases not covered (optional future enhancements):

  • writeSkillOutput: Error during mkdir (currently only writeFile errors are tested)
  • fileSystemReadFileTool: Large file handling, binary file handling, symlink handling

These are minor and don't block this PR.


Verdict

✅ LGTM - This is a clean, focused PR that improves test coverage without introducing risks. The tests are well-written and follow project conventions.


🤖 Review by Claude Code

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
tests/core/skill/writeSkillOutput.test.ts (1)

165-194: Consider consolidating duplicate test invocations.

Similar to the EPERM test, this test invokes writeSkillOutput twice with identical mocks. See the suggestion for lines 108-138 for a consolidated approach.

🧹 Nitpick comments (1)
tests/core/skill/writeSkillOutput.test.ts (1)

108-138: Consider consolidating duplicate test invocations.

The test invokes writeSkillOutput twice with identical mocks—once to check the error type and again to check the message. This can be consolidated using a single invocation with chained assertions.

Apply this diff:

-    await expect(
-      writeSkillOutput(output, skillDir, {
-        mkdir: mockMkdir as unknown as typeof import('node:fs/promises').mkdir,
-        writeFile: mockWriteFile as unknown as typeof import('node:fs/promises').writeFile,
-      }),
-    ).rejects.toThrow(RepomixError);
-
-    await expect(
+    const promise = writeSkillOutput(output, skillDir, {
+      mkdir: mockMkdir as unknown as typeof import('node:fs/promises').mkdir,
+      writeFile: mockWriteFile as unknown as typeof import('node:fs/promises').writeFile,
+    });
+
+    await expect(promise).rejects.toThrow(RepomixError);
+    await expect(promise).rejects.toThrow(/Permission denied/);
+  });

Note: Remove the second writeSkillOutput call (lines 132-137) since both assertions can be applied to the same promise.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20ed7b3 and d1d5adc.

📒 Files selected for processing (2)
  • tests/core/skill/writeSkillOutput.test.ts (2 hunks)
  • tests/mcp/tools/fileSystemReadFileTool.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/core/skill/writeSkillOutput.test.ts (2)
src/core/skill/writeSkillOutput.ts (1)
  • writeSkillOutput (17-58)
src/shared/errorHandle.ts (1)
  • RepomixError (6-11)
🪛 GitHub Check: Lint TypeScript
tests/mcp/tools/fileSystemReadFileTool.test.ts

[failure] 157-157:
Argument of type 'string' is not assignable to parameter of type 'SuspiciousFileResult'.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test (macos-latest, 20.x)
  • GitHub Check: Test (ubuntu-latest, 22.x)
  • GitHub Check: Test (macos-latest, 24.x)
  • GitHub Check: Test (macos-latest, 22.x)
  • GitHub Check: Build and run (windows-latest, 24.x)
  • GitHub Check: Test (windows-latest, 20.x)
  • GitHub Check: Test (windows-latest, 24.x)
  • GitHub Check: Build and run (windows-latest, 25.x)
  • GitHub Check: Build and run with Bun (windows-latest, latest)
  • GitHub Check: Test with Bun (windows-latest, latest)
  • GitHub Check: claude-review
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (8)
tests/core/skill/writeSkillOutput.test.ts (2)

79-106: LGTM!

The test correctly validates that tech-stack.md is written when techStack is provided in the output references.


196-217: LGTM!

The test correctly validates that non-Error objects are handled and rethrown as RepomixError.

tests/mcp/tools/fileSystemReadFileTool.test.ts (6)

1-1: LGTM!

The changes to use the default export from node:fs/promises and the addition of security check worker mocks properly enable testing of file reading with security validation scenarios.

Also applies to: 8-21


31-31: LGTM!

Using clearAllMocks() is correct here since it preserves the mock implementations defined in vi.mock() while clearing call history between tests.


82-107: LGTM!

The test correctly validates that directory paths are rejected with an appropriate error message directing users to the correct tool.


109-142: LGTM!

The test thoroughly validates the successful file read path, including all metadata fields and both text and structured content formats.


178-195: LGTM!

The test correctly validates that general errors during file operations are caught and returned with appropriate error messages.


197-214: LGTM!

The test correctly validates that non-Error objects are handled gracefully with appropriate error messages.

…ystemReadFileTool

Add comprehensive tests to increase code coverage from 89.81% to 90.28%:

writeSkillOutput.ts (63.88% → 100%):
- Add test for techStack file writing
- Add tests for EPERM/EACCES error handling
- Add test for generic error handling
- Add test for non-Error object handling

fileSystemReadFileTool.ts (62.5% → 100%):
- Add test for directory path error
- Add test for successful file reading
- Add test for security check failure
- Add test for general errors during file reading
- Add test for non-Error object handling
@yamadashy yamadashy force-pushed the test/improve-coverage-for-skill-and-mcp branch from d1d5adc to cd2b7de Compare December 14, 2025 13:11
…request

Add command for resolving addressed PR review comments via GitHub GraphQL API.
Remove unused pr-review-request command.
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Dec 14, 2025

PR Review: test(skill,mcp): improve test coverage for writeSkillOutput and fileSystemReadFileTool

Summary

Good PR that improves test coverage from 89.81% to 90.36% by adding comprehensive tests for error handling in writeSkillOutput.ts and fileSystemReadFileTool.ts. The tests are well-structured and follow project conventions.


Code Quality Assessment

Strengths:

  • Tests follow the project's dependency injection pattern
  • Good coverage of error scenarios (EPERM, EACCES, generic errors, non-Error objects)
  • Security check integration is properly tested
  • Tests are well-organized and readable

Issue: vi.resetAllMocks() vs vi.clearAllMocks()

Details

In fileSystemReadFileTool.test.ts at line 31, vi.resetAllMocks() is used in beforeEach, but the mock implementations are defined at the top level with vi.mock(). This works because vi.mock() is hoisted and re-evaluated, but vi.clearAllMocks() would be more semantically correct here since you want to preserve the mock implementations while clearing call history.

The current code works but could be clearer:

// Current (line 31)
vi.resetAllMocks();

// More explicit (same behavior in this context, but clearer intent)
vi.clearAllMocks();

This is a minor stylistic point - the current code functions correctly.


Suggestion: Promise Reuse Pattern

Details

The error tests in writeSkillOutput.test.ts use a good pattern of storing the promise and asserting multiple times:

const promise = writeSkillOutput(output, skillDir, {...});
await expect(promise).rejects.toThrow(RepomixError);
await expect(promise).rejects.toThrow(/Permission denied/);

This is efficient and clean. No changes needed - just noting this as a good pattern.


Premortem Analysis

Risk Likelihood Mitigation
Mock hoisting issues Low ✅ Handled - vi.mock() is hoisted correctly
Test isolation/shared state Low beforeEach clears mocks between tests
Flaky tests Low Tests are deterministic with mocked I/O

Not covered (acceptable for unit tests):

  • writeSkillOutput: Error during mkdir operation (only writeFile errors tested)
  • fileSystemReadFileTool: Binary file handling, symlinks

These edge cases are acceptable to leave for integration tests.


Verdict

✅ LGTM - This is a clean, focused PR that improves test coverage without introducing risks. Ready to merge.


🤖 Generated with Claude Code

@yamadashy yamadashy merged commit b7f960e into main Dec 14, 2025
54 checks passed
@yamadashy yamadashy deleted the test/improve-coverage-for-skill-and-mcp branch December 14, 2025 13:22
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Dec 14, 2025

PR Review Update (2nd Review)

I previously reviewed this PR and gave it a LGTM. After reviewing the additional feedback from other reviewers, I have one follow-up observation:

Issue: vi.resetAllMocks() vs vi.clearAllMocks()

I notice the test file at tests/mcp/tools/fileSystemReadFileTool.test.ts:31 uses vi.resetAllMocks():

beforeEach(() => {
  vi.resetAllMocks();  // <-- This should be vi.clearAllMocks()
  ...
});

Problem: vi.resetAllMocks() will reset mock implementations to undefined, which could cause issues since the vi.mock() at the top of the file defines the implementations. vi.clearAllMocks() only clears the call history while preserving the mock implementations.

Details

The CodeRabbit review mentioned this was addressed (line 31), but looking at the current state of the test file, it still shows vi.resetAllMocks() in the beforeEach block. This could lead to flaky tests if the mock implementations are inadvertently reset between tests.

Recommendation: Change vi.resetAllMocks() to vi.clearAllMocks() to ensure mock implementations from vi.mock() blocks are preserved.

CodeRabbit's Suggestions

The CodeRabbit suggestions about consolidating duplicate assertions are valid optimizations but are stylistic preferences. The current pattern of separate assertions is clearer about what's being tested, so this is low priority.


Overall: This is still a solid PR that improves test coverage. The resetAllMocks vs clearAllMocks issue is minor but worth addressing for test reliability.

🤖 Review by Claude Code

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