"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-health-score';
function setupTestData() {
    const db = (0, database_1.getDb)();
    db.prepare('DELETE FROM memory_events WHERE project = ?').run(TEST_PROJECT);
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'decision', summary: 'Architecture choice', importance: 9 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: 'Build failure', importance: 7 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'fix', summary: 'Fixed build', importance: 8 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'verification', summary: 'Tests pass', importance: 6 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: 'Code update', importance: 3 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'handoff', summary: 'Session handoff', importance: 5 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'pattern', summary: 'Learned pattern', importance: 8 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'publish', summary: 'v1.0.0', importance: 7 });
}
describe('Memory Health Score', () => {
    beforeAll(() => { setupTestData(); });
    test('computeMemoryHealth returns valid result', () => {
        const { computeMemoryHealth } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        expect(health.project).toBe(TEST_PROJECT);
        expect(typeof health.overallScore).toBe('number');
        expect(health.overallScore).toBeGreaterThanOrEqual(0);
        expect(health.overallScore).toBeLessThanOrEqual(100);
    });
    test('grade is valid', () => {
        const { computeMemoryHealth } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        expect(['A+', 'A', 'B+', 'B', 'C+', 'C', 'D', 'F']).toContain(health.grade);
    });
    test('breakdown has all dimensions', () => {
        const { computeMemoryHealth } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        expect(typeof health.breakdown.completeness).toBe('number');
        expect(typeof health.breakdown.freshness).toBe('number');
        expect(typeof health.breakdown.quality).toBe('number');
        expect(typeof health.breakdown.balance).toBe('number');
        expect(typeof health.breakdown.engagement).toBe('number');
    });
    test('metrics are populated', () => {
        const { computeMemoryHealth } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        expect(health.metrics.totalEvents).toBe(8);
        expect(health.metrics.decisionsLogged).toBe(1);
        expect(health.metrics.errorsLogged).toBe(1);
        expect(health.metrics.fixesLogged).toBe(1);
        expect(health.metrics.verificationsLogged).toBe(1);
        expect(typeof health.metrics.patternsLearned).toBe('number');
    });
    test('suggestions is an array', () => {
        const { computeMemoryHealth } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        expect(Array.isArray(health.suggestions)).toBe(true);
    });
    test('formatHealthReport produces string', () => {
        const { computeMemoryHealth, formatHealthReport } = require('../walls/06-memory/stores/memory-health');
        const health = computeMemoryHealth(TEST_PROJECT);
        const report = formatHealthReport(health);
        expect(typeof report).toBe('string');
        expect(report).toContain('Memory Health');
        expect(report).toContain('Score');
    });
});
//# sourceMappingURL=memory-health.test.js.map