"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 database_1 = require("../walls/06-memory/database/database");
const style_memory_1 = require("../walls/06-memory/style/style-memory");
function makeTmpDir() {
    const dir = path.join(os.tmpdir(), `cell-style-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
    fs.mkdirSync(dir, { recursive: true });
    return dir;
}
function cleanTmpDir(dir) {
    try {
        fs.rmSync(dir, { recursive: true, force: true });
    }
    catch { }
}
describe('Style Memory', () => {
    let tmpDir;
    beforeAll(() => {
        (0, database_1.getDb)();
    });
    beforeEach(() => {
        tmpDir = makeTmpDir();
    });
    afterEach(() => {
        cleanTmpDir(tmpDir);
    });
    it('initDefaultStyle creates style files', () => {
        (0, style_memory_1.initDefaultStyle)(tmpDir);
        const styleDir = path.join(tmpDir, '.cell', 'memory', 'style');
        expect(fs.existsSync(path.join(styleDir, 'developer-style.json'))).toBe(true);
        expect(fs.existsSync(path.join(styleDir, 'project-style.json'))).toBe(true);
        expect(fs.existsSync(path.join(styleDir, 'communication.md'))).toBe(true);
    });
    it('loadDeveloperStyle returns default when no file', () => {
        const style = (0, style_memory_1.loadDeveloperStyle)(tmpDir);
        expect(style.communication).toBeTruthy();
        expect(style.coding).toBeTruthy();
        expect(style.verification.length).toBeGreaterThan(0);
    });
    it('saveDeveloperStyle and loadDeveloperStyle round-trip', () => {
        (0, style_memory_1.saveDeveloperStyle)(tmpDir, {
            communication: 'English, formal',
            coding: 'functional style',
            verification: ['npm test'],
            privacy: ['no tracking'],
            product_rules: ['OSS only'],
            preferences: { theme: 'dark' },
        });
        const loaded = (0, style_memory_1.loadDeveloperStyle)(tmpDir);
        expect(loaded.communication).toBe('English, formal');
        expect(loaded.coding).toBe('functional style');
        expect(loaded.preferences.theme).toBe('dark');
    });
    it('loadProjectStyle returns defaults when no file', () => {
        const style = (0, style_memory_1.loadProjectStyle)(tmpDir);
        expect(style.architecture).toBeTruthy();
        expect(style.naming).toBeTruthy();
    });
    it('saveProjectStyle and loadProjectStyle round-trip', () => {
        (0, style_memory_1.saveProjectStyle)(tmpDir, {
            architecture: 'monolith',
            naming: 'snake_case',
            testing: 'pytest',
            stack: ['Python', 'FastAPI'],
            conventions: ['use type hints'],
            entry_points: ['main.py'],
            module_system: 'python',
        });
        const loaded = (0, style_memory_1.loadProjectStyle)(tmpDir);
        expect(loaded.architecture).toBe('monolith');
        expect(loaded.stack).toContain('Python');
    });
    it('updateDeveloperPreference adds preference', () => {
        (0, style_memory_1.initDefaultStyle)(tmpDir);
        (0, style_memory_1.updateDeveloperPreference)(tmpDir, 'editor', 'VS Code');
        const style = (0, style_memory_1.loadDeveloperStyle)(tmpDir);
        expect(style.preferences.editor).toBe('VS Code');
    });
    it('addVerificationCommand adds command', () => {
        (0, style_memory_1.initDefaultStyle)(tmpDir);
        (0, style_memory_1.addVerificationCommand)(tmpDir, 'ruff check .');
        const style = (0, style_memory_1.loadDeveloperStyle)(tmpDir);
        expect(style.verification).toContain('ruff check .');
    });
    it('addProductRule adds rule', () => {
        (0, style_memory_1.initDefaultStyle)(tmpDir);
        (0, style_memory_1.addProductRule)(tmpDir, 'Never commit secrets');
        const style = (0, style_memory_1.loadDeveloperStyle)(tmpDir);
        expect(style.product_rules).toContain('Never commit secrets');
    });
    it('addProjectConvention adds convention', () => {
        (0, style_memory_1.initDefaultStyle)(tmpDir);
        (0, style_memory_1.addProjectConvention)(tmpDir, 'Use async/await');
        const style = (0, style_memory_1.loadProjectStyle)(tmpDir);
        expect(style.conventions).toContain('Use async/await');
    });
});
//# sourceMappingURL=style-memory.test.js.map