Skip to content

feat: --no-file-summary now also suppresses generationHeader; doesn't suppress headerText (fixes #554) #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/core/output/outputGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,19 @@ const generateParsableXmlOutput = async (renderContext: RenderContext): Promise<
const xmlBuilder = new XMLBuilder({ ignoreAttributes: false });
const xmlDocument = {
repomix: {
'#text': renderContext.generationHeader,
file_summary: renderContext.fileSummaryEnabled
? {
'#text': 'This section contains a summary of this file.',
'#text': renderContext.generationHeader,
purpose: renderContext.summaryPurpose,
file_format: `${renderContext.summaryFileFormat}
4. Repository files, each consisting of:
- File path as an attribute
- Full contents of the file`,
usage_guidelines: renderContext.summaryUsageGuidelines,
notes: renderContext.summaryNotes,
additional_info: {
user_provided_header: renderContext.headerText,
},
}
: undefined,
user_provided_header: renderContext.headerText,
directory_structure: renderContext.directoryStructureEnabled ? renderContext.treeString : undefined,
files: renderContext.filesEnabled
? {
Expand Down
7 changes: 3 additions & 4 deletions src/core/output/outputStyles/markdownStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Handlebars from 'handlebars';

export const getMarkdownTemplate = () => {
return /* md */ `
{{#if fileSummaryEnabled}}
{{{generationHeader}}}

{{#if fileSummaryEnabled}}
# File Summary

## Purpose
Expand All @@ -22,11 +22,10 @@ export const getMarkdownTemplate = () => {
## Notes
{{{summaryNotes}}}

## Additional Info
{{/if}}
{{#if headerText}}
### User Provided Header
# User Provided Header
{{{headerText}}}
{{/if}}

{{/if}}
{{#if directoryStructureEnabled}}
Expand Down
12 changes: 6 additions & 6 deletions src/core/output/outputStyles/plainStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const PLAIN_LONG_SEPARATOR = '='.repeat(64);

export const getPlainTemplate = () => {
return `
{{#if fileSummaryEnabled}}
{{{generationHeader}}}

{{#if fileSummaryEnabled}}
${PLAIN_LONG_SEPARATOR}
File Summary
${PLAIN_LONG_SEPARATOR}
Expand All @@ -32,13 +32,13 @@ Notes:
------
{{{summaryNotes}}}

Additional Info:
----------------
{{/if}}

{{#if headerText}}
User Provided Header:
-----------------------
${PLAIN_LONG_SEPARATOR}
User Provided Header
${PLAIN_LONG_SEPARATOR}
{{{headerText}}}
{{/if}}

{{/if}}
{{#if directoryStructureEnabled}}
Expand Down
11 changes: 4 additions & 7 deletions src/core/output/outputStyles/xmlStyle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const getXmlTemplate = () => {
return /* xml */ `
{{#if fileSummaryEnabled}}
{{{generationHeader}}}

{{#if fileSummaryEnabled}}
<file_summary>
This section contains a summary of this file.

Expand All @@ -25,16 +25,13 @@ This section contains a summary of this file.
{{{summaryNotes}}}
</notes>

<additional_info>
</file_summary>

{{/if}}
{{#if headerText}}
<user_provided_header>
{{{headerText}}}
</user_provided_header>
{{/if}}

</additional_info>

</file_summary>

{{/if}}
{{#if directoryStructureEnabled}}
Expand Down
49 changes: 49 additions & 0 deletions tests/core/output/outputGenerate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,53 @@ describe('outputGenerate', () => {
expect(output).toContain('## File: dir/file2.txt');
expect(output).toContain('````\n```\ncontent2\n```\n````');
});

test('generateOutput (txt) should omit generationHeader when fileSummaryEnabled is false, but always include headerText if provided', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.txt',
style: 'plain',
fileSummary: false,
headerText: 'ALWAYS SHOW THIS HEADER',
},
});
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];
const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);
expect(output).not.toContain('This file is a merged representation'); // generationHeader
expect(output).toContain('ALWAYS SHOW THIS HEADER');
});

test('generateOutput (xml) omits generationHeader when fileSummaryEnabled is false, but always includes headerText', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.xml',
style: 'xml',
fileSummary: false,
headerText: 'XML HEADER',
parsableStyle: true,
},
});
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['#text']).toBeUndefined();
expect(parsedOutput.repomix.user_provided_header).toBe('XML HEADER');
});

test('generateOutput (markdown) omits generationHeader when fileSummaryEnabled is false, but always includes headerText', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.md',
style: 'markdown',
fileSummary: false,
headerText: 'MARKDOWN HEADER',
parsableStyle: false,
},
});
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];
const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);
expect(output).not.toContain('This file is a merged representation');
expect(output).toContain('MARKDOWN HEADER');
});
});
35 changes: 33 additions & 2 deletions tests/core/output/outputStyles/markdownStyle.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Handlebars from 'handlebars';
import { describe, expect, test } from 'vitest';
import { generateOutput } from '../../../../src/core/output/outputGenerate.js';
import { getMarkdownTemplate } from '../../../../src/core/output/outputStyles/markdownStyle.js';
import { createMockConfig } from '../../../testing/testUtils.js';

describe('markdownStyle', () => {
describe('getMarkdownTemplate', () => {
Expand Down Expand Up @@ -59,7 +61,7 @@ describe('markdownStyle', () => {

const result = compiledTemplate(data);

expect(result).toContain('### User Provided Header');
expect(result).toContain('# User Provided Header');
expect(result).toContain('Custom Header Text');
});

Expand All @@ -74,7 +76,7 @@ describe('markdownStyle', () => {

const result = compiledTemplate(data);

expect(result).not.toContain('### User Provided Header');
expect(result).not.toContain('# User Provided Header');
});

test('should render instruction section when provided', () => {
Expand All @@ -92,6 +94,35 @@ describe('markdownStyle', () => {
expect(result).toContain('# Instruction');
expect(result).toContain('Custom Instruction Text');
});

test('should display headerText if specified even if fileSummary is disabled', () => {
const template = getMarkdownTemplate();
const compiledTemplate = Handlebars.compile(template);
const data = {
headerText: 'MARKDOWN HEADER',
fileSummaryEnabled: false,
directoryStructureEnabled: true,
processedFiles: [],
};
const result = compiledTemplate(data);
expect(result).not.toContain('This file is a merged representation');
expect(result).toContain('MARKDOWN HEADER');
});

test('should not display generationHeader if fileSummary is disabled', () => {
const template = getMarkdownTemplate();
const compiledTemplate = Handlebars.compile(template);
const data = {
generationHeader: 'Generated Test Header',
fileSummaryEnabled: false,
directoryStructureEnabled: true,
processedFiles: [],
};
const result = compiledTemplate(data);
expect(result).not.toContain('This file is a merged representation');
expect(result).not.toContain('Generated Test Header');
expect(result).toContain('# Directory Structure');
});
});

describe('getFileExtension helper', () => {
Expand Down
14 changes: 14 additions & 0 deletions tests/core/output/outputStyles/plainStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ describe('plainStyle', () => {
expect(output).toContain('Custom header text');
expect(output).toContain('Files');
});

test('plain style: headerText always present, generationHeader only if fileSummaryEnabled', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.txt',
style: 'plain',
fileSummary: false,
headerText: 'PLAIN HEADER',
},
});
const output = await generateOutput([process.cwd()], mockConfig, [], []);
expect(output).not.toContain('This file is a merged representation');
expect(output).toContain('PLAIN HEADER');
});
});
15 changes: 15 additions & 0 deletions tests/core/output/outputStyles/xmlStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ describe('xmlStyle', () => {
expect(output).toContain('Custom header text');
expect(output).toContain('files');
});

test('xml style: headerText always present, generationHeader only if fileSummaryEnabled', async () => {
const mockConfig = createMockConfig({
output: {
filePath: 'output.xml',
style: 'xml',
fileSummary: false,
headerText: 'XML HEADER',
parsableStyle: false,
},
});
const output = await generateOutput([process.cwd()], mockConfig, [], []);
expect(output).not.toContain('This file is a merged representation');
expect(output).toContain('XML HEADER');
});
});
Loading
Loading