"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-error-trends';
function setupTestData() {
    const db = (0, database_1.getDb)();
    db.prepare('DELETE FROM memory_events WHERE project = ?').run(TEST_PROJECT);
    for (let i = 0; i < 10; i++) {
        (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: `Edit ${i}`, importance: 3 });
        if (i % 2 === 0)
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: `Error ${i}`, importance: 7 });
        if (i % 3 === 0)
            (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'fix', summary: `Fix ${i}`, importance: 8 });
    }
}
describe('Error Trend Analysis', () => {
    beforeAll(() => { setupTestData(); });
    test('computeErrorTrends returns valid result', () => {
        const { computeErrorTrends } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        expect(trend.project).toBe(TEST_PROJECT);
        expect(typeof trend.summary.totalErrors).toBe('number');
        expect(typeof trend.summary.errorRate).toBe('number');
        expect(Array.isArray(trend.dailyTrend)).toBe(true);
    });
    test('summary has required fields', () => {
        const { computeErrorTrends } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        expect(trend.summary.totalErrors).toBe(5);
        expect(['improving', 'stable', 'worsening']).toContain(trend.summary.trend);
    });
    test('fix rate computed', () => {
        const { computeErrorTrends } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        expect(typeof trend.fixRate.rate).toBe('number');
        expect(trend.fixRate.rate).toBeGreaterThanOrEqual(0);
        expect(trend.fixRate.rate).toBeLessThanOrEqual(100);
    });
    test('chart is string', () => {
        const { computeErrorTrends } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        expect(typeof trend.chart).toBe('string');
        expect(trend.chart).toContain('Error Trend');
    });
    test('topErrors has entries', () => {
        const { computeErrorTrends } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        expect(trend.topErrors.length).toBeGreaterThan(0);
        expect(trend.topErrors[0].summary).toBeDefined();
        expect(typeof trend.topErrors[0].fixed).toBe('boolean');
    });
    test('formatErrorTrend produces markdown', () => {
        const { computeErrorTrends, formatErrorTrend } = require('../walls/06-memory/stores/error-trends');
        const trend = computeErrorTrends(TEST_PROJECT, 30);
        const formatted = formatErrorTrend(trend);
        expect(formatted).toContain('Error Trend');
        expect(formatted).toContain('Summary');
    });
});
//# sourceMappingURL=error-trends.test.js.map