import { describe, expect, test } from "bun:test"
import path from "path"
import { loadClaudePlugin } from "../src/parsers/claude"
import { sanitizePathName } from "../src/utils/files"

const pluginRoot = process.cwd()

describe("sanitizePathName", () => {
  test("replaces colons with hyphens", () => {
    expect(sanitizePathName("other:skill")).toBe("other-skill")
    expect(sanitizePathName("other:tool")).toBe("other-tool")
  })

  test("no CE skill name contains a colon", async () => {
    const plugin = await loadClaudePlugin(pluginRoot)
    for (const skill of plugin.skills) {
      expect(skill.name).not.toContain(":")
    }
  })

  test("passes through names without colons", () => {
    expect(sanitizePathName("frontend-design")).toBe("frontend-design")
  })

  test("handles multiple colons", () => {
    expect(sanitizePathName("a:b:c")).toBe("a-b-c")
  })
})

describe("path sanitization collision detection", () => {
  test("no two skill names collide after sanitization", async () => {
    const plugin = await loadClaudePlugin(pluginRoot)
    const sanitized = plugin.skills.map((skill) => sanitizePathName(skill.name))
    const unique = new Set(sanitized)

    expect(unique.size).toBe(sanitized.length)
  })

  test("no two agent names collide after sanitization", async () => {
    const plugin = await loadClaudePlugin(pluginRoot)
    const sanitized = plugin.agents.map((agent) => sanitizePathName(agent.name))
    const unique = new Set(sanitized)

    expect(unique.size).toBe(sanitized.length)
  })
})
