2026-02-03 15:19:01 +07:00

144 lines
4.6 KiB
TypeScript

import { describe, test, expect } from "bun:test"
import { createBuiltinSkills } from "./skills"
describe("createBuiltinSkills", () => {
test("returns playwright skill by default", () => {
// given - no options (default)
// when
const skills = createBuiltinSkills()
// then
const browserSkill = skills.find((s) => s.name === "playwright")
expect(browserSkill).toBeDefined()
expect(browserSkill!.description).toContain("browser")
expect(browserSkill!.mcpConfig).toHaveProperty("playwright")
})
test("returns playwright skill when browserProvider is 'playwright'", () => {
// given
const options = { browserProvider: "playwright" as const }
// when
const skills = createBuiltinSkills(options)
// then
const playwrightSkill = skills.find((s) => s.name === "playwright")
const agentBrowserSkill = skills.find((s) => s.name === "agent-browser")
expect(playwrightSkill).toBeDefined()
expect(agentBrowserSkill).toBeUndefined()
})
test("returns agent-browser skill when browserProvider is 'agent-browser'", () => {
// given
const options = { browserProvider: "agent-browser" as const }
// when
const skills = createBuiltinSkills(options)
// then
const agentBrowserSkill = skills.find((s) => s.name === "agent-browser")
const playwrightSkill = skills.find((s) => s.name === "playwright")
expect(agentBrowserSkill).toBeDefined()
expect(agentBrowserSkill!.description).toContain("browser")
expect(agentBrowserSkill!.allowedTools).toContain("Bash(agent-browser:*)")
expect(agentBrowserSkill!.template).toContain("agent-browser")
expect(playwrightSkill).toBeUndefined()
})
test("agent-browser skill template is inlined (not loaded from file)", () => {
// given
const options = { browserProvider: "agent-browser" as const }
// when
const skills = createBuiltinSkills(options)
const agentBrowserSkill = skills.find((s) => s.name === "agent-browser")
// then - template should contain substantial content (inlined, not fallback)
expect(agentBrowserSkill!.template).toContain("## Quick start")
expect(agentBrowserSkill!.template).toContain("## Commands")
expect(agentBrowserSkill!.template).toContain("agent-browser open")
expect(agentBrowserSkill!.template).toContain("agent-browser snapshot")
})
test("always includes frontend-ui-ux and git-master skills", () => {
// given - both provider options
// when
const defaultSkills = createBuiltinSkills()
const agentBrowserSkills = createBuiltinSkills({ browserProvider: "agent-browser" })
// then
for (const skills of [defaultSkills, agentBrowserSkills]) {
expect(skills.find((s) => s.name === "frontend-ui-ux")).toBeDefined()
expect(skills.find((s) => s.name === "git-master")).toBeDefined()
}
})
test("returns exactly 4 skills regardless of provider", () => {
// given
// when
const defaultSkills = createBuiltinSkills()
const agentBrowserSkills = createBuiltinSkills({ browserProvider: "agent-browser" })
// then
expect(defaultSkills).toHaveLength(4)
expect(agentBrowserSkills).toHaveLength(4)
})
test("should exclude playwright when it is in disabledSkills", () => {
// #given
const options = { disabledSkills: new Set(["playwright"]) }
// #when
const skills = createBuiltinSkills(options)
// #then
expect(skills.map((s) => s.name)).not.toContain("playwright")
expect(skills.map((s) => s.name)).toContain("frontend-ui-ux")
expect(skills.map((s) => s.name)).toContain("git-master")
expect(skills.map((s) => s.name)).toContain("dev-browser")
expect(skills.length).toBe(3)
})
test("should exclude multiple skills when they are in disabledSkills", () => {
// #given
const options = { disabledSkills: new Set(["playwright", "git-master"]) }
// #when
const skills = createBuiltinSkills(options)
// #then
expect(skills.map((s) => s.name)).not.toContain("playwright")
expect(skills.map((s) => s.name)).not.toContain("git-master")
expect(skills.map((s) => s.name)).toContain("frontend-ui-ux")
expect(skills.map((s) => s.name)).toContain("dev-browser")
expect(skills.length).toBe(2)
})
test("should return an empty array when all skills are disabled", () => {
// #given
const options = {
disabledSkills: new Set(["playwright", "frontend-ui-ux", "git-master", "dev-browser"]),
}
// #when
const skills = createBuiltinSkills(options)
// #then
expect(skills.length).toBe(0)
})
test("should return all skills when disabledSkills set is empty", () => {
// #given
const options = { disabledSkills: new Set<string>() }
// #when
const skills = createBuiltinSkills(options)
// #then
expect(skills.length).toBe(4)
})
})