"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 PLAYBOOKS_DIR = path.join(os.homedir(), '.fivo', 'cell', 'playbooks');
describe('PlaybookGenerator', () => {
    let module;
    beforeEach(async () => {
        module = await Promise.resolve().then(() => __importStar(require('../../walls/05-community/stats/playbook-generator')));
        if (fs.existsSync(PLAYBOOKS_DIR)) {
            for (const f of fs.readdirSync(PLAYBOOKS_DIR))
                fs.unlinkSync(path.join(PLAYBOOKS_DIR, f));
        }
    });
    const mockProfile = {
        projectId: 'proj-1',
        name: 'My TypeScript Project',
        primaryLanguage: 'typescript',
        languages: [{ language: 'typescript', count: 10, pct: 80 }, { language: 'javascript', count: 2, pct: 20 }],
        categories: [{ category: 'variable_declaration', count: 5, pct: 50 }, { category: 'function_declaration', count: 3, pct: 30 }],
        frameworks: [{ framework: 'react', count: 5 }],
        totalPatterns: 10,
        totalSignals: 50,
        topPatterns: [
            { patternId: 'p1', description: 'use const over let', acceptRate: 0.9 },
            { patternId: 'p2', description: 'use arrow functions', acceptRate: 0.8 },
        ],
        patternSequences: [{ from: 'var', to: 'const', count: 5 }, { from: 'function', to: 'arrow', count: 3 }],
        averageConfidence: 0.85,
        createdAt: 1000,
        updatedAt: 2000,
    };
    test('generatePlaybook creates playbook file and returns content', () => {
        const playbook = module.generatePlaybook('proj-1', mockProfile);
        expect(playbook.projectId).toBe('proj-1');
        expect(playbook.projectName).toBe('My TypeScript Project');
        expect(playbook.overview).toContain('TypeScript Project');
        expect(playbook.overview).toContain('Primary Language: typescript');
        expect(playbook.conventions.title).toBe('Coding Conventions');
        expect(playbook.patterns.content).toContain('use const over let');
        expect(playbook.onboardingGuide.content).toContain('Fivo Cell daemon');
    });
    test('getPlaybook retrieves saved playbook', () => {
        module.generatePlaybook('proj-1', mockProfile);
        const loaded = module.getPlaybook('proj-1');
        expect(loaded).not.toBeNull();
        expect(loaded.projectName).toBe('My TypeScript Project');
    });
    test('getPlaybook returns null for missing', () => {
        expect(module.getPlaybook('nonexistent')).toBeNull();
    });
    test('listPlaybooks returns all project IDs', () => {
        module.generatePlaybook('a', mockProfile);
        module.generatePlaybook('b', mockProfile);
        const list = module.listPlaybooks();
        expect(list).toContain('a');
        expect(list).toContain('b');
    });
});
//# sourceMappingURL=playbook-generator.test.js.map