Enhances code extraction and project indexing

Adds support for Dart and Liquid languages with tree-sitter parsing.
Improves accuracy of code symbol extraction for existing languages.
Indexes project files to enhance code navigation features.
Migrates build system to facilitate code contributions.
Removes git hook functionality.
Integrates Sentry for error tracking and reporting.
Enhances project initialization and configuration loading.
This commit is contained in:
Colby McHenry
2026-02-09 22:18:59 -06:00
parent f0ddfccf47
commit d0ee6f7fc4
50 changed files with 3428 additions and 3332 deletions
+3 -243
View File
@@ -1,7 +1,9 @@
/**
* Sync Module Tests
*
* Tests for git hooks installation and sync functionality.
* Tests for sync functionality (incremental updates).
* Note: Git hooks functionality has been removed in favor of codegraph's
* Claude Code hooks integration.
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
@@ -11,248 +13,6 @@ import * as os from 'os';
import CodeGraph from '../src/index';
describe('Sync Module', () => {
describe('Git Hooks', () => {
let testDir: string;
let cg: CodeGraph;
beforeEach(() => {
testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-sync-test-'));
// Create a sample source file
const srcDir = path.join(testDir, 'src');
fs.mkdirSync(srcDir);
fs.writeFileSync(
path.join(srcDir, 'index.ts'),
`export function hello() { return 'world'; }`
);
// Initialize CodeGraph
cg = CodeGraph.initSync(testDir, {
config: {
include: ['**/*.ts'],
exclude: [],
},
});
});
afterEach(() => {
if (cg) {
cg.destroy();
}
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
});
describe('isGitRepository()', () => {
it('should return false for non-git directory', () => {
expect(cg.isGitRepository()).toBe(false);
});
it('should return true for git directory', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
expect(cg.isGitRepository()).toBe(true);
});
});
describe('isGitHookInstalled()', () => {
it('should return false when no hook is installed', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
expect(cg.isGitHookInstalled()).toBe(false);
});
it('should return false for non-codegraph hook', () => {
// Initialize git with a custom hook
const hooksDir = path.join(testDir, '.git', 'hooks');
fs.mkdirSync(path.join(testDir, '.git'));
fs.mkdirSync(hooksDir);
fs.writeFileSync(
path.join(hooksDir, 'post-commit'),
'#!/bin/sh\necho "custom hook"'
);
expect(cg.isGitHookInstalled()).toBe(false);
});
it('should return true when codegraph hook is installed', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
// Install hook
cg.installGitHooks();
expect(cg.isGitHookInstalled()).toBe(true);
});
});
describe('installGitHooks()', () => {
it('should fail if not a git repository', () => {
const result = cg.installGitHooks();
expect(result.success).toBe(false);
expect(result.message).toContain('Not a git repository');
});
it('should install hook in git repository', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
const result = cg.installGitHooks();
expect(result.success).toBe(true);
expect(result.message).toContain('installed');
// Verify hook file exists
const hookPath = path.join(testDir, '.git', 'hooks', 'post-commit');
expect(fs.existsSync(hookPath)).toBe(true);
// Verify hook content contains marker
const content = fs.readFileSync(hookPath, 'utf-8');
expect(content).toContain('CodeGraph auto-sync hook');
expect(content).toContain('codegraph sync');
});
it('should create hooks directory if missing', () => {
// Initialize git without hooks directory
fs.mkdirSync(path.join(testDir, '.git'));
const result = cg.installGitHooks();
expect(result.success).toBe(true);
expect(fs.existsSync(path.join(testDir, '.git', 'hooks'))).toBe(true);
});
it('should backup existing non-codegraph hook', () => {
// Initialize git with a custom hook
const hooksDir = path.join(testDir, '.git', 'hooks');
fs.mkdirSync(path.join(testDir, '.git'));
fs.mkdirSync(hooksDir);
const customHookContent = '#!/bin/sh\necho "custom hook"';
fs.writeFileSync(
path.join(hooksDir, 'post-commit'),
customHookContent
);
const result = cg.installGitHooks();
expect(result.success).toBe(true);
expect(result.previousHookBackedUp).toBe(true);
// Verify backup exists
const backupPath = path.join(hooksDir, 'post-commit.codegraph-backup');
expect(fs.existsSync(backupPath)).toBe(true);
expect(fs.readFileSync(backupPath, 'utf-8')).toBe(customHookContent);
});
it('should update existing codegraph hook without backup', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
// Install hook first time
cg.installGitHooks();
// Install again (update)
const result = cg.installGitHooks();
expect(result.success).toBe(true);
expect(result.message).toContain('updated');
expect(result.previousHookBackedUp).toBeUndefined();
});
it('should make hook executable', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
cg.installGitHooks();
const hookPath = path.join(testDir, '.git', 'hooks', 'post-commit');
const stats = fs.statSync(hookPath);
// Check executable bit (at least for owner)
expect(stats.mode & 0o100).toBeTruthy();
});
});
describe('removeGitHooks()', () => {
it('should succeed if no hook exists', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
const result = cg.removeGitHooks();
expect(result.success).toBe(true);
expect(result.message).toContain('No post-commit hook found');
});
it('should not remove non-codegraph hook', () => {
// Initialize git with a custom hook
const hooksDir = path.join(testDir, '.git', 'hooks');
fs.mkdirSync(path.join(testDir, '.git'));
fs.mkdirSync(hooksDir);
fs.writeFileSync(
path.join(hooksDir, 'post-commit'),
'#!/bin/sh\necho "custom hook"'
);
const result = cg.removeGitHooks();
expect(result.success).toBe(false);
expect(result.message).toContain('not installed by CodeGraph');
// Verify hook still exists
expect(fs.existsSync(path.join(hooksDir, 'post-commit'))).toBe(true);
});
it('should remove codegraph hook', () => {
// Initialize git
fs.mkdirSync(path.join(testDir, '.git'));
// Install then remove
cg.installGitHooks();
const result = cg.removeGitHooks();
expect(result.success).toBe(true);
expect(result.message).toContain('removed');
// Verify hook is gone
const hookPath = path.join(testDir, '.git', 'hooks', 'post-commit');
expect(fs.existsSync(hookPath)).toBe(false);
});
it('should restore backup when removing', () => {
// Initialize git with a custom hook
const hooksDir = path.join(testDir, '.git', 'hooks');
fs.mkdirSync(path.join(testDir, '.git'));
fs.mkdirSync(hooksDir);
const customHookContent = '#!/bin/sh\necho "custom hook"';
fs.writeFileSync(
path.join(hooksDir, 'post-commit'),
customHookContent
);
// Install (backs up custom hook) then remove
cg.installGitHooks();
const result = cg.removeGitHooks();
expect(result.success).toBe(true);
expect(result.restoredFromBackup).toBe(true);
// Verify original hook is restored
const hookPath = path.join(hooksDir, 'post-commit');
expect(fs.existsSync(hookPath)).toBe(true);
expect(fs.readFileSync(hookPath, 'utf-8')).toBe(customHookContent);
// Verify backup is gone
const backupPath = path.join(hooksDir, 'post-commit.codegraph-backup');
expect(fs.existsSync(backupPath)).toBe(false);
});
});
});
describe('Sync Functionality', () => {
let testDir: string;
let cg: CodeGraph;