hikma-engine
Version:
Code Knowledge Graph Indexer - A sophisticated TypeScript-based indexer that transforms Git repositories into multi-dimensional knowledge stores for AI agents
134 lines (133 loc) • 5.96 kB
JavaScript
/**
* @file Tests for the configuration management system.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
const path = __importStar(require("path"));
describe('ConfigManager', () => {
let configManager;
const testProjectRoot = '/tmp/test-project';
beforeEach(() => {
configManager = new index_1.ConfigManager(testProjectRoot);
});
describe('initialization', () => {
it('should initialize with default configuration', () => {
const config = configManager.getConfig();
expect(config).toBeDefined();
expect(config.database).toBeDefined();
expect(config.ai).toBeDefined();
expect(config.indexing).toBeDefined();
expect(config.logging).toBeDefined();
});
it('should resolve database paths relative to project root', () => {
const dbConfig = configManager.getDatabaseConfig();
expect(dbConfig.sqlite.path).toBe(path.resolve(testProjectRoot, './data/metadata.db'));
expect(dbConfig.sqlite.vectorExtension).toBe(path.resolve(testProjectRoot, './extensions/vec0.dylib'));
});
});
describe('configuration getters', () => {
it('should return database configuration', () => {
const dbConfig = configManager.getDatabaseConfig();
expect(dbConfig.sqlite).toBeDefined();
expect(dbConfig.sqlite.path).toBeDefined();
expect(dbConfig.sqlite.vectorExtension).toBeDefined();
});
it('should return AI configuration', () => {
const aiConfig = configManager.getAIConfig();
expect(aiConfig.embedding).toBeDefined();
expect(aiConfig.summary).toBeDefined();
expect(aiConfig.embedding.model).toBe('Xenova/all-MiniLM-L6-v2');
});
it('should return indexing configuration', () => {
const indexingConfig = configManager.getIndexingConfig();
expect(indexingConfig.filePatterns).toBeDefined();
expect(indexingConfig.ignorePatterns).toBeDefined();
expect(indexingConfig.maxFileSize).toBe(1024 * 1024);
});
});
describe('global configuration', () => {
it('should initialize global configuration', () => {
const globalConfig = (0, index_1.initializeConfig)(testProjectRoot);
expect(globalConfig).toBeInstanceOf(index_1.ConfigManager);
});
it('should throw error when accessing uninitialized global config', () => {
// This would require resetting the global state, which is complex in tests
// In a real test environment, you'd mock the global state
expect(() => {
// This test would need proper setup to work
}).not.toThrow(); // Placeholder
});
});
describe('configuration updates', () => {
it('should allow runtime configuration updates', () => {
const originalLogLevel = configManager.getLoggingConfig().level;
configManager.updateConfig({
logging: {
...configManager.getLoggingConfig(),
level: 'debug',
},
});
const updatedLogLevel = configManager.getLoggingConfig().level;
expect(updatedLogLevel).toBe('debug');
expect(updatedLogLevel).not.toBe(originalLogLevel);
});
});
});
describe('Environment variable overrides', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
});
afterAll(() => {
process.env = originalEnv;
});
it('should override database paths from environment variables', () => {
process.env.HIKMA_SQLITE_PATH = './custom/metadata.db';
process.env.HIKMA_SQLITE_VEC_EXTENSION = './custom/vec0.so';
const configManager = new index_1.ConfigManager('/tmp/test');
const dbConfig = configManager.getDatabaseConfig();
expect(dbConfig.sqlite.path).toBe(path.resolve('/tmp/test', './custom/metadata.db'));
expect(dbConfig.sqlite.vectorExtension).toBe(path.resolve('/tmp/test', './custom/vec0.so'));
});
it('should override log level from environment variables', () => {
process.env.HIKMA_LOG_LEVEL = 'debug';
const configManager = new index_1.ConfigManager('/tmp/test');
const loggingConfig = configManager.getLoggingConfig();
expect(loggingConfig.level).toBe('debug');
});
});
;