import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { mkdtempSync, rmSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; import { Index } from '../src/core/index.js'; describe('index', () => { let cwd: string; beforeEach(() => { cwd = mkdtempSync(join(tmpdir(), 'agenthub-')); }); afterEach(() => { rmSync(cwd, { recursive: true, force: true }); }); it('indexes and searches a task', () => { const index = new Index(cwd); index.upsert({ id: 'TSK-0001', type: 'task', title: 'Implement DNS cache', content: 'Add local DNS cache for performance', filePath: join(cwd, '.agenthub', 'tasks', 'TSK-0001.md'), createdAt: '2026-06-24T10:00:00Z', updatedAt: '2026-06-24T10:00:00Z', }); const results = index.search('DNS'); expect(results).toHaveLength(1); expect(results[0].id).toBe('TSK-0001'); index.close(); }); });