"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 memory_compact_1 = require("../walls/06-memory/archive/memory-compact");
describe('Memory Compact', () => {
    beforeAll(() => {
        (0, database_1.getDb)();
    });
    afterEach(() => {
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_events WHERE project = ?').run('compact-test');
    });
    it('compactMemoryEvents always returns 0 (never delete raw events)', () => {
        const deleted = (0, memory_compact_1.compactMemoryEvents)(30);
        expect(deleted).toBe(0);
    });
    it('compactMemoryEvents returns 0 even with old low-importance events', () => {
        const db = (0, database_1.getDb)();
        const oldDate = new Date(Date.now() - 100 * 86400000).toISOString();
        db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
       VALUES (?, 'file_event', 'Old low', 1, ?)`).run('compact-test', oldDate);
        const deleted = (0, memory_compact_1.compactMemoryEvents)(90);
        expect(deleted).toBe(0);
    });
    it('compactMemoryEvents returns 0 for high-importance old events', () => {
        const db = (0, database_1.getDb)();
        const oldDate = new Date(Date.now() - 100 * 86400000).toISOString();
        db.prepare(`INSERT INTO memory_events (project, type, summary, importance, created_at)
       VALUES (?, 'decision', 'Old important', 8, ?)`).run('compact-test', oldDate);
        const deleted = (0, memory_compact_1.compactMemoryEvents)(90);
        expect(deleted).toBe(0);
    });
    it('getMemoryHealth returns stats', () => {
        (0, memory_event_store_1.recordMemoryEvent)({ project: 'compact-test', type: 'edit', summary: 'Test', importance: 3 });
        const health = (0, memory_compact_1.getMemoryHealth)(process.cwd());
        expect(health.eventCount).toBeGreaterThanOrEqual(1);
        expect(health.handoffLines).toBeGreaterThanOrEqual(0);
        expect(typeof health.oldestEvent).toBe('string');
    });
});
//# sourceMappingURL=memory-compact.test.js.map