719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
162 lines
5.4 KiB
TypeScript
162 lines
5.4 KiB
TypeScript
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
import type { RepomixConfigMerged } from '../../../src/config/configSchema.js';
|
|
import type { ProcessedFile } from '../../../src/core/file/fileTypes.js';
|
|
import * as gitDiffModule from '../../../src/core/git/gitDiffHandle.js';
|
|
import * as gitRepositoryModule from '../../../src/core/git/gitRepositoryHandle.js';
|
|
import { pack } from '../../../src/core/packager.js';
|
|
import { createMockConfig } from '../../testing/testUtils.js';
|
|
|
|
// Mock the dependencies
|
|
vi.mock('../../../src/core/git/gitDiffHandle.js', () => ({
|
|
getWorkTreeDiff: vi.fn(),
|
|
getStagedDiff: vi.fn(),
|
|
getGitDiffs: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../../../src/core/git/gitRepositoryHandle.js', () => ({
|
|
isGitRepository: vi.fn(),
|
|
isGitInstalled: vi.fn().mockResolvedValue(false),
|
|
getFileChangeCount: vi.fn().mockResolvedValue({}),
|
|
}));
|
|
|
|
describe('Git Diffs Functionality', () => {
|
|
let mockConfig: RepomixConfigMerged;
|
|
const mockRootDir = '/test/repo';
|
|
const sampleDiff = `diff --git a/file1.js b/file1.js
|
|
index 123..456 100644
|
|
--- a/file1.js
|
|
+++ b/file1.js
|
|
@@ -1,5 +1,5 @@
|
|
-old line
|
|
+new line
|
|
`;
|
|
|
|
beforeEach(() => {
|
|
vi.resetAllMocks();
|
|
|
|
// Sample minimal config using createMockConfig utility
|
|
mockConfig = createMockConfig({
|
|
cwd: mockRootDir,
|
|
output: {
|
|
filePath: 'repomix-output.txt',
|
|
style: 'plain',
|
|
git: {
|
|
includeDiffs: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
// Set up our mocks
|
|
vi.mocked(gitRepositoryModule.isGitRepository).mockResolvedValue(true);
|
|
vi.mocked(gitDiffModule.getWorkTreeDiff).mockResolvedValue(sampleDiff);
|
|
vi.mocked(gitDiffModule.getStagedDiff).mockResolvedValue('');
|
|
});
|
|
|
|
test('should not fetch diffs when includeDiffs is disabled', async () => {
|
|
// Mock the dependencies for pack
|
|
const mockSearchFiles = vi.fn().mockResolvedValue({ filePaths: [] });
|
|
const mockCollectFiles = vi.fn().mockResolvedValue({ rawFiles: [], skippedFiles: [] });
|
|
const mockProcessFiles = vi.fn().mockResolvedValue([]);
|
|
const mockValidateFileSafety = vi.fn().mockResolvedValue({
|
|
safeFilePaths: [],
|
|
safeRawFiles: [],
|
|
suspiciousFilesResults: [],
|
|
});
|
|
const mockProduceOutput = vi.fn().mockResolvedValue({
|
|
outputForMetrics: 'mocked output',
|
|
});
|
|
const mockCalculateMetrics = vi.fn().mockResolvedValue({
|
|
totalFiles: 0,
|
|
totalCharacters: 0,
|
|
totalTokens: 0,
|
|
fileCharCounts: {},
|
|
fileTokenCounts: {},
|
|
});
|
|
const mockSortPaths = vi.fn().mockImplementation((paths) => paths);
|
|
const mockCreateMetricsTaskRunner = vi.fn().mockReturnValue({
|
|
taskRunner: {
|
|
run: vi.fn().mockResolvedValue(0),
|
|
cleanup: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
warmupPromise: Promise.resolve(),
|
|
});
|
|
|
|
// Config with diffs disabled
|
|
if (mockConfig.output.git) {
|
|
mockConfig.output.git.includeDiffs = false;
|
|
}
|
|
|
|
await pack([mockRootDir], mockConfig, vi.fn(), {
|
|
searchFiles: mockSearchFiles,
|
|
collectFiles: mockCollectFiles,
|
|
processFiles: mockProcessFiles,
|
|
validateFileSafety: mockValidateFileSafety,
|
|
produceOutput: mockProduceOutput,
|
|
calculateMetrics: mockCalculateMetrics,
|
|
createMetricsTaskRunner: mockCreateMetricsTaskRunner,
|
|
sortPaths: mockSortPaths,
|
|
});
|
|
|
|
// Should not call getWorkTreeDiff
|
|
expect(gitDiffModule.getWorkTreeDiff).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should calculate diff token count correctly', async () => {
|
|
// Create a processed files array with a sample file
|
|
const processedFiles: ProcessedFile[] = [
|
|
{
|
|
path: 'test.js',
|
|
content: 'console.log("test");',
|
|
},
|
|
];
|
|
|
|
// Mock dependencies
|
|
const mockSearchFiles = vi.fn().mockResolvedValue({ filePaths: ['test.js'] });
|
|
const mockCollectFiles = vi.fn().mockResolvedValue({ rawFiles: processedFiles, skippedFiles: [] });
|
|
const mockProcessFiles = vi.fn().mockResolvedValue(processedFiles);
|
|
const mockValidateFileSafety = vi.fn().mockResolvedValue({
|
|
safeFilePaths: ['test.js'],
|
|
safeRawFiles: processedFiles,
|
|
suspiciousFilesResults: [],
|
|
});
|
|
const mockProduceOutput = vi.fn().mockResolvedValue({
|
|
outputForMetrics: 'Generated output with diffs included',
|
|
});
|
|
const mockCalculateMetrics = vi.fn().mockResolvedValue({
|
|
totalFiles: 1,
|
|
totalCharacters: 30,
|
|
totalTokens: 10,
|
|
fileCharCounts: { 'test.js': 10 },
|
|
fileTokenCounts: { 'test.js': 5 },
|
|
gitDiffTokenCount: 15, // Mock diff token count
|
|
});
|
|
const mockSortPaths = vi.fn().mockImplementation((paths) => paths);
|
|
const mockCreateMetricsTaskRunner = vi.fn().mockReturnValue({
|
|
taskRunner: {
|
|
run: vi.fn().mockResolvedValue(0),
|
|
cleanup: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
warmupPromise: Promise.resolve(),
|
|
});
|
|
|
|
// Config with diffs enabled
|
|
if (mockConfig.output.git) {
|
|
mockConfig.output.git.includeDiffs = true;
|
|
}
|
|
|
|
const result = await pack([mockRootDir], mockConfig, vi.fn(), {
|
|
searchFiles: mockSearchFiles,
|
|
collectFiles: mockCollectFiles,
|
|
processFiles: mockProcessFiles,
|
|
validateFileSafety: mockValidateFileSafety,
|
|
produceOutput: mockProduceOutput,
|
|
calculateMetrics: mockCalculateMetrics,
|
|
createMetricsTaskRunner: mockCreateMetricsTaskRunner,
|
|
sortPaths: mockSortPaths,
|
|
});
|
|
|
|
// Check gitDiffTokenCount in the result
|
|
expect(result.gitDiffTokenCount).toBe(15);
|
|
});
|
|
});
|