Skip to content

Conversation

@yamadashy
Copy link
Owner

Summary

This PR adds comprehensive test coverage for the issue reported in #959 where .ignore files are allegedly ignored when customPatterns is defined in the configuration.

What's Included

  • Config merge behavior tests
  • Integration tests with actual .ignore files
  • Zod schema parsing tests

Current Status

All tests pass, indicating that the reported issue cannot be reproduced in the current codebase (v1.9.1). Further investigation is needed to understand the exact reproduction steps.

Checklist

  • Run npm run test
  • Run npm run lint
  • Identify root cause if bug exists
  • Implement fix if needed

Add comprehensive test coverage to verify that .ignore files work correctly
when customPatterns is defined in the configuration. These tests serve as
regression tests for issue #959.

Tests added:
- Config merge behavior when customPatterns is defined
- Integration test with actual .ignore files and customPatterns
- Zod schema parsing behavior for ignore configuration

All tests currently pass, indicating the reported issue cannot be reproduced
in the current codebase.

Related to #959
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Important

Review skipped

Draft detected.

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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/959-dotignore-with-custom-patterns

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 23, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4eeb116
Status: ✅  Deploy successful!
Preview URL: https://6195c699.repomix.pages.dev
Branch Preview URL: https://fix-959-dotignore-with-custo.repomix.pages.dev

View logs

@codecov
Copy link

codecov bot commented Nov 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (a63546b) to head (4eeb116).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #960   +/-   ##
=======================================
  Coverage   89.68%   89.68%           
=======================================
  Files         111      111           
  Lines        7843     7843           
  Branches     1504     1504           
=======================================
  Hits         7034     7034           
  Misses        809      809           

☔ 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.

@claude
Copy link
Contributor

claude bot commented Nov 23, 2025

PR Review - Test Coverage for Issue #959

I've reviewed the test additions for investigating the .ignore file behavior with customPatterns. Here's my comprehensive feedback:

✅ Strengths

Well-Structured Test Coverage

The PR provides three complementary test layers that effectively cover the issue:

  1. Unit tests for config merge behavior (configMerge.test.ts)
  2. Schema validation tests for Zod parsing (configSchema.zod.test.ts)
  3. Integration tests with actual file system (fileSearch.ignore.integration.test.ts)

This layered approach is excellent for isolating potential issues at different levels.

Good Test Design

  • Integration tests properly create/cleanup temporary directories
  • Tests verify both positive and negative cases
  • Clear, descriptive test names that explain what's being tested
  • Tests follow the existing patterns in the codebase
🔍 Issues & Recommendations

1. Schema Test Reveals a Potential Root Cause

In configSchema.zod.test.ts:11-18, the test expects useDotIgnore to be undefined when not provided:

const result = repomixConfigFileSchema.parse(input);
// useDotIgnore should not be set when not provided in input
expect(result.ignore?.useDotIgnore).toBeUndefined();

This is actually revealing the likely bug! When users define only customPatterns in their config, useDotIgnore remains undefined from the schema parse. Then in configLoad.ts:213-222, the merge spreads the file config:

ignore: {
  ...baseConfig.ignore,      // useDotIgnore: true
  ...fileConfig.ignore,      // useDotIgnore: undefined (overwrites!)
  ...cliConfig.ignore,
  // ...
}

When spreading an object with useDotIgnore: undefined, it overwrites the default true value with undefined, which could be falsy in some contexts.

2. Integration Test May Have False Negatives

In fileSearch.ignore.integration.test.ts:38, you explicitly set all ignore flags:

ignore: {
  useGitignore: false,
  useDotIgnore: true,  // ← Explicitly set
  useDefaultPatterns: false,
  customPatterns: ['bin/'],
}

This doesn't reproduce the user's scenario! The bug report says users define ONLY customPatterns. The test should be:

ignore: {
  customPatterns: ['bin/'],  // Only this, like the user's config
}

Then rely on createMockConfig to apply defaults, which would expose whether the merge logic properly preserves useDotIgnore: true.

3. createMockConfig May Hide the Bug

In testUtils.ts:30-34, createMockConfig explicitly spreads defaultConfig.ignore:

ignore: {
  ...defaultConfig.ignore,  // Always applies defaults
  ...config.ignore,
  // ...
}

This works differently than the actual mergeConfigs function, potentially masking the bug. The test environment should match production behavior.

🎯 Recommendations for Next Steps

To Reproduce the Bug:

  1. Modify the integration test to use only customPatterns without explicitly setting other flags
  2. Don't use createMockConfig - instead call mergeConfigs directly with a fileConfig that mimics the user's exact scenario:
    const fileConfig: RepomixConfigFile = {
      ignore: {
        customPatterns: ['bin/'],
      }
    };
    const merged = mergeConfigs(testDir, fileConfig, {});
  3. Verify the merged config before testing file search:
    expect(merged.ignore.useDotIgnore).toBe(true); // This might fail!

To Fix the Bug:

The merge logic in configLoad.ts:213-222 should filter out undefined values or use a smarter merge strategy:

ignore: {
  ...baseConfig.ignore,
  ...(fileConfig.ignore ? Object.fromEntries(
    Object.entries(fileConfig.ignore).filter(([_, v]) => v !== undefined)
  ) : {}),
  ...(cliConfig.ignore ? Object.fromEntries(
    Object.entries(cliConfig.ignore).filter(([_, v]) => v !== undefined)
  ) : {}),
  customPatterns: [
    ...(baseConfig.ignore.customPatterns || []),
    ...(fileConfig.ignore?.customPatterns || []),
    ...(cliConfig.ignore?.customPatterns || []),
  ],
}

Or better yet, merge each field individually with null-coalescing:

ignore: {
  useGitignore: cliConfig.ignore?.useGitignore ?? fileConfig.ignore?.useGitignore ?? baseConfig.ignore.useGitignore,
  useDotIgnore: cliConfig.ignore?.useDotIgnore ?? fileConfig.ignore?.useDotIgnore ?? baseConfig.ignore.useDotIgnore,
  // ...
}
⚡ Premortem Analysis - Potential Failure Scenarios

Edge Cases to Test:

  1. Partial config override: User sets useGitignore: false but not useDotIgnore - does useDotIgnore remain true?
  2. CLI override: CLI customPatterns combined with file config customPatterns - are both preserved?
  3. Nested config files: Global config + local config both with customPatterns
  4. Empty customPatterns array: Does customPatterns: [] cause the same issue as having patterns?
  5. TypeScript/JS configs: The bug might behave differently with export default { ignore: { customPatterns: [...] } }

Integration Issues:

  • globby behavior: The ignoreFiles parameter uses separate config than ignore patterns. If .ignore isn't in ignoreFiles, it won't be read.
  • Priority conflicts: What if .ignore says include and customPatterns says exclude the same file?

Deployment Risks:

  • Breaking change: If the fix changes merge behavior, existing users with explicit useDotIgnore: false in their configs might see different behavior
  • Migration: Users who worked around the bug by not using customPatterns will need to update configs
📋 Minor Issues

Code Quality:

  1. fileSearch.ignore.integration.test.ts:15: The fixture directory ignore-test-temp could conflict if tests run in parallel. Consider using a unique name per test or using vitest's test context.

  2. configMerge.test.ts:22: Comment says "should not be affected by customPatterns" but this is the bug being investigated! If the bug exists, this test might pass incorrectly.

  3. Missing test: No test for when useDotIgnore is explicitly false AND customPatterns is defined - this should respect the explicit false.


Summary

The tests are well-structured but may not expose the bug due to test utilities that differ from production behavior. The schema test actually hints at the root cause: undefined values overwriting defaults during object spread. I recommend updating tests to more closely match the user's scenario and testing the mergeConfigs output directly before implementing a fix.


const result = repomixConfigFileSchema.parse(input);

// useDotIgnore should not be set when not provided in input
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is revealing the likely root cause of issue #959!

When repomixConfigFileSchema.parse() receives a config with only customPatterns, it returns an object where useDotIgnore is undefined (not present). Then when mergeConfigs() does:

ignore: {
  ...baseConfig.ignore,      // useDotIgnore: true
  ...fileConfig.ignore,      // useDotIgnore: undefined
  ...cliConfig.ignore,
}

The spread of fileConfig.ignore will include useDotIgnore: undefined, which overwrites the default true value.

Recommendation: This is actually the expected Zod behavior - it only includes fields that are explicitly set. The fix should be in mergeConfigs() to handle undefined values properly (see my main review comment for solutions).

Comment on lines +34 to +35
const config = createMockConfig({
ignore: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical issue: This test doesn't match the bug scenario reported in #959!

The bug report shows users defining ONLY customPatterns:

{
  "ignore": {
    "customPatterns": ["bin/"]
  }
}

But this test explicitly sets all flags including useDotIgnore: true. This could mask the bug if the issue is that useDotIgnore defaults aren't being applied properly when only customPatterns is defined.

Suggested change
const config = createMockConfig({
ignore: {
// Create config with ONLY customPatterns (matching user's scenario in #959)
const fileConfig: RepomixConfigFile = {
ignore: {
customPatterns: ['bin/'],
},
};
const cliConfig: RepomixConfigCli = {};
const config = mergeConfigs(testDir, fileConfig, cliConfig);
// Verify the merge preserved the default useDotIgnore: true
expect(config.ignore.useDotIgnore).toBe(true);

This would test the actual merge behavior and expose whether the bug exists.


const merged = mergeConfigs(cwd, fileConfig, cliConfig);

// useDotIgnore should be true by default and should not be affected by customPatterns
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment states this "should not be affected" but that's exactly what we're testing for in #959!

If the bug exists, this assertion might actually fail (which would be correct - exposing the bug). Consider adding an explicit check:

// useDotIgnore should be true by default and should not be affected by customPatterns
expect(merged.ignore.useDotIgnore).toBe(true);

Also, it would be valuable to verify what the fileConfig.ignore object looks like after Zod parsing to confirm whether useDotIgnore is undefined or not present.

try {
await fs.rm(testDir, { recursive: true, force: true });
} catch {
// Ignore errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential test isolation issue: Using a fixed directory name ignore-test-temp could cause conflicts if tests run in parallel or if cleanup fails.

Consider using a unique directory per test run:

const testDir = path.join(process.cwd(), 'tests/fixtures', `ignore-test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);

Or use vitest's test context to ensure proper isolation.

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.

2 participants