"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const prompt_builder_1 = require("../walls/01-context/context/prompt-builder");
const mockDb = {
    prepare: jest.fn(),
};
jest.mock('../walls/06-memory/database/database', () => ({
    getDb: () => mockDb,
}));
function fakeStmt(rows) {
    return {
        all: (..._args) => rows,
        get: (..._args) => rows[0] || undefined,
    };
}
function setupRichMocks() {
    mockDb.prepare.mockReset();
    mockDb.prepare.mockImplementation((sql) => {
        const s = sql.trim().toUpperCase();
        if (s.startsWith('SELECT * FROM DEVELOPER_PROFILES')) {
            return fakeStmt([{
                    id: 1, project: 'fivo-cell', files_scanned: 100, total_lines: 5000,
                    naming_style: 'camelCase', quote_style: 'single', semicolon_style: 'always',
                    indent_style: '2-spaces', async_style: 'uses-async', error_handling: 'try-catch',
                    test_pattern: 'jest', strengths: '["Uses async/await"]', improvements: '["Add error handling"]',
                    scanned_at: new Date().toISOString(),
                }]);
        }
        if (s.includes('CODE_PATTERNS')) {
            if (s.includes("CATEGORY = 'BLIND_SPOTS'") || s.includes("CATEGORY = 'BLIND_SPOTS' AND")) {
                return fakeStmt([{ pattern_type: 'blind_spot_async_notry', pattern_value: 'async missing try/catch', category: 'blind_spots', count: 14, trust_score: 88 }]);
            }
            if (s.startsWith('SELECT PATTERN_VALUE FROM CODE_PATTERNS'))
                return fakeStmt([]);
            return fakeStmt([{ pattern_type: 'naming', pattern_value: 'camelCase', category: 'naming', count: 50, trust_score: 92 }]);
        }
        if (s.startsWith('SELECT * FROM SCANS'))
            return fakeStmt([{ id: 1, project: 'fivo-cell', started_at: new Date().toISOString(), completed_at: new Date().toISOString(), files_scanned: 100 }]);
        if (s.startsWith('SELECT * FROM ERROR_LOG'))
            return fakeStmt([]);
        if (s.startsWith('SELECT PATTERN_VALUE FROM CODE_PATTERNS'))
            return fakeStmt([]);
        if (s.startsWith('SELECT * FROM SESSIONS')) {
            return fakeStmt([{ id: 5, tool_name: 'cursor', project: 'fivo-cell', start_time: new Date().toISOString(), end_time: new Date(Date.now() - 7200000).toISOString(), files_touched: '["src/foo.ts"]', key_decisions: '["used better-sqlite3"]', context_snapshot: 'working on X' }]);
        }
        if (s.includes('SESSION_APPROACHES') && s.includes('GROUP BY')) {
            return fakeStmt([{ approach: 'chokidar', status: 'failed', count: 2, last_reason: 'too heavy', last_seen: new Date().toISOString() }]);
        }
        if (s.startsWith('SELECT FILE_PATH') && s.includes('SESSION_FILES')) {
            return fakeStmt([{ file_path: 'src/foo.ts', total_touches: 8, session_count: 3, last_touched: new Date().toISOString() }]);
        }
        if (s.startsWith('SELECT * FROM SESSION_QUESTIONS')) {
            return fakeStmt([{ id: 1, session_id: 5, project: 'fivo-cell', question: 'How to detect tool switch?', priority: 'high', resolved: 0, answer: null, created_at: new Date().toISOString(), resolved_at: null }]);
        }
        return fakeStmt([]);
    });
}
describe('tool-specific formatting (Unit 2.5)', () => {
    beforeEach(() => setupRichMocks());
    it('Claude Code format: @cell block with sections', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        // Pre-Launch Test 7: header uses ⚡ CELL CONTEXT — <project>
        expect(out).toContain('⚡ CELL CONTEXT');
        expect(out).toContain('fivo-cell');
        // New section markers
        expect(out).toContain('📦 PROJECT');
        expect(out).toContain('Stack:');
        expect(out).toContain('⚠️ BLIND SPOTS');
        expect(out).toContain('🎯 LAST SESSION');
        // Footer
        expect(out).toContain('End @cell Context');
    });
    it('Pre-Launch Test 7: divider lines wrap the header', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        const divider = '━'.repeat(15);
        // Header is wrapped with two divider lines
        const dividerMatches = out.match(new RegExp(divider, 'g')) || [];
        expect(dividerMatches.length).toBeGreaterThanOrEqual(2);
    });
    it('Pre-Launch Test 7: real project name appears (not "Fivo-Cell" literal)', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        expect(out).toContain('⚡ CELL CONTEXT — fivo-cell');
    });
    it('Pre-Launch Test 7: blind spots show as → file:line style', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        // blind spot section uses → prefix
        expect(out).toMatch(/⚠️ BLIND SPOTS:[\s\S]*→/);
    });
    it('Pre-Launch Test 7: last session shows working-on task', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        expect(out).toMatch(/🎯 LAST SESSION[\s\S]*Working on:/);
    });
    it('@cell block works for @cell token (canonical name)', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', '@cell');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, '@cell');
        expect(out).toContain('⚡ CELL CONTEXT');
        expect(out).toContain('📦 PROJECT');
    });
    it('@cell block works for cell-block token', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'cell-block');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'cell-block');
        expect(out).toContain('⚡ CELL CONTEXT');
        expect(out).toContain('📦 PROJECT');
    });
    it('Cursor format: structured, no narrative, focused on hot files + style + decisions', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'cursor');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'cursor');
        expect(out).toContain('@context');
        expect(out).toContain('style:');
        expect(out).toContain('hot:');
        expect(out).toContain('avoid:');
        expect(out).not.toContain('━━━');
        expect(out).not.toContain('▸');
    });
    it('Windsurf format: balanced markdown, focused on next-step suggestions', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'windsurf');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'windsurf');
        expect(out).toContain('# Cell Context');
        expect(out).toContain('##');
        expect(out).toContain('try/catch');
        expect(out).toContain('tool switch');
    });
    it('GitHub Copilot format: ultra-compact one-liner (inline completion context)', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'copilot');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'copilot');
        expect(out.length).toBeLessThan(500);
        expect(out).not.toContain('\n\n');
    });
    it('Antigravity format: structured with code blocks', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'antigravity');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'antigravity');
        expect(out).toContain('```');
        expect(out).toContain('fivo-cell');
    });
    it('Unknown tool: falls back to @cell block', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'unknown-tool');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'unknown-tool');
        // Falls back to the new visual @cell block
        expect(out).toContain('⚡ CELL CONTEXT');
        expect(out).toContain('📦 PROJECT');
    });
    it('formatContextForTool is case-insensitive', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude');
        const out1 = (0, prompt_builder_1.formatContextForTool)(ctx, 'CLAUDE-CODE');
        const out2 = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        expect(out1).toBe(out2);
    });
    it('Cursor format includes tried approaches as "avoid" list', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'cursor');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'cursor');
        expect(out).toContain('chokidar');
        expect(out).toContain('failed');
    });
    it('Windsurf format includes open questions as bullet list', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'windsurf');
        const out = (0, prompt_builder_1.formatContextForTool)(ctx, 'windsurf');
        expect(out).toContain('tool switch');
        expect(out).toContain('high');
    });
    it('Claude Code format is longest (>200 chars)', () => {
        const ctx = (0, prompt_builder_1.buildContext)('fivo-cell', 'claude-code');
        const claude = (0, prompt_builder_1.formatContextForTool)(ctx, 'claude-code');
        const copilot = (0, prompt_builder_1.formatContextForTool)(ctx, 'copilot');
        expect(claude.length).toBeGreaterThan(200);
        expect(copilot.length).toBeLessThan(claude.length);
    });
});
//# sourceMappingURL=tool-specific-format.test.js.map