"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../walls/06-memory/database/database");
const memory_event_store_1 = require("../walls/06-memory/stores/memory-event-store");
const context_ranker_1 = require("../walls/06-memory/stores/context-ranker");
describe('Context Ranker', () => {
    beforeAll(() => {
        (0, database_1.getDb)();
    });
    afterEach(() => {
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_events WHERE project = ?').run('ranker-test');
    });
    it('rankMemories returns empty for no data', () => {
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test' });
        expect(results).toEqual([]);
    });
    it('rankMemories ranks by importance', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'file_event', summary: 'Low importance', importance: 1 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'decision', summary: 'High importance', importance: 9 });
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test' });
        expect(results.length).toBe(2);
        expect(results[0].summary).toBe('High importance');
        expect(results[0].relevance).toBeGreaterThan(results[1].relevance);
    });
    it('rankMemories filters by query', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'edit', summary: 'Fixed autostart bug', importance: 5 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'edit', summary: 'Updated docs', importance: 5 });
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test', query: 'autostart' });
        expect(results.length).toBe(1);
        expect(results[0].summary).toContain('autostart');
    });
    it('rankMemories filters by minImportance', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'file_event', summary: 'Low', importance: 1 });
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'decision', summary: 'High', importance: 8 });
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test', minImportance: 5 });
        expect(results.length).toBe(1);
        expect(results[0].summary).toBe('High');
    });
    it('rankMemories limits results', () => {
        for (let i = 0; i < 10; i++) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'edit', summary: `Event ${i}`, importance: 5 });
        }
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test', maxResults: 3 });
        expect(results.length).toBe(3);
    });
    it('getTopMemoriesForContext returns within word limit', () => {
        for (let i = 0; i < 5; i++) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'decision', summary: `Decision ${i} about architecture`, importance: 8 });
        }
        const results = (0, context_ranker_1.getTopMemoriesForContext)('ranker-test', 100);
        expect(results.length).toBeLessThanOrEqual(5);
    });
    it('rankMemories boosts recency', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'ranker-test', type: 'edit', summary: 'Old event', importance: 5 });
        const results = (0, context_ranker_1.rankMemories)({ project: 'ranker-test' });
        expect(results.length).toBe(1);
        expect(results[0].relevance).toBeGreaterThan(0);
    });
});
//# sourceMappingURL=context-ranker.test.js.map