"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("source-map-support/register");
const diff_1 = require("diff");
const utils_1 = require("../../utils");
const patch_1 = require("../../agents/tools/patch");
const hashes_1 = require("../../hashes");
async function debugFailure() {
    const successCount = 0;
    const attempts = 0;
    const testHash = "40eda1dc8f1e3052997f2930ae59fed2";
    const dataset = [];
    let patchData;
    for (const data of dataset) {
        if ((await (0, hashes_1.md5Hash)(data.patch)) === testHash) {
            patchData = data;
            break;
        }
    }
    if (patchData) {
        const originalContent = patchData.before;
        const dirName = `./src/dataset/diffs/test_files/fail/${testHash}`;
        const patch = await (0, utils_1.readFile)(`${dirName}/ai-patch.diff`, "utf-8");
        const fixedPatch = (0, patch_1.fixPatch)(patchData.before, patch);
        await (0, utils_1.writeFile)(`${dirName}/ai-fixed-patch.diff`, fixedPatch);
        const updatedContent = (0, diff_1.applyPatch)(originalContent, fixedPatch);
        console.log({ updatedContent });
        const success = !!updatedContent;
        if (updatedContent === patchData.after || fixedPatch === patchData.patch) {
            console.log("SUCCESS");
            console.log("EXACT MATCH");
        }
        else {
            console.log("AI SUGGESTED");
            console.log(patch);
            console.log("FIXED PATCH");
            console.log(fixedPatch);
            console.log("ACTUAL");
            console.log(patchData.patch);
            console.log("DID PATCH APPLY?", !!updatedContent);
        }
    }
    const parsedAnswer = (0, diff_1.parsePatch)(patchData.patch);
    const fileName = parsedAnswer[0].oldFileName;
    console.log({ successCount, attempts, total: dataset.length });
}
if (require.main === module) {
    debugFailure();
}
//# sourceMappingURL=debug.js.map