From d80de24e2ddaa49465eb5008b9d9099da4e16307 Mon Sep 17 00:00:00 2001 From: hzt <3061613175@qq.com> Date: Fri, 20 Feb 2026 12:52:25 +0800 Subject: [PATCH] test(output): add comprehensive tests for files:false option across all 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 #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 --- tests/cli/actions/defaultAction.test.ts | 18 ++++++ tests/config/configLoad.test.ts | 20 +++++++ tests/core/output/outputGenerate.test.ts | 71 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/tests/cli/actions/defaultAction.test.ts b/tests/cli/actions/defaultAction.test.ts index 4d5852a98..989023ece 100644 --- a/tests/cli/actions/defaultAction.test.ts +++ b/tests/cli/actions/defaultAction.test.ts @@ -305,6 +305,24 @@ describe('defaultAction', () => { expect(config.ignore?.useDefaultPatterns).toBe(false); }); + 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(); + }); + it('should handle --skill-generate with string name', () => { const options: CliOptions = { skillGenerate: 'my-skill', diff --git a/tests/config/configLoad.test.ts b/tests/config/configLoad.test.ts index aa221e7b4..a625b15ff 100644 --- a/tests/config/configLoad.test.ts +++ b/tests/config/configLoad.test.ts @@ -351,5 +351,25 @@ describe('configLoad', () => { const merged = mergeConfigs(process.cwd(), {}, { skillGenerate: 'from-cli' }); expect(merged.skillGenerate).toBe('from-cli'); }); + + test('should respect files: false from CLI config', () => { + const merged = mergeConfigs(process.cwd(), {}, { output: { files: false } }); + expect(merged.output.files).toBe(false); + }); + + test('should respect files: false from file config', () => { + const merged = mergeConfigs(process.cwd(), { output: { files: false } }, {}); + expect(merged.output.files).toBe(false); + }); + + test('should let CLI files: false override file config files: true', () => { + const merged = mergeConfigs(process.cwd(), { output: { files: true } }, { output: { files: false } }); + expect(merged.output.files).toBe(false); + }); + + test('should default files to true when not set in any config', () => { + const merged = mergeConfigs(process.cwd(), {}, {}); + expect(merged.output.files).toBe(true); + }); }); }); diff --git a/tests/core/output/outputGenerate.test.ts b/tests/core/output/outputGenerate.test.ts index 7f6a98430..df15bb27c 100644 --- a/tests/core/output/outputGenerate.test.ts +++ b/tests/core/output/outputGenerate.test.ts @@ -293,6 +293,77 @@ describe('outputGenerate', () => { expect(output).not.toContain('content1'); }); + 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(' { + const mockConfig = createMockConfig({ + output: { + filePath: 'output.xml', + style: 'xml', + parsableStyle: true, + files: false, + }, + }); + const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: '
foo
' }]; + + 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'); + }); + test('generateOutput should exclude directory structure when disabled', async () => { const mockConfig = createMockConfig({ output: {