Files
yamadashy--repomix/tests/core/git/gitRepositoryHandle.test.ts
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

113 lines
3.8 KiB
TypeScript

import { beforeEach, describe, expect, test, vi } from 'vitest';
import { getFileChangeCount, isGitInstalled, isGitRepository } from '../../../src/core/git/gitRepositoryHandle.js';
import { logger } from '../../../src/shared/logger.js';
vi.mock('../../../src/shared/logger');
describe('gitRepositoryHandle', () => {
beforeEach(() => {
vi.resetAllMocks();
});
describe('getFileChangeCount', () => {
test('should count file changes correctly', async () => {
const mockFilenames = ['file1.ts', 'file2.ts', 'file1.ts', 'file3.ts', 'file2.ts'];
const mockExecGitLogFilenames = vi.fn().mockResolvedValue(mockFilenames);
const result = await getFileChangeCount('/test/dir', 5, {
execGitLogFilenames: mockExecGitLogFilenames,
});
expect(result).toEqual({
'file1.ts': 2,
'file2.ts': 2,
'file3.ts': 1,
});
expect(mockExecGitLogFilenames).toHaveBeenCalledWith('/test/dir', 5);
});
test('should return empty object when git command fails', async () => {
const mockExecGitLogFilenames = vi.fn().mockRejectedValue(new Error('git command failed'));
const result = await getFileChangeCount('/test/dir', 5, {
execGitLogFilenames: mockExecGitLogFilenames,
});
expect(result).toEqual({});
expect(logger.trace).toHaveBeenCalledWith('Failed to get file change counts:', 'git command failed');
});
test('should handle empty git log output', async () => {
const mockExecGitLogFilenames = vi.fn().mockResolvedValue([]);
const result = await getFileChangeCount('/test/dir', 5, {
execGitLogFilenames: mockExecGitLogFilenames,
});
expect(result).toEqual({});
expect(mockExecGitLogFilenames).toHaveBeenCalledWith('/test/dir', 5);
});
});
describe('isGitRepository', () => {
test('should return true when directory is a git repository', async () => {
const mockExecGitRevParse = vi.fn().mockResolvedValue('true');
const result = await isGitRepository('/test/dir', {
execGitRevParse: mockExecGitRevParse,
});
expect(result).toBe(true);
expect(mockExecGitRevParse).toHaveBeenCalledWith('/test/dir');
});
test('should return false when directory is not a git repository', async () => {
const mockExecGitRevParse = vi.fn().mockRejectedValue(new Error('Not a git repository'));
const result = await isGitRepository('/test/dir', {
execGitRevParse: mockExecGitRevParse,
});
expect(result).toBe(false);
expect(mockExecGitRevParse).toHaveBeenCalledWith('/test/dir');
});
});
describe('isGitInstalled', () => {
test('should return true when git is installed', async () => {
const mockExecGitVersion = vi.fn().mockResolvedValue('git version 2.34.1');
const result = await isGitInstalled({
execGitVersion: mockExecGitVersion,
});
expect(result).toBe(true);
expect(mockExecGitVersion).toHaveBeenCalled();
});
test('should return false when git command fails', async () => {
const mockExecGitVersion = vi.fn().mockRejectedValue(new Error('Command not found: git'));
const result = await isGitInstalled({
execGitVersion: mockExecGitVersion,
});
expect(result).toBe(false);
expect(mockExecGitVersion).toHaveBeenCalled();
expect(logger.trace).toHaveBeenCalledWith('Git is not installed:', 'Command not found: git');
});
test('should return false when git version output contains error', async () => {
const mockExecGitVersion = vi.fn().mockResolvedValue('error: git not found');
const result = await isGitInstalled({
execGitVersion: mockExecGitVersion,
});
expect(result).toBe(false);
expect(mockExecGitVersion).toHaveBeenCalled();
});
});
});