#!/usr/bin/env bun
/**
* Phase 2 Integration Test - Test all extractors
*/
import { extractCommitInfo } from './src/extractors/commit.js';
import { extractStagedChanges } from './src/extractors/staged.js';
import { extractUnstagedChanges } from './src/extractors/unstaged.js';
import { extractCodebaseInfo } from './src/extractors/codebase.js';
import { simpleGit } from 'simple-git';
const REPO_PATH = process.cwd();
async function testCommitExtractor() {
console.log('\nπ¦ Testing Commit Extractor...');
const git = simpleGit(REPO_PATH);
try {
// Get the latest commit
const log = await git.log({ maxCount: 1 });
if (log.all.length === 0) {
console.log('β οΈ No commits found, skipping commit extractor test');
return;
}
const commitHash = log.latest!.hash;
console.log(` Using commit: ${commitHash.slice(0, 8)}`);
const commitInfo = await extractCommitInfo(REPO_PATH, commitHash);
console.log(` β
Author: ${commitInfo.author}`);
console.log(` β
Message: ${commitInfo.message.split('\n')[0]}`);
console.log(` β
Files changed: ${commitInfo.files.length}`);
if (commitInfo.files.length > 0) {
console.log(` β
First file: ${commitInfo.files[0].path} (${commitInfo.files[0].status})`);
}
} catch (error) {
console.error(' β Error:', error instanceof Error ? error.message : String(error));
}
}
async function testUnstagedExtractor() {
console.log('\nπ¦ Testing Unstaged Changes Extractor...');
try {
const diffInfo = await extractUnstagedChanges(REPO_PATH);
console.log(` β
Type: ${diffInfo.type}`);
console.log(` β
Files changed: ${diffInfo.files.length}`);
console.log(` β
Total additions: ${diffInfo.totalStats.additions}`);
console.log(` β
Total deletions: ${diffInfo.totalStats.deletions}`);
if (diffInfo.files.length > 0) {
console.log(` β
First file: ${diffInfo.files[0].path} (${diffInfo.files[0].status})`);
} else {
console.log(' βΉοΈ No unstaged changes found');
}
} catch (error) {
console.error(' β Error:', error instanceof Error ? error.message : String(error));
}
}
async function testStagedExtractor() {
console.log('\nπ¦ Testing Staged Changes Extractor...');
try {
const diffInfo = await extractStagedChanges(REPO_PATH);
console.log(` β
Type: ${diffInfo.type}`);
console.log(` β
Files changed: ${diffInfo.files.length}`);
console.log(` β
Total additions: ${diffInfo.totalStats.additions}`);
console.log(` β
Total deletions: ${diffInfo.totalStats.deletions}`);
if (diffInfo.files.length > 0) {
console.log(` β
First file: ${diffInfo.files[0].path} (${diffInfo.files[0].status})`);
} else {
console.log(' βΉοΈ No staged changes found');
}
} catch (error) {
console.error(' β Error:', error instanceof Error ? error.message : String(error));
}
}
async function testCodebaseExtractor() {
console.log('\nπ¦ Testing Codebase Extractor...');
try {
const codebaseInfo = await extractCodebaseInfo(REPO_PATH);
console.log(` β
Root path: ${codebaseInfo.rootPath}`);
console.log(` β
Total files: ${codebaseInfo.totalFiles}`);
console.log(` β
Languages: ${codebaseInfo.languages.join(', ')}`);
console.log(` β
Structure root: ${codebaseInfo.structure.name}`);
console.log(` β
Top-level items: ${codebaseInfo.structure.children?.length || 0}`);
if (codebaseInfo.files.length > 0) {
const file = codebaseInfo.files[0];
console.log(` β
First file: ${file.relativePath} (${file.language}, ${file.lines} lines)`);
}
// Display a sample of the structure
console.log('\n π Directory structure (top level):');
codebaseInfo.structure.children?.slice(0, 5).forEach(child => {
const icon = child.type === 'directory' ? 'π' : 'π';
console.log(` ${icon} ${child.name}`);
});
if (codebaseInfo.structure.children && codebaseInfo.structure.children.length > 5) {
console.log(` ... and ${codebaseInfo.structure.children.length - 5} more`);
}
} catch (error) {
console.error(' β Error:', error instanceof Error ? error.message : String(error));
}
}
async function main() {
console.log('π§ͺ Phase 2 Integration Tests');
console.log('============================');
console.log(`Repository: ${REPO_PATH}`);
await testCommitExtractor();
await testUnstagedExtractor();
await testStagedExtractor();
await testCodebaseExtractor();
console.log('\nβ
All tests completed!');
}
main().catch(console.error);