import { describe, it, expect } from "vitest";
import { parseGitHubRemote, generateBranchName, } from "../../autofix/branch-manager.js";
describe("branch-manager", () => {
    describe("parseGitHubRemote", () => {
        it("parses SSH format URLs", () => {
            const result = parseGitHubRemote("git@github.com:owner/repo.git");
            expect(result).toEqual({ owner: "owner", repo: "repo" });
        });
        it("parses SSH format URLs without .git suffix", () => {
            const result = parseGitHubRemote("git@github.com:owner/repo");
            expect(result).toEqual({ owner: "owner", repo: "repo" });
        });
        it("parses HTTPS format URLs", () => {
            const result = parseGitHubRemote("https://github.com/owner/repo.git");
            expect(result).toEqual({ owner: "owner", repo: "repo" });
        });
        it("parses HTTPS format URLs without .git suffix", () => {
            const result = parseGitHubRemote("https://github.com/owner/repo");
            expect(result).toEqual({ owner: "owner", repo: "repo" });
        });
        it("returns undefined for non-GitHub URLs", () => {
            expect(parseGitHubRemote("https://gitlab.com/owner/repo.git")).toBeUndefined();
            expect(parseGitHubRemote("git@gitlab.com:owner/repo.git")).toBeUndefined();
        });
        it("handles repos with dashes and underscores", () => {
            const result = parseGitHubRemote("git@github.com:my-org/my_repo-name.git");
            expect(result).toEqual({ owner: "my-org", repo: "my_repo-name" });
        });
    });
    describe("generateBranchName", () => {
        it("generates branch name with prefix and identifier", () => {
            const result = generateBranchName("vaspera/autofix", "critical");
            expect(result).toMatch(/^vaspera\/autofix\/critical-[a-z0-9]+$/);
        });
        it("sanitizes special characters", () => {
            const result = generateBranchName("fix", "SQL Injection!!!");
            // Special characters become dashes, includes timestamp suffix
            expect(result).toMatch(/^fix\/sql-injection/);
            expect(result).toContain("sql-injection");
        });
        it("truncates long identifiers", () => {
            const longId = "a".repeat(50);
            const result = generateBranchName("fix", longId);
            // Identifier should be truncated to 30 chars + timestamp
            const parts = result.split("/");
            const afterPrefix = parts[1];
            const identifierPart = afterPrefix.split("-").slice(0, -1).join("-");
            expect(identifierPart.length).toBeLessThanOrEqual(30);
        });
        it("converts to lowercase", () => {
            const result = generateBranchName("FIX", "XSS-Attack");
            expect(result).toMatch(/^FIX\/xss-attack-[a-z0-9]+$/);
        });
        it("removes consecutive dashes", () => {
            const result = generateBranchName("fix", "foo---bar");
            expect(result).toMatch(/^fix\/foo-bar-[a-z0-9]+$/);
        });
    });
});
//# sourceMappingURL=branch-manager.test.js.map