"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 journey_memory_1 = require("../walls/03-knowledge/decisions/journey-memory");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const tmpDir = path.join(os.tmpdir(), 'cell-journey-test-' + Date.now());
beforeAll(() => {
    if (!fs.existsSync(tmpDir))
        fs.mkdirSync(tmpDir, { recursive: true });
    // Create a fake project
    const projDir = path.join(tmpDir, 'test-project');
    fs.mkdirSync(projDir, { recursive: true });
    fs.writeFileSync(path.join(projDir, 'package.json'), JSON.stringify({
        name: 'test-project',
        dependencies: { express: '^4.18.0', zod: '^3.22.0' },
        devDependencies: { jest: '^29.0.0', typescript: '^5.0.0' },
    }));
    fs.mkdirSync(path.join(projDir, '.git'), { recursive: true });
    // Create actual source files for skill detection
    const srcDir = path.join(projDir, 'src');
    fs.mkdirSync(srcDir, { recursive: true });
    fs.writeFileSync(path.join(srcDir, 'index.ts'), 'export const hello = () => "world";');
    fs.writeFileSync(path.join(srcDir, 'utils.ts'), 'export function add(a: number, b: number) { return a + b; }');
    fs.writeFileSync(path.join(srcDir, 'test.spec.ts'), 'import { describe, it, expect } from "jest";');
});
afterAll(() => {
    try {
        fs.rmSync(tmpDir, { recursive: true, force: true });
    }
    catch { }
});
describe('Journey Memory (Feature #6)', () => {
    it('buildJourneyTimeline returns array', () => {
        const timeline = (0, journey_memory_1.buildJourneyTimeline)(tmpDir);
        expect(Array.isArray(timeline)).toBe(true);
    });
    it('timeline includes project creation milestone', () => {
        const timeline = (0, journey_memory_1.buildJourneyTimeline)(tmpDir);
        const milestone = timeline.find(e => e.type === 'milestone' && e.detail.includes('test-project'));
        expect(milestone).toBeDefined();
    });
    it('timeline detects first-use of major deps', () => {
        const timeline = (0, journey_memory_1.buildJourneyTimeline)(tmpDir);
        const express = timeline.find(e => e.type === 'first-use' && e.detail.includes('express'));
        expect(express).toBeDefined();
    });
    it('buildSkillProgression returns array', () => {
        const skills = (0, journey_memory_1.buildSkillProgression)(tmpDir);
        expect(Array.isArray(skills)).toBe(true);
    });
    it('skills include TypeScript', () => {
        const skills = (0, journey_memory_1.buildSkillProgression)(tmpDir);
        const ts = skills.find(s => s.area === 'TypeScript');
        expect(ts).toBeDefined();
        expect(ts.metrics.totalFiles).toBeGreaterThan(0);
    });
    it('skill has valid level', () => {
        const skills = (0, journey_memory_1.buildSkillProgression)(tmpDir);
        for (const s of skills) {
            expect(['beginner', 'intermediate', 'proficient', 'mastered']).toContain(s.currentLevel);
        }
    });
    it('buildContextChains returns array', () => {
        const chains = (0, journey_memory_1.buildContextChains)(tmpDir);
        expect(Array.isArray(chains)).toBe(true);
    });
    it('chains detect repeated patterns across projects', () => {
        // Create a second project with same deps to trigger chain detection
        const proj2 = path.join(tmpDir, 'test-project-2');
        fs.mkdirSync(proj2, { recursive: true });
        fs.writeFileSync(path.join(proj2, 'package.json'), JSON.stringify({
            name: 'test-project-2',
            dependencies: { express: '^4.18.0' },
            devDependencies: { jest: '^29.0.0' },
        }));
        fs.mkdirSync(path.join(proj2, '.git'), { recursive: true });
        const chains = (0, journey_memory_1.buildContextChains)(tmpDir);
        // Should find Testing since jest is in 2 projects
        const testing = chains.find(c => c.pattern === 'Testing');
        expect(testing).toBeDefined();
    });
    it('buildGoalTracker returns valid structure', () => {
        const skills = (0, journey_memory_1.buildSkillProgression)(tmpDir);
        const goals = (0, journey_memory_1.buildGoalTracker)(skills);
        expect(goals).toHaveProperty('goals');
        expect(goals).toHaveProperty('recommendations');
        expect(Array.isArray(goals.recommendations)).toBe(true);
    });
    it('buildJourneyReport returns complete report', () => {
        const report = (0, journey_memory_1.buildJourneyReport)(tmpDir);
        expect(report).toHaveProperty('timeline');
        expect(report).toHaveProperty('skills');
        expect(report).toHaveProperty('chains');
        expect(report).toHaveProperty('goals');
        expect(report).toHaveProperty('summary');
        expect(report.summary.totalProjects).toBeGreaterThanOrEqual(1);
        expect(report.summary.languagesLearned).toBeGreaterThanOrEqual(1);
    });
    it('saveJourneyReport writes files', () => {
        const report = (0, journey_memory_1.buildJourneyReport)(tmpDir);
        const savedPath = (0, journey_memory_1.saveJourneyReport)(report);
        expect(fs.existsSync(savedPath)).toBe(true);
        const content = JSON.parse(fs.readFileSync(savedPath, 'utf-8'));
        expect(content.summary).toBeDefined();
    });
});
//# sourceMappingURL=journey-memory.test.js.map