"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 TEST_PROJECT = 'test-recommendations';
function setupTestData() {
    const db = (0, database_1.getDb)();
    db.prepare('DELETE FROM memory_events WHERE project = ?').run(TEST_PROJECT);
    // Errors without fixes
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: 'TypeError in auth module', importance: 8, topic: 'auth' });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: 'SQL injection vulnerability', importance: 9, topic: 'security' });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: 'Null pointer in handler', importance: 6, topic: 'bugfix' });
    // Edits to same file
    for (let i = 0; i < 10; i++) {
        (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: `Edit #${i}`, files: ['src/auth.ts'], importance: 3 });
    }
    // Decisions
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'decision', summary: 'Use JWT for auth', importance: 8 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'decision', summary: 'Switch to PostgreSQL', importance: 9 });
    // Some verifications
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'verification', summary: 'Tests pass', importance: 6 });
}
describe('Smart Recommendations', () => {
    beforeAll(() => { setupTestData(); });
    test('generates recommendations', () => {
        const { generateSmartRecommendations } = require('../walls/06-memory/stores/smart-recommendations');
        const recs = generateSmartRecommendations(TEST_PROJECT);
        expect(Array.isArray(recs)).toBe(true);
        expect(recs.length).toBeGreaterThan(0);
    });
    test('recommendations have required fields', () => {
        const { generateSmartRecommendations } = require('../walls/06-memory/stores/smart-recommendations');
        const recs = generateSmartRecommendations(TEST_PROJECT);
        for (const r of recs) {
            expect(r.id).toBeDefined();
            expect(['action', 'focus', 'improve', 'learn', 'prevent', 'optimize']).toContain(r.category);
            expect(['high', 'medium', 'low']).toContain(r.priority);
            expect(r.title).toBeDefined();
            expect(r.description).toBeDefined();
            expect(r.rationale).toBeDefined();
            expect(typeof r.confidence).toBe('number');
        }
    });
    test('detects unfixed errors', () => {
        const { generateSmartRecommendations } = require('../walls/06-memory/stores/smart-recommendations');
        const recs = generateSmartRecommendations(TEST_PROJECT);
        const fixRecs = recs.filter((r) => r.title.startsWith('Fix:'));
        expect(fixRecs.length).toBeGreaterThan(0);
    });
    test('detects file hotspots', () => {
        const { generateSmartRecommendations } = require('../walls/06-memory/stores/smart-recommendations');
        const recs = generateSmartRecommendations(TEST_PROJECT);
        const refactorRecs = recs.filter((r) => r.category === 'optimize');
        expect(refactorRecs.length).toBeGreaterThan(0);
    });
    test('getRecommendationSummary returns counts', () => {
        const { getRecommendationSummary } = require('../walls/06-memory/stores/smart-recommendations');
        const summary = getRecommendationSummary(TEST_PROJECT);
        expect(summary.total).toBeGreaterThan(0);
        expect(typeof summary.high).toBe('number');
        expect(typeof summary.medium).toBe('number');
        expect(typeof summary.low).toBe('number');
        expect(summary.top3).toBeDefined();
    });
    test('sorted by priority', () => {
        const { generateSmartRecommendations } = require('../walls/06-memory/stores/smart-recommendations');
        const recs = generateSmartRecommendations(TEST_PROJECT);
        const prioMap = { high: 0, medium: 1, low: 2 };
        for (let i = 1; i < recs.length; i++) {
            expect(prioMap[recs[i].priority]).toBeGreaterThanOrEqual(prioMap[recs[i - 1].priority]);
        }
    });
});
//# sourceMappingURL=smart-recommendations.test.js.map