import { describe, it, expect } from 'vitest';
import { rankByRelevance } from '../recall.js';
import type { MemoryEntry } from '../entries.js';

describe('rankByRelevance', () => {
  it('returns entries matching query keywords', () => {
    const entries: MemoryEntry[] = [
      { id: '1', topic: 'project', title: 'Style', content: 'Use two-space indentation', tags: ['style'] },
      { id: '2', topic: 'project', title: 'Tests', content: 'Use vitest for testing', tags: ['testing'] },
    ];
    const result = rankByRelevance('what indentation?', entries);
    expect(result).toHaveLength(1);
    expect(result[0].title).toBe('Style');
  });
});

describe('rankByHybrid', () => {
  it('falls back to BM25 when embeddings unavailable', async () => {
    const entries: MemoryEntry[] = [
      { id: '1', topic: 'project', title: 'Style', content: 'Use two-space indentation', tags: ['style'] },
      { id: '2', topic: 'project', title: 'Tests', content: 'Use vitest for testing', tags: ['testing'] },
    ];
    const { rankByHybrid } = await import('../recall.js');
    const result = await rankByHybrid('indentation style', entries);
    expect(result.length).toBeGreaterThan(0);
  });
});
