"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-compression';
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: 'Use gzip for compression', importance: 8, topic: 'performance' });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'error', summary: 'Memory leak in handler', importance: 7, topic: 'bugfix' });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'fix', summary: 'Fixed memory leak with cleanup', importance: 8, topic: 'bugfix' });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'edit', summary: 'Updated config', importance: 3 });
    (0, memory_event_store_1.recordMemoryEvent)({ project: TEST_PROJECT, type: 'verification', summary: 'Tests pass after fix', importance: 6 });
}
describe('Context Compression', () => {
    beforeAll(() => { setupTestData(); });
    test('compressContext returns valid result', () => {
        const { compressContext } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressContext({ project: TEST_PROJECT });
        expect(ctx.project).toBe(TEST_PROJECT);
        expect(['compact', 'full', 'topic']).toContain(ctx.mode);
        expect(typeof ctx.tokenEstimate).toBe('number');
        expect(Array.isArray(ctx.sections)).toBe(true);
        expect(ctx.compressedAt).toBeDefined();
    });
    test('compact mode has fewer sections than full', () => {
        const { compressContext } = require('../walls/06-memory/stores/context-compression');
        const compact = compressContext({ project: TEST_PROJECT, mode: 'compact' });
        const full = compressContext({ project: TEST_PROJECT, mode: 'full' });
        expect(full.sections.length).toBeGreaterThanOrEqual(compact.sections.length);
    });
    test('topic filter works', () => {
        const { compressContext } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressContext({ project: TEST_PROJECT, mode: 'topic', topic: 'bugfix' });
        expect(ctx.sections.length).toBeGreaterThan(0);
    });
    test('maxWords limits output', () => {
        const { compressContext } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressContext({ project: TEST_PROJECT, maxWords: 50 });
        let totalWords = 0;
        for (const s of ctx.sections)
            totalWords += s.wordCount;
        expect(totalWords).toBeLessThanOrEqual(100);
    });
    test('sections have required fields', () => {
        const { compressContext } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressContext({ project: TEST_PROJECT });
        for (const s of ctx.sections) {
            expect(s.type).toBeDefined();
            expect(s.title).toBeDefined();
            expect(s.content).toBeDefined();
            expect(typeof s.wordCount).toBe('number');
            expect(typeof s.importance).toBe('number');
            expect(typeof s.compressed).toBe('boolean');
        }
    });
    test('compressToMinimal works', () => {
        const { compressToMinimal } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressToMinimal(TEST_PROJECT);
        expect(ctx.mode).toBe('compact');
        expect(ctx.tokenEstimate).toBeLessThan(1000);
    });
    test('compressForAITool returns tool-specific context', () => {
        const { compressForAITool } = require('../walls/06-memory/stores/context-compression');
        const cursor = compressForAITool(TEST_PROJECT, 'cursor');
        const claude = compressForAITool(TEST_PROJECT, 'claude-code');
        expect(cursor.tokenEstimate).toBeLessThanOrEqual(claude.tokenEstimate);
    });
    test('formatCompressedContext produces string', () => {
        const { compressContext, formatCompressedContext } = require('../walls/06-memory/stores/context-compression');
        const ctx = compressContext({ project: TEST_PROJECT });
        const formatted = formatCompressedContext(ctx);
        expect(typeof formatted).toBe('string');
        expect(formatted).toContain('Context');
    });
});
//# sourceMappingURL=context-compression.test.js.map