test(output): Add comprehensive tests for files:false option across all styles - #1162
test(output): Add comprehensive tests for files:false option across all styles#1162hztBUAA wants to merge 1 commit into
Conversation
Summary of ChangesHello @hztBUAA, 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 significantly improves the test coverage for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
📝 WalkthroughWalkthroughThis PR adds test coverage for the --no-files CLI flag and its impact on output generation. Two test suites receive new test cases: one verifies CLI option handling converts the flag to config.output.files setting, and the other validates that generated outputs across multiple styles (XML, Markdown, JSON) exclude file sections when the flag is set. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
There was a problem hiding this comment.
Code Review
This pull request adds valuable test coverage for the files: false option across all output styles, which was previously only tested for the plain style. The changes look good and correctly verify the intended behavior. I've added a couple of suggestions to refactor the new tests using parameterized tests (test.each and it.each). This will help reduce code duplication and improve the maintainability of the test suite. Overall, great work on improving the test coverage!
| it('should handle --no-files flag', () => { | ||
| const options = { | ||
| files: false, | ||
| }; | ||
| const config = buildCliConfig(options); | ||
|
|
||
| expect(config.output?.files).toBe(false); | ||
| }); | ||
|
|
||
| it('should not set files in config when files option is true (Commander default)', () => { | ||
| const options = { | ||
| files: true, | ||
| }; | ||
| const config = buildCliConfig(options); | ||
|
|
||
| expect(config.output?.files).toBeUndefined(); | ||
| }); |
There was a problem hiding this comment.
These two tests for the files option can be combined into a single parameterized test using it.each. This makes the test cases more explicit and reduces boilerplate, improving maintainability.
it.each([
{ files: false, expected: false, description: 'should handle --no-files flag' },
{
files: true,
expected: undefined,
description: 'should not set files in config when files option is true (Commander default)',
},
])('$description', ({ files, expected }) => {
const options = {
files,
};
const config = buildCliConfig(options);
expect(config.output?.files).toBe(expected);
});| test('generateOutput should exclude files section in xml style when files is false', async () => { | ||
| const mockConfig = createMockConfig({ | ||
| output: { | ||
| filePath: 'output.xml', | ||
| style: 'xml', | ||
| files: false, | ||
| }, | ||
| }); | ||
| const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }]; | ||
|
|
||
| const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []); | ||
|
|
||
| expect(output).not.toContain('file1.txt'); | ||
| expect(output).not.toContain('content1'); | ||
| expect(output).not.toContain('<files>'); | ||
| }); | ||
|
|
||
| test('generateOutput should exclude files section in parsable xml style when files is false', async () => { | ||
| const mockConfig = createMockConfig({ | ||
| output: { | ||
| filePath: 'output.xml', | ||
| style: 'xml', | ||
| parsableStyle: true, | ||
| files: false, | ||
| }, | ||
| }); | ||
| const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: '<div>foo</div>' }]; | ||
|
|
||
| const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []); | ||
|
|
||
| const parser = new XMLParser({ ignoreAttributes: false }); | ||
| const parsedOutput = parser.parse(output); | ||
| expect(parsedOutput.repomix.files).toBeUndefined(); | ||
| }); | ||
|
|
||
| test('generateOutput should exclude files section in markdown style when files is false', async () => { | ||
| const mockConfig = createMockConfig({ | ||
| output: { | ||
| filePath: 'output.md', | ||
| style: 'markdown', | ||
| files: false, | ||
| }, | ||
| }); | ||
| const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }]; | ||
|
|
||
| const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []); | ||
|
|
||
| expect(output).not.toContain('## File: file1.txt'); | ||
| expect(output).not.toContain('content1'); | ||
| expect(output).not.toContain('# Files'); | ||
| }); | ||
|
|
||
| test('generateOutput should exclude files section in json style when files is false', async () => { | ||
| const mockConfig = createMockConfig({ | ||
| output: { | ||
| filePath: 'output.json', | ||
| style: 'json', | ||
| files: false, | ||
| }, | ||
| }); | ||
| const mockProcessedFiles: ProcessedFile[] = [ | ||
| { path: 'file1.txt', content: 'content1' }, | ||
| { path: 'file2.txt', content: 'content2' }, | ||
| ]; | ||
|
|
||
| const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []); | ||
|
|
||
| const parsed = JSON.parse(output); | ||
| expect(parsed).not.toHaveProperty('files'); | ||
| }); |
There was a problem hiding this comment.
These four new tests are very similar in structure. They can be consolidated into a single parameterized test using test.each to reduce code duplication and improve maintainability.
test.each([
{
description: 'xml style',
config: { filePath: 'output.xml', style: 'xml' as const },
processedFiles: [{ path: 'file1.txt', content: 'content1' }],
check: (output: string) => {
expect(output).not.toContain('file1.txt');
expect(output).not.toContain('content1');
expect(output).not.toContain('<files>');
},
},
{
description: 'parsable xml style',
config: { filePath: 'output.xml', style: 'xml' as const, parsableStyle: true },
processedFiles: [{ path: 'file1.txt', content: '<div>foo</div>' }],
check: (output: string) => {
const parser = new XMLParser({ ignoreAttributes: false });
const parsedOutput = parser.parse(output);
expect(parsedOutput.repomix.files).toBeUndefined();
},
},
{
description: 'markdown style',
config: { filePath: 'output.md', style: 'markdown' as const },
processedFiles: [{ path: 'file1.txt', content: 'content1' }],
check: (output: string) => {
expect(output).not.toContain('## File: file1.txt');
expect(output).not.toContain('content1');
expect(output).not.toContain('# Files');
},
},
{
description: 'json style',
config: { filePath: 'output.json', style: 'json' as const },
processedFiles: [
{ path: 'file1.txt', content: 'content1' },
{ path: 'file2.txt', content: 'content2' },
],
check: (output: string) => {
const parsed = JSON.parse(output);
expect(parsed).not.toHaveProperty('files');
},
},
])(
'generateOutput should exclude files section in $description when files is false',
async ({ config, processedFiles, check }) => {
const mockConfig = createMockConfig({
output: {
...config,
files: false,
},
});
const output = await generateOutput([process.cwd()], mockConfig, processedFiles, []);
check(output);
},
);…ll output styles Add test coverage for the `output.files: false` configuration option to ensure file contents are properly excluded across all output formats. This addresses the concern raised in yamadashy#1060. New tests: - buildCliConfig: --no-files flag mapping and Commander default handling - mergeConfigs: files:false from CLI, file config, CLI override, defaults - generateOutput: files:false for xml, parsable xml, markdown, json styles
5fbaf3d to
d80de24
Compare
|
Thanks for the review and feedback. I am following up on this PR now and will either push the requested changes or reply point-by-point shortly. |
|
Quick follow-up: I am reviewing the feedback and will update this PR shortly. |
Summary
Addresses #1060 by adding comprehensive test coverage for the
output.files: falseconfiguration option across all output styles and configuration paths.After thorough investigation, the
files: falseoption works correctly on the current main branch across all code paths (CLI options, config file, programmaticrunCliAPI). However, the test coverage was limited to only the plain text output style. This PR adds tests to ensure the behavior remains correct across all output formats and configuration paths.New tests added:
tests/cli/actions/defaultAction.test.ts(2 tests)--no-filesflag correctly maps tooutput.files: falsein CLI configfiles: truewhen--no-filesis not passed) does not override config file settingstests/config/configLoad.test.ts(4 tests)files: falsefrom CLI config is respected in merged configfiles: falsefrom file config is respected in merged configfiles: falseproperly overrides file configfiles: truefiles: truewhen not set anywheretests/core/output/outputGenerate.test.ts(5 tests)<file path=elements in outputfileskey isundefinedin parsed XML# Filessection or## File:entriesfilesproperty in parsed JSONInvestigation Notes
The
files: falseoption is correctly handled at every level:--no-files):buildCliConfig()mapsoptions.files === falsetocliConfig.output.files = falserepomix.config.json):output.files: falseis correctly loaded and mergedrunCli()):files: falsein options is correctly processed{{#if filesEnabled}}, and parsable xml/json generators checkrenderContext.filesEnabledThe reported issue may stem from placing
files: falseat the top level ofrepomix.config.jsoninstead of nesting it underoutput(i.e.,output: { files: false }). Top-levelfilesis silently ignored by the config schema.Checklist
npm run test- All 1105 tests pass (including 11 new)Fixes #1060