// engine/migration/parity-validator.ts — Functional parity validation (SPEC-028a)
// Generates parity checklists and contract tests for migrated components
// --- Checklist generation ---
function buildParityChecklist(component) {
    return [
        {
            category: 'endpoints',
            description: `All endpoints exposed by ${component} are present in the new implementation`,
            status: 'pending',
        },
        {
            category: 'request-schema',
            description: `Request body/params schema is identical (field names, types, required/optional)`,
            status: 'pending',
        },
        {
            category: 'response-schema',
            description: `Response body schema is identical (field names, types, nested structures)`,
            status: 'pending',
        },
        {
            category: 'error-codes',
            description: `HTTP status codes and error message formats match the origin`,
            status: 'pending',
        },
        {
            category: 'side-effects',
            description: `Database writes, events emitted, and external calls match origin behavior`,
            status: 'pending',
        },
    ];
}
// --- Contract test generation ---
function buildContractTests(component, endpoints) {
    return endpoints.map((endpoint) => {
        const method = endpoint.startsWith('GET') ? 'GET' : 'POST';
        const path = endpoint.replace(/^(GET|POST|PUT|DELETE|PATCH)\s+/, '');
        return {
            endpoint: path,
            method,
            sampleInput: {
                description: `Sample input for ${component} ${endpoint}`,
                placeholder: 'Replace with actual request body/params from origin',
            },
            expectedOutputPattern: {
                description: `Expected response shape from ${component} ${endpoint}`,
                placeholder: 'Replace with actual response schema from origin',
            },
            tolerances: [
                'Timestamp fields may differ by up to 1 second',
                'UUID/ID fields may differ — compare by reference not by value',
            ],
        };
    });
}
// --- Difference classification ---
function classifyDifferences(differences) {
    const regressions = [];
    const intentionalChanges = [];
    for (const diff of differences) {
        const lower = diff.toLowerCase();
        if (lower.includes('missing') ||
            lower.includes('broken') ||
            lower.includes('error') ||
            lower.includes('fail') ||
            lower.includes('wrong') ||
            lower.includes('regression')) {
            regressions.push(diff);
        }
        else {
            intentionalChanges.push(diff);
        }
    }
    return { regressions, intentionalChanges };
}
// --- Public API ---
export function generateParityValidation(params) {
    const { component, endpoints, observedDifferences = [] } = params;
    const checklist = buildParityChecklist(component);
    const contractTests = buildContractTests(component, endpoints);
    const { regressions, intentionalChanges } = classifyDifferences(observedDifferences);
    return {
        component,
        checklist,
        contractTests,
        regressions,
        intentionalChanges,
        validatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=parity-validator.js.map