"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../walls/06-memory/database/database");
const memory_insights_1 = require("../walls/06-memory/stores/memory-insights");
describe('Memory Insights', () => {
    beforeAll(() => {
        (0, database_1.getDb)();
    });
    afterEach(() => {
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_events WHERE project = ?').run('insights-test');
    });
    it('generateMemoryInsights returns empty for no data', () => {
        const insights = (0, memory_insights_1.generateMemoryInsights)('nonexistent-project');
        expect(Array.isArray(insights)).toBe(true);
    });
    it('getInsightSummary returns summary object', () => {
        const summary = (0, memory_insights_1.getInsightSummary)('nonexistent-project');
        expect(summary).toHaveProperty('total');
        expect(summary).toHaveProperty('byType');
        expect(summary).toHaveProperty('bySeverity');
        expect(summary).toHaveProperty('topInsights');
        expect(summary.total).toBe(0);
    });
    it('detects repeated error patterns', () => {
        // Insert multiple errors with same summary
        const db = (0, database_1.getDb)();
        for (let i = 0; i < 3; i++) {
            db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
         VALUES (?, 'error', 'TypeError: cannot read property', 7, datetime('now'))`).run('insights-test');
        }
        const insights = (0, memory_insights_1.generateMemoryInsights)('insights-test');
        const riskInsights = insights.filter(i => i.type === 'risk');
        expect(riskInsights.length).toBeGreaterThanOrEqual(1);
        expect(riskInsights[0].title).toContain('error pattern');
    });
    it('detects low verification events', () => {
        const db = (0, database_1.getDb)();
        for (let i = 0; i < 15; i++) {
            db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
         VALUES (?, 'edit', ?, 3, datetime('now'))`).run('insights-test', `Edit #${i}`);
        }
        const insights = (0, memory_insights_1.generateMemoryInsights)('insights-test');
        const recommendations = insights.filter(i => i.type === 'recommendation');
        expect(recommendations.length).toBeGreaterThanOrEqual(1);
    });
    it('detects activity trend changes', () => {
        const db = (0, database_1.getDb)();
        // Add events from 2 weeks ago (lower activity)
        for (let i = 0; i < 2; i++) {
            const oldDate = new Date(Date.now() - 14 * 86400000).toISOString();
            db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
         VALUES (?, 'edit', ?, 3, ?)`).run('insights-test', `Old edit ${i}`, oldDate);
        }
        // Add more recent events (higher activity)
        for (let i = 0; i < 10; i++) {
            db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
         VALUES (?, 'edit', ?, 3, datetime('now'))`).run('insights-test', `Recent edit ${i}`);
        }
        const insights = (0, memory_insights_1.generateMemoryInsights)('insights-test', 30);
        expect(insights.length).toBeGreaterThanOrEqual(1);
    });
    it('getInsightSummary with data', () => {
        const db = (0, database_1.getDb)();
        db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
       VALUES (?, 'decision', 'Choose React', 8, datetime('now'))`).run('insights-test');
        const summary = (0, memory_insights_1.getInsightSummary)('insights-test');
        expect(summary.total).toBeGreaterThanOrEqual(0);
    });
});
//# sourceMappingURL=memory-insights.test.js.map