"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 database_1 = require("../walls/06-memory/database/database");
const cross_project_memory_1 = require("../walls/06-memory/stores/cross-project-memory");
describe('Cross-Project Memory', () => {
    const testDir = path.join(__dirname, '__cross-project-test__');
    const projectName = '__cross-project-test__';
    beforeAll(() => {
        (0, database_1.getDb)();
        if (!fs.existsSync(testDir))
            fs.mkdirSync(testDir, { recursive: true });
    });
    afterAll(() => {
        try {
            fs.rmSync(testDir, { recursive: true, force: true });
        }
        catch { }
        const db = (0, database_1.getDb)();
        db.prepare('DELETE FROM memory_patterns WHERE project = ?').run(projectName);
    });
    it('sharePatternToMemory returns an id', () => {
        const id = (0, cross_project_memory_1.sharePatternToMemory)(testDir, {
            category: 'testing',
            rule: 'Always use describe blocks for test organization',
            language: 'TypeScript',
            successRate: 0.9,
        });
        expect(typeof id).toBe('string');
        expect(id.length).toBeGreaterThan(0);
    });
    it('getSharedPatterns returns shared patterns', () => {
        (0, cross_project_memory_1.sharePatternToMemory)(testDir, {
            category: 'coding',
            rule: 'Use const over let',
            language: 'TypeScript',
        });
        const patterns = (0, cross_project_memory_1.getSharedPatterns)(testDir);
        expect(patterns.length).toBeGreaterThanOrEqual(1);
        expect(patterns[0]).toHaveProperty('category');
        expect(patterns[0]).toHaveProperty('pattern');
    });
    it('getSharedPatterns filters by category', () => {
        (0, cross_project_memory_1.sharePatternToMemory)(testDir, {
            category: 'testing',
            rule: 'Write tests for new features',
        });
        const testingPatterns = (0, cross_project_memory_1.getSharedPatterns)(testDir, 'testing');
        expect(testingPatterns.every(p => p.category === 'testing')).toBe(true);
    });
    it('getCrossProjectStats returns stats', () => {
        const stats = (0, cross_project_memory_1.getCrossProjectStats)();
        expect(stats).toHaveProperty('totalPatterns');
        expect(stats).toHaveProperty('totalProjects');
        expect(stats).toHaveProperty('topCategories');
        expect(stats).toHaveProperty('topProjects');
        expect(stats.totalPatterns).toBeGreaterThanOrEqual(0);
    });
    it('sharePatternToMemory creates file in .cell/cross-project', () => {
        const id = (0, cross_project_memory_1.sharePatternToMemory)(testDir, {
            category: 'pattern-test',
            rule: 'Test file creation',
        });
        const filePath = path.join(testDir, '.cell', 'cross-project', `${id}.json`);
        expect(fs.existsSync(filePath)).toBe(true);
        const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
        expect(content.sourceProject).toBe(projectName);
        expect(content.rule).toBe('Test file creation');
    });
});
//# sourceMappingURL=cross-project-memory.test.js.map