"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-growth';
function setupTestData() {
    const db = (0, database_1.getDb)();
    db.prepare('DELETE FROM memory_events WHERE project = ?').run(TEST_PROJECT);
    // Spread events over 10 days
    for (let i = 0; i < 10; i++) {
        const date = new Date(Date.now() - i * 86400000).toISOString();
        for (let j = 0; j < 3; j++) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: `Edit day ${i} #${j}`, importance: 3 });
        }
        if (i % 3 === 0) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'decision', summary: `Decision day ${i}`, importance: 8 });
        }
        if (i % 4 === 0) {
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: `Error day ${i}`, importance: 7 });
        }
    }
}
describe('Memory Growth Trends', () => {
    beforeAll(() => { setupTestData(); });
    test('computeGrowthTrends returns valid result', () => {
        const { computeGrowthTrends } = require('../walls/06-memory/stores/memory-growth');
        const trend = computeGrowthTrends(TEST_PROJECT, 30);
        expect(trend.project).toBe(TEST_PROJECT);
        expect(trend.period).toBe('30d');
        expect(Array.isArray(trend.dataPoints)).toBe(true);
        expect(typeof trend.summary.totalEvents).toBe('number');
        expect(typeof trend.prediction.next7dEstimate).toBe('number');
    });
    test('summary has required fields', () => {
        const { computeGrowthTrends } = require('../walls/06-memory/stores/memory-growth');
        const trend = computeGrowthTrends(TEST_PROJECT, 30);
        expect(trend.summary.totalEvents).toBeGreaterThan(0);
        expect(typeof trend.summary.avgDailyGrowth).toBe('number');
        expect(['accelerating', 'steady', 'decelerating', 'declining']).toContain(trend.summary.trend);
    });
    test('prediction has confidence', () => {
        const { computeGrowthTrends } = require('../walls/06-memory/stores/memory-growth');
        const trend = computeGrowthTrends(TEST_PROJECT, 30);
        expect(trend.prediction.confidence).toBeGreaterThanOrEqual(0);
        expect(trend.prediction.confidence).toBeLessThanOrEqual(1);
    });
    test('chart is string', () => {
        const { computeGrowthTrends } = require('../walls/06-memory/stores/memory-growth');
        const trend = computeGrowthTrends(TEST_PROJECT, 30);
        expect(typeof trend.chart).toBe('string');
        expect(trend.chart).toContain('Memory Growth');
    });
    test('formatGrowthTrend produces markdown', () => {
        const { computeGrowthTrends, formatGrowthTrend } = require('../walls/06-memory/stores/memory-growth');
        const trend = computeGrowthTrends(TEST_PROJECT, 30);
        const formatted = formatGrowthTrend(trend);
        expect(formatted).toContain('Memory Growth');
        expect(formatted).toContain('Summary');
    });
});
//# sourceMappingURL=memory-growth.test.js.map