|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { execSync } from 'child_process'; |
| 3 | +import { tmpdir } from 'os'; |
| 4 | +import { mkdirSync, writeFileSync } from 'fs'; |
| 5 | +import { join } from 'path'; |
| 6 | + |
| 7 | +describe('Integration Tests', () => { |
| 8 | + const createTestRepo = () => { |
| 9 | + const repoPath = join(tmpdir(), `test-repo-${Date.now()}`); |
| 10 | + mkdirSync(repoPath, { recursive: true }); |
| 11 | + |
| 12 | + execSync('git init', { cwd: repoPath }); |
| 13 | + execSync('git config user.email "test@example.com"', { cwd: repoPath }); |
| 14 | + execSync('git config user.name "Test User"', { cwd: repoPath }); |
| 15 | + |
| 16 | + writeFileSync(join(repoPath, 'test.txt'), 'test content'); |
| 17 | + execSync('git add .', { cwd: repoPath }); |
| 18 | + execSync('git commit -m "Initial commit"', { cwd: repoPath }); |
| 19 | + |
| 20 | + return repoPath; |
| 21 | + }; |
| 22 | + |
| 23 | + describe('get_commit_stats', () => { |
| 24 | + it('should get stats from real repository', () => { |
| 25 | + const repoPath = createTestRepo(); |
| 26 | + const since = '2020-01-01'; |
| 27 | + |
| 28 | + const cmd = `git -C ${repoPath} log --since=${since} --pretty=format:'%H' --numstat`; |
| 29 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 30 | + |
| 31 | + expect(output).toContain('test.txt'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should handle author filter', () => { |
| 35 | + const repoPath = createTestRepo(); |
| 36 | + const author = 'test@example.com'; |
| 37 | + |
| 38 | + const cmd = `git -C ${repoPath} log --author=${author} --pretty=format:'%H'`; |
| 39 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 40 | + |
| 41 | + expect(output).toBeTruthy(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('get_author_metrics', () => { |
| 46 | + it('should get author stats', () => { |
| 47 | + const repoPath = createTestRepo(); |
| 48 | + const since = '2020-01-01'; |
| 49 | + |
| 50 | + const cmd = `git -C ${repoPath} log --since=${since} --pretty=format:'%an <%ae>' --numstat`; |
| 51 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 52 | + |
| 53 | + expect(output).toContain('Test User'); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('get_file_churn', () => { |
| 58 | + it('should identify changed files', () => { |
| 59 | + const repoPath = createTestRepo(); |
| 60 | + const since = '2020-01-01'; |
| 61 | + |
| 62 | + const cmd = `git -C ${repoPath} log --since=${since} --name-only --pretty=format:`; |
| 63 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 64 | + |
| 65 | + expect(output).toContain('test.txt'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('get_commit_patterns', () => { |
| 70 | + it('should get commit timestamps', () => { |
| 71 | + const repoPath = createTestRepo(); |
| 72 | + const since = '2020-01-01'; |
| 73 | + |
| 74 | + const cmd = `git -C ${repoPath} log --since=${since} --pretty=format:'%ad' --date=format:'%u %H'`; |
| 75 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 76 | + |
| 77 | + expect(output).toBeTruthy(); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('get_code_ownership', () => { |
| 82 | + it('should identify file authors', () => { |
| 83 | + const repoPath = createTestRepo(); |
| 84 | + |
| 85 | + const cmd = `git -C ${repoPath} ls-files`; |
| 86 | + const files = execSync(cmd, { encoding: 'utf-8' }).trim().split('\n'); |
| 87 | + |
| 88 | + expect(files).toContain('test.txt'); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe('get_velocity_trends', () => { |
| 93 | + it('should group commits by week', () => { |
| 94 | + const repoPath = createTestRepo(); |
| 95 | + const since = '2020-01-01'; |
| 96 | + |
| 97 | + const cmd = `git -C ${repoPath} log --since=${since} --pretty=format:'%ad' --date=format:'%Y-%m-%d'`; |
| 98 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 99 | + |
| 100 | + expect(output).toMatch(/\d{4}-\d{2}-\d{2}/); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + describe('get_collaboration_metrics', () => { |
| 105 | + it('should find files with multiple authors', () => { |
| 106 | + const repoPath = createTestRepo(); |
| 107 | + |
| 108 | + const cmd = `git -C ${repoPath} ls-files`; |
| 109 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 110 | + |
| 111 | + expect(output).toBeTruthy(); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + describe('get_quality_metrics', () => { |
| 116 | + it('should calculate commit sizes', () => { |
| 117 | + const repoPath = createTestRepo(); |
| 118 | + const since = '2020-01-01'; |
| 119 | + |
| 120 | + const cmd = `git -C ${repoPath} log --since=${since} --pretty=format:'%H' --numstat`; |
| 121 | + const output = execSync(cmd, { encoding: 'utf-8' }); |
| 122 | + |
| 123 | + const lines = output.split('\n'); |
| 124 | + let totalChanges = 0; |
| 125 | + |
| 126 | + for (const line of lines) { |
| 127 | + const match = line.match(/^(\d+)\s+(\d+)/); |
| 128 | + if (match) { |
| 129 | + totalChanges += parseInt(match[1]) + parseInt(match[2]); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + expect(totalChanges).toBeGreaterThan(0); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + describe('get_technical_debt', () => { |
| 138 | + it('should identify stale files', () => { |
| 139 | + const repoPath = createTestRepo(); |
| 140 | + |
| 141 | + const cmd = `git -C ${repoPath} ls-files`; |
| 142 | + const files = execSync(cmd, { encoding: 'utf-8' }).trim().split('\n'); |
| 143 | + |
| 144 | + expect(files.length).toBeGreaterThan(0); |
| 145 | + }); |
| 146 | + }); |
| 147 | +}); |
0 commit comments