2026-01-25 14:52:50 +09:00
|
|
|
import { describe, it, expect } from "bun:test"
|
|
|
|
|
import { createSlashcommandTool } from "./tools"
|
|
|
|
|
import type { CommandInfo } from "./types"
|
|
|
|
|
import type { LoadedSkill } from "../../features/opencode-skill-loader"
|
|
|
|
|
|
|
|
|
|
function createMockCommand(name: string, description = ""): CommandInfo {
|
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
metadata: {
|
|
|
|
|
name,
|
|
|
|
|
description: description || `Test command ${name}`,
|
|
|
|
|
},
|
|
|
|
|
scope: "builtin",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createMockSkill(name: string, description = ""): LoadedSkill {
|
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
path: `/test/skills/${name}/SKILL.md`,
|
|
|
|
|
resolvedPath: `/test/skills/${name}`,
|
|
|
|
|
definition: {
|
|
|
|
|
name,
|
|
|
|
|
description: description || `Test skill ${name}`,
|
|
|
|
|
template: "Test template",
|
|
|
|
|
},
|
|
|
|
|
scope: "opencode-project",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("slashcommand tool - synchronous description", () => {
|
|
|
|
|
it("includes available_skills immediately when commands and skills are pre-provided", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-25 14:52:50 +09:00
|
|
|
const commands = [createMockCommand("commit", "Create a git commit")]
|
|
|
|
|
const skills = [createMockSkill("playwright", "Browser automation via Playwright MCP")]
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-25 14:52:50 +09:00
|
|
|
const tool = createSlashcommandTool({ commands, skills })
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-25 14:52:50 +09:00
|
|
|
expect(tool.description).toContain("<available_skills>")
|
|
|
|
|
expect(tool.description).toContain("commit")
|
|
|
|
|
expect(tool.description).toContain("playwright")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("includes all pre-provided commands and skills in description immediately", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given
|
2026-01-25 14:52:50 +09:00
|
|
|
const commands = [
|
|
|
|
|
createMockCommand("commit", "Git commit"),
|
|
|
|
|
createMockCommand("plan", "Create plan"),
|
|
|
|
|
]
|
|
|
|
|
const skills = [
|
|
|
|
|
createMockSkill("playwright", "Browser automation"),
|
|
|
|
|
createMockSkill("frontend-ui-ux", "Frontend design"),
|
|
|
|
|
createMockSkill("git-master", "Git operations"),
|
|
|
|
|
]
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when
|
2026-01-25 14:52:50 +09:00
|
|
|
const tool = createSlashcommandTool({ commands, skills })
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then
|
2026-01-25 14:52:50 +09:00
|
|
|
expect(tool.description).toContain("commit")
|
|
|
|
|
expect(tool.description).toContain("plan")
|
|
|
|
|
expect(tool.description).toContain("playwright")
|
|
|
|
|
expect(tool.description).toContain("frontend-ui-ux")
|
|
|
|
|
expect(tool.description).toContain("git-master")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it("shows prefix-only description when both commands and skills are empty", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given / #when
|
2026-01-25 14:52:50 +09:00
|
|
|
const tool = createSlashcommandTool({ commands: [], skills: [] })
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then - even with no items, description should be built synchronously (not just prefix)
|
2026-01-25 14:52:50 +09:00
|
|
|
expect(tool.description).toContain("Load a skill")
|
|
|
|
|
})
|
2026-02-01 16:47:50 +09:00
|
|
|
|
|
|
|
|
it("includes user_message parameter documentation in description", () => {
|
|
|
|
|
// given
|
|
|
|
|
const commands = [createMockCommand("publish", "Publish package")]
|
|
|
|
|
const skills: LoadedSkill[] = []
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
const tool = createSlashcommandTool({ commands, skills })
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(tool.description).toContain("user_message")
|
|
|
|
|
expect(tool.description).toContain("command='publish' user_message='patch'")
|
|
|
|
|
})
|
2026-01-25 14:52:50 +09:00
|
|
|
})
|