"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 utils_1 = require("../../../../src/utils");
const agents_1 = require("../../../../src/agents");
const services_1 = require("../../../../src/services");
const list_1 = require("../../../../src/agents/tools/list");
describe("Developer", () => {
    const { Patcher } = (0, agents_1.agents)();
    beforeAll(() => {
        const { Tools } = (0, services_1.services)();
        Tools.addTools(list_1.includedTools);
        Patcher.disableTool("searchFiles");
        Patcher.disableTool("execCommand");
        Patcher.enableTool("modifyFile");
        Patcher.enableTool("readFile");
    });
    test("should be able to patch a codebase", async () => {
        const inputPath = "tests/integration/patching/input.txt";
        const originalText = (await (0, utils_1.readFile)(inputPath)).toString();
        await Patcher.call(`Update the file in ${inputPath} change the string "finalAnswer" to "FinalAnswer" on line 120. Do not modify anything else. Treat this file as a typescript file.`);
        const updatedText = (await (0, utils_1.readFile)(inputPath)).toString();
        await (0, utils_1.writeFile)(inputPath, originalText);
        expect(updatedText).toBe(originalText.replace(`"finalAnswer"`, `"FinalAnswer"`));
    });
    test("should be able to update the unseen file", async () => {
        const unseenPath = "tests/integration/patching/unseen.txt";
        const originalText = (await (0, utils_1.readFile)(unseenPath)).toString();
        await Patcher.call(`Update the file in ${unseenPath} change the file additions and deletions count from 200 to 300. Do not modify anything else. Treat this file as a typescript file.`);
        const updatedText = (await (0, utils_1.readFile)(unseenPath)).toString();
        await (0, utils_1.writeFile)(unseenPath, originalText);
        expect(updatedText).toBe(originalText.replaceAll("200", "300"));
    });
    test.only("should be able to create a simple flag service", async () => {
        const outputPath = "tests/integration/fileblocks/outputs/flags.js";
        const promptText = `
  Create the following class

    - **Class Name**: FlagsService
    - **Internal Variables**:
      - flags: Object
      - log: Boolean
    - **Constructor**:
      - Parameters: flags (Array<string>), log (Boolean)
    - **Methods**:
      - register(flags: Array<string>): Initializes flags with false.
      - flip(flag: string): Toggles and logs the state of a flag.
      - enableLogging(): Enables logging.
      - disableLogging(): Disables logging.
      - enabled(flag: string): Checks if a flag is enabled.
    - **Singleton Variable**: Flags

      Make sure to module.exports the class and Singleton, as we will be importing it in the test via require("./outputs/flags.js").Flags
`;
        await Patcher.call(`Modify the file in ${outputPath} for these instructions.: ${promptText}`);
        const fileContent = (await (0, utils_1.readFile)(outputPath)).toString();
        console.log(fileContent);
        jest.resetModules();
        const service = require("./outputs/flags.js").Flags;
        try {
            service.register(["test"]);
            expect(service.enabled("test")).toEqual(false);
            service.flip("test");
            expect(service.enabled("test")).toEqual(true);
            await Patcher.call(`Modify the file in ${outputPath} and add a method called hasFlag that takes a string and returns a boolean. It should return true if the flag is defined at all, even if it is false. This is a unit test, only modify the file I've specified.`);
            jest.resetModules();
            const newService = require("./outputs/flags.js").Flags;
            newService.register(["test"]);
            expect(newService.hasFlag("test")).toEqual(true);
            fs.unlinkSync(outputPath);
        }
        catch (e) {
            console.log(e);
        }
    });
});
//# sourceMappingURL=readwrite.test.js.map