mirror of
https://github.com/yamadashy/repomix.git
synced 2026-10-06 16:35:24 +02:00
- Update generateSummaryPurpose function to accept RepomixConfigMerged parameter - Add logic to differentiate between entire codebase vs subset in purpose description - Update function call in outputGenerate.ts to pass config parameter - Add comprehensive tests for both entire codebase and subset scenarios Previously, the summary purpose section always claimed the file contained "the entire repository's contents", even when repomix was configured to process only a subset of files (e.g., with include patterns). This created inconsistency with other parts of the output that correctly indicated when only a subset was processed. This change ensures the purpose section accurately describes the content as either "the entire repository's contents" or "a subset of the repository's contents that is considered the most important context" based on the actual file selection configuration.
170 lines
5.7 KiB
TypeScript
170 lines
5.7 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
analyzeContent,
|
|
generateHeader,
|
|
generateSummaryNotes,
|
|
generateSummaryPurpose,
|
|
generateSummaryUsageGuidelines,
|
|
} from '../../../src/core/output/outputStyleDecorate.js';
|
|
import { createMockConfig } from '../../testing/testUtils.js';
|
|
|
|
describe('analyzeContent', () => {
|
|
it('should detect entire codebase when using default settings', () => {
|
|
const config = createMockConfig();
|
|
const result = analyzeContent(config);
|
|
expect(result.selection.isEntireCodebase).toBe(true);
|
|
});
|
|
|
|
it('should detect subset when using include patterns', () => {
|
|
const config = createMockConfig({
|
|
include: ['src/**/*.ts'],
|
|
});
|
|
const result = analyzeContent(config);
|
|
expect(result.selection.isEntireCodebase).toBe(false);
|
|
expect(result.selection.include).toBe(true);
|
|
});
|
|
|
|
it('should detect processing states', () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
removeComments: true,
|
|
removeEmptyLines: true,
|
|
},
|
|
});
|
|
const result = analyzeContent(config);
|
|
expect(result.processing.commentsRemoved).toBe(true);
|
|
expect(result.processing.emptyLinesRemoved).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('generateHeader', () => {
|
|
const mockDate = '2025-01-29T11:23:01.763Z';
|
|
|
|
it('should generate header for entire codebase', () => {
|
|
const config = createMockConfig();
|
|
const header = generateHeader(config, mockDate);
|
|
expect(header).toContain('entire codebase');
|
|
expect(header).not.toContain('subset');
|
|
});
|
|
|
|
it('should generate header for subset with processing', () => {
|
|
const config = createMockConfig({
|
|
include: ['src/**/*.ts'],
|
|
output: {
|
|
removeComments: true,
|
|
},
|
|
});
|
|
const header = generateHeader(config, mockDate);
|
|
expect(header).toContain('subset of the codebase');
|
|
expect(header).toContain('comments have been removed');
|
|
});
|
|
|
|
it('should include security check disabled warning', () => {
|
|
const config = createMockConfig({
|
|
security: {
|
|
enableSecurityCheck: false,
|
|
},
|
|
});
|
|
const header = generateHeader(config, mockDate);
|
|
expect(header).toContain('security check has been disabled');
|
|
});
|
|
|
|
it('should include multiple processing states', () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
removeComments: true,
|
|
removeEmptyLines: true,
|
|
showLineNumbers: true,
|
|
},
|
|
});
|
|
const header = generateHeader(config, mockDate);
|
|
expect(header).toContain('comments have been removed');
|
|
expect(header).toContain('empty lines have been removed');
|
|
expect(header).toContain('line numbers have been added');
|
|
});
|
|
});
|
|
|
|
describe('generateSummaryPurpose', () => {
|
|
it('should generate consistent purpose text', () => {
|
|
const purpose = generateSummaryPurpose(createMockConfig());
|
|
expect(purpose).toContain('packed representation');
|
|
expect(purpose).toContain('AI systems');
|
|
expect(purpose).toContain('code review');
|
|
});
|
|
|
|
it('should indicate entire repository when using default settings', () => {
|
|
const config = createMockConfig();
|
|
const purpose = generateSummaryPurpose(config);
|
|
expect(purpose).toContain("entire repository's contents");
|
|
expect(purpose).not.toContain('subset');
|
|
});
|
|
|
|
it('should indicate subset when using include patterns', () => {
|
|
const config = createMockConfig({
|
|
include: ['src/**/*.ts'],
|
|
});
|
|
const purpose = generateSummaryPurpose(config);
|
|
expect(purpose).toContain("subset of the repository's contents that is considered the most important context");
|
|
expect(purpose).not.toContain('entire repository');
|
|
});
|
|
});
|
|
|
|
describe('generateSummaryUsageGuidelines', () => {
|
|
it('should include header text note when headerText is provided', () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
headerText: 'Custom header',
|
|
},
|
|
});
|
|
const guidelines = generateSummaryUsageGuidelines(config, '');
|
|
expect(guidelines).toContain('Repository Description');
|
|
});
|
|
|
|
it('should include instruction note when instruction is provided', () => {
|
|
const config = createMockConfig();
|
|
const guidelines = generateSummaryUsageGuidelines(config, 'Custom instruction');
|
|
expect(guidelines).toContain('Repository Instruction');
|
|
});
|
|
});
|
|
|
|
describe('generateSummaryNotes', () => {
|
|
it('should include selection information', () => {
|
|
const config = createMockConfig({
|
|
include: ['src/**/*.ts'],
|
|
ignore: {
|
|
customPatterns: ['*.test.ts'],
|
|
},
|
|
});
|
|
const notes = generateSummaryNotes(config);
|
|
expect(notes).toContain('Only files matching these patterns are included: src/**/*.ts');
|
|
expect(notes).toContain('Files matching these patterns are excluded: *.test.ts');
|
|
});
|
|
|
|
it('should include processing notes', () => {
|
|
const config = createMockConfig({
|
|
output: {
|
|
removeComments: true,
|
|
showLineNumbers: true,
|
|
style: 'xml',
|
|
parsableStyle: true,
|
|
},
|
|
security: {
|
|
enableSecurityCheck: false,
|
|
},
|
|
});
|
|
const notes = generateSummaryNotes(config);
|
|
expect(notes).toContain('Code comments have been removed');
|
|
expect(notes).toContain('Line numbers have been added');
|
|
expect(notes).toContain('Content has been formatted for parsing in xml style');
|
|
expect(notes).toContain('Security check has been disabled');
|
|
});
|
|
|
|
it('should handle case with minimal processing', () => {
|
|
const config = createMockConfig();
|
|
const notes = generateSummaryNotes(config);
|
|
expect(notes).toContain('Files matching patterns in .gitignore are excluded');
|
|
expect(notes).toContain('Files matching default ignore patterns are excluded');
|
|
expect(notes).not.toContain('Code comments have been removed');
|
|
});
|
|
});
|