"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const vibe_confidence_1 = require("../walls/06-memory/vibe/vibe-confidence");
const vibe_engine_1 = require("../walls/06-memory/vibe/vibe-engine");
function makeTmpDir() {
    const dir = path.join(os.tmpdir(), `vibe-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
    fs.mkdirSync(dir, { recursive: true });
    const vibeDir = path.join(dir, '.cell', 'vibe');
    fs.mkdirSync(vibeDir, { recursive: true });
    return dir;
}
function cleanTmpDir(dir) {
    try {
        fs.rmSync(dir, { recursive: true, force: true });
    }
    catch { }
}
describe('Vibe Confidence Engine', () => {
    test('calculateVibe returns 0 for 0 signals', () => {
        expect((0, vibe_confidence_1.calculateVibe)(0, 10)).toBe(0);
    });
    test('vibe grows with count', () => {
        const low = (0, vibe_confidence_1.calculateVibe)(1, 10);
        const mid = (0, vibe_confidence_1.calculateVibe)(5, 10);
        const high = (0, vibe_confidence_1.calculateVibe)(15, 10);
        expect(low).toBeLessThan(mid);
        expect(mid).toBeLessThan(high);
    });
    test('vibe caps at 100', () => {
        const vibe = (0, vibe_confidence_1.calculateVibe)(100, 50, 1.3);
        expect(vibe).toBeLessThanOrEqual(100);
    });
    test('multiplier increases vibe', () => {
        const base = (0, vibe_confidence_1.calculateVibe)(5, 10, 1.0);
        const boosted = (0, vibe_confidence_1.calculateVibe)(5, 10, 1.3);
        expect(boosted).toBeGreaterThan(base);
    });
    test('evolveVibe blends old and new', () => {
        const evolved = (0, vibe_confidence_1.evolveVibe)(50, true, 4, 10, 1.0);
        expect(evolved).toBeGreaterThan(50);
    });
    test('evolveVibe decays with no evidence', () => {
        const evolved = (0, vibe_confidence_1.evolveVibe)(80, false, 5, 10);
        expect(evolved).toBe(79);
    });
    test('getVibeLevel returns correct levels', () => {
        expect((0, vibe_confidence_1.getVibeLevel)(0)).toBe('uncertain');
        expect((0, vibe_confidence_1.getVibeLevel)(50)).toBe('learning');
        expect((0, vibe_confidence_1.getVibeLevel)(65)).toBe('strong');
        expect((0, vibe_confidence_1.getVibeLevel)(80)).toBe('very_strong');
        expect((0, vibe_confidence_1.getVibeLevel)(95)).toBe('certain');
    });
    test('shouldWriteToFile threshold at 50', () => {
        expect((0, vibe_confidence_1.shouldWriteToFile)(49)).toBe(false);
        expect((0, vibe_confidence_1.shouldWriteToFile)(50)).toBe(true);
    });
    test('shouldShowInContext threshold at 65', () => {
        expect((0, vibe_confidence_1.shouldShowInContext)(64)).toBe(false);
        expect((0, vibe_confidence_1.shouldShowInContext)(65)).toBe(true);
    });
});
describe('Vibe Summary Builder', () => {
    test('builds summary from signals', () => {
        const signals = [
            { id: 'language_hindi', group: 'communication', category: 'Communication Style', count: 22, vibe: 95, firstSeen: '2026-01-01', lastSeen: '2026-06-01' },
            { id: 'tone_direct', group: 'communication', category: 'Communication Style', count: 15, vibe: 88, firstSeen: '2026-01-01', lastSeen: '2026-06-01' },
            { id: 'changes_minimal', group: 'code_philosophy', category: 'Coding Philosophy', count: 12, vibe: 85, firstSeen: '2026-01-01', lastSeen: '2026-06-01' },
        ];
        const rules = [
            { text: 'Hinglish preferred. Vibe: 95', category: 'Communication Style', vibe: 95, count: 22, level: 'certain' },
            { text: 'Direct tone. Vibe: 88', category: 'Communication Style', vibe: 88, count: 15, level: 'very_strong' },
        ];
        const summary = (0, vibe_engine_1.buildVibeSummary)(signals, rules);
        expect(summary.communication.language).toBe('hinglish');
        expect(summary.communication.tone).toBe('direct');
        expect(summary.totalRules).toBe(2);
    });
    test('handles empty signals gracefully', () => {
        const summary = (0, vibe_engine_1.buildVibeSummary)([], []);
        expect(summary.summary).toBe('Style still learning.');
        expect(summary.totalRules).toBe(0);
    });
});
describe('Vibe File I/O', () => {
    let tmpDir;
    beforeEach(() => { tmpDir = makeTmpDir(); });
    afterEach(() => { cleanTmpDir(tmpDir); });
    test('resetVibe cleans vibe directory', () => {
        const vibeDir = path.join(tmpDir, '.cell', 'vibe');
        fs.writeFileSync(path.join(vibeDir, 'vibe.md'), '# test', 'utf-8');
        expect(fs.existsSync(path.join(vibeDir, 'vibe.md'))).toBe(true);
        (0, vibe_engine_1.resetVibe)(tmpDir);
        expect(fs.existsSync(path.join(vibeDir, 'vibe.md'))).toBe(false);
    });
});
//# sourceMappingURL=vibe-engine.test.js.map