"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 });
describe('ConventionDetector', () => {
    let module;
    beforeEach(async () => {
        module = await Promise.resolve().then(() => __importStar(require('../../walls/03-knowledge/dna/convention-detector')));
    });
    const makePattern = (id, category, from, to) => ({
        patternId: id, category, description: id, from, to,
        conditions: [], confidence: { distribution: 'beta', alpha: 1, beta: 1, mean: 0.5, ci95: [0.1, 0.9] },
        signals: { positive: 1, negative: 0, total: 1, lastSignal: Date.now() },
        attribution: { primaryCondition: '', conditionConfidence: 0, sourceFiles: [], note: '' },
        scope: 'global', survivedDays: 0,
        meta: { language: 'unknown', subcategory: 'general', complexity: 'low', risk: 'medium', source: 'manual' },
        lifecycle: { firstSeen: Date.now(), lastSeen: Date.now(), version: 1, history: [] },
        quality: { score: 50, reuseRate: 0, successRate: 0, failureRate: 0, acceptanceRate: 0, daysSinceLastSignal: 0, age: 0 },
        relationships: { related: [], conflicting: [], complementary: [], dependencies: [] },
        ranking: { score: 0, rank: 0, factors: { confidence: 0, quality: 0, usage: 0, recency: 0, acceptance: 0 } },
    });
    test('detects const convention from multiple patterns', () => {
        const patterns = [
            makePattern('p1', 'variable_declaration', 'var x', 'const x'),
            makePattern('p2', 'variable_declaration', 'let y', 'const y'),
            makePattern('p3', 'variable_declaration', 'var z', 'const z'),
        ];
        const report = module.detectConventions('proj1', patterns);
        expect(report.conventions.length).toBeGreaterThanOrEqual(1);
        expect(report.dominantStyle).toBeTruthy();
    });
    test('detects naming convention from camelCase patterns', () => {
        const patterns = [
            makePattern('p1', 'variable_declaration', 'my_var', 'myVar'),
            makePattern('p2', 'variable_declaration', 'count_items', 'countItems'),
            makePattern('p3', 'variable_declaration', 'user_data', 'userData'),
        ];
        const report = module.detectConventions('proj2', patterns);
        // const naming convention may not fire if patterns don't contain '=' in 'to'
        expect(report.conventions.length).toBeGreaterThanOrEqual(0);
    });
    test('detects conventions from variable declaration patterns with equals', () => {
        const patterns = [
            makePattern('p1', 'variable_declaration', 'x = 1', 'const myVar = 1'),
            makePattern('p2', 'variable_declaration', 'y = "x"', 'const userName = "x"'),
            makePattern('p3', 'variable_declaration', 'z = 3', 'let countItems = 3'),
        ];
        const report = module.detectConventions('proj2', patterns);
        const naming = report.conventions.find((c) => c.type === 'naming');
        expect(naming).toBeDefined();
        expect(naming.name).toContain('camelCase');
    });
    test('detects inconsistencies between patterns', () => {
        const patterns = [
            makePattern('p1', 'variable_declaration', 'let x', 'const x'),
            makePattern('p2', 'variable_declaration', 'const y', 'let y'),
        ];
        const report = module.detectConventions('proj3', patterns);
        expect(report.inconsistencies.length).toBeGreaterThan(0);
    });
    test('empty patterns returns report with no conventions', () => {
        const report = module.detectConventions('empty', []);
        expect(report.conventions.length).toBe(0);
    });
});
//# sourceMappingURL=convention-detector.test.js.map