"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const error_predictor_1 = require("../../walls/03-knowledge/decisions/error-predictor");
describe('ErrorPredictor', () => {
    let predictor;
    beforeEach(() => {
        predictor = new error_predictor_1.ErrorPredictor();
    });
    test('detects null access without check', () => {
        const code = 'const result = user.getName();';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'null_access')).toBe(true);
    });
    test('skips null access with prior null check', () => {
        const code = 'if (user !== null) {\n  const result = user.getName();\n}';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'null_access')).toBe(false);
    });
    test('detects type mismatch', () => {
        const code = 'const age: string = 25;';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'type_mismatch')).toBe(true);
    });
    test('detects missing await', () => {
        const code = 'async function load() {\n  const data = fetch("/api");\n}';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'missing_await')).toBe(true);
    });
    test('detects unhandled promise', () => {
        const code = 'fetch("/api").then(r => r.json());';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'unhandled_promise')).toBe(true);
    });
    test('getQuickFix returns fix for each type', () => {
        expect(predictor.getQuickFix({ line: 1, type: 'null_access', severity: 'high', message: '', suggestion: '' })).toContain('null');
        expect(predictor.getQuickFix({ line: 1, type: 'missing_await', severity: 'high', message: '', suggestion: '' })).toContain('await');
        expect(predictor.getQuickFix({ line: 1, type: 'unhandled_promise', severity: 'medium', message: '', suggestion: '' })).toContain('catch');
    });
    test('returns empty for clean code', () => {
        const code = 'const x = 1 + 2;';
        const predictions = predictor.predict(code);
        expect(predictions).toHaveLength(0);
    });
    test('AST detects missing await inside async function', () => {
        const code = 'async function loadData() {\n  const r = fetch("/api/users");\n  return r.json();\n}';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'missing_await')).toBe(true);
    });
    test('AST skips missing await for sync calls', () => {
        const code = 'function loadData() {\n  return "hello";\n}';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'missing_await')).toBe(false);
    });
    test('AST detects unhandled .then without .catch', () => {
        const code = 'fetch("/api").then(r => r.json()).then(d => console.log(d));';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'unhandled_promise')).toBe(true);
    });
    test('AST skips .then with .catch chain', () => {
        const code = 'fetch("/api").then(r => r.json()).catch(e => console.error(e));';
        const predictions = predictor.predict(code);
        expect(predictions.some((p) => p.type === 'unhandled_promise')).toBe(false);
    });
});
//# sourceMappingURL=error-predictor.test.js.map