mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-23 08:58:58 +00:00
* plan: mcp-unblock, a session that waits in Claude Code, answered in its group * plan: mcp-unblock, events per state, a mod for the usage menu * plan: mcp-unblock, revision 3: the build in two stages * mcp: tool prompts of subagents and artifacts in the session group * plan: mcp-unblock, deviations of stage 2 * mcp: Claude's questions, plans and stops in the session group * plan: mcp-unblock, one pull request * mcp: renumber the waiting flows, test a subagent's card on the board
78 lines
5.3 KiB
TypeScript
78 lines
5.3 KiB
TypeScript
import {spawn} from "child_process"
|
|
import {readFileSync} from "fs"
|
|
import {join} from "path"
|
|
import {configVariables, defaultConfig} from "../../src/config"
|
|
|
|
const read = (file: string): any => JSON.parse(readFileSync(join(__dirname, "../..", file), "utf8"))
|
|
const packageJson = read("package.json")
|
|
const cli = (args: string): string => `node "\${CLAUDE_PLUGIN_ROOT}/dist/cli.js" ${args}`
|
|
|
|
describe("plugin", () => {
|
|
it("has the package version and the config defaults", () => {
|
|
const plugin = read(".claude-plugin/plugin.json")
|
|
expect(plugin.name).toBe("simplex")
|
|
expect(plugin.version).toBe(packageJson.version)
|
|
expect(plugin.userConfig.main_group.default).toBe(defaultConfig.mainGroup)
|
|
expect(plugin.userConfig.approve.default).toBe(defaultConfig.approve)
|
|
expect(plugin.userConfig.approve.description).toBe("requests: you approve connections and messages in the SimpleX app. host: Claude Code asks you instead, after an admin or owner approves this in the session's group.")
|
|
expect(plugin.userConfig.expire_hours.default).toBe(defaultConfig.expireHours)
|
|
expect(Object.keys(plugin.userConfig)).toEqual(["main_group", "approve", "expire_hours"])
|
|
})
|
|
|
|
it("starts the session server of the plugin's own build with the options as variables", () => {
|
|
const {simplex} = read(".mcp.json").mcpServers
|
|
expect(simplex.command).toBe("node")
|
|
expect(simplex.args).toEqual(["${CLAUDE_PLUGIN_ROOT}/dist/cli.js", "session"])
|
|
expect(simplex.env).toEqual({
|
|
[configVariables.mainGroup]: "${user_config.main_group}",
|
|
[configVariables.approve]: "${user_config.approve}",
|
|
[configVariables.expireHours]: "${user_config.expire_hours}",
|
|
})
|
|
})
|
|
|
|
it("lets a tool call wait for the longest expiry, the responses and a margin", () => {
|
|
const responseWaitHours = 24
|
|
const marginMs = 10 * 60_000
|
|
const maxExpireHours = read(".claude-plugin/plugin.json").userConfig.expire_hours.max
|
|
expect(maxExpireHours).toBe(23)
|
|
expect(read(".mcp.json").mcpServers.simplex.timeout).toBe((maxExpireHours + responseWaitHours) * 3_600_000 + marginMs)
|
|
})
|
|
|
|
it("runs the hooks from the plugin's own build, allows the plugin's tools, runs the turn hook at the start and the end of every tool use and after each compaction, asks the session server before every tool use whether its tool is approved, runs the display hook synchronously for MessageDisplay, lets the PermissionRequest and Elicitation hooks wait a day for a card, and runs the turn hook at a failed turn and at the notifications of a waiting Claude Code", () => {
|
|
const {hooks} = read("hooks/hooks.json")
|
|
expect(hooks.SessionStart[0].hooks[0]).toEqual({type: "command", command: cli("hook session-start"), timeout: 600})
|
|
expect(hooks.PreToolUse[0].matcher).toBe("mcp__plugin_simplex_simplex__.*")
|
|
expect(hooks.PreToolUse[0].hooks[0]).toEqual({type: "command", command: 'node "${CLAUDE_PLUGIN_ROOT}/plugin/allow.js"'})
|
|
for (const event of ["UserPromptSubmit", "Stop", "PostModelSwitch", "PostCompact", "SubagentStart", "SubagentStop"]) expect(hooks[event]).toEqual([{hooks: [{type: "command", command: cli("hook turn"), async: true}]}])
|
|
const steps = {matcher: "*", hooks: [{type: "command", command: cli("hook turn"), async: true}]}
|
|
expect(hooks.PreToolUse[1]).toEqual({...steps, hooks: [...steps.hooks, {type: "mcp_tool", server: "plugin:simplex:simplex", tool: "pre_tool_use", input: {tool: "${tool_name}"}, timeout: 5}]})
|
|
for (const event of ["PostToolUse", "PostToolUseFailure"]) expect(hooks[event]).toEqual([steps])
|
|
expect(hooks.MessageDisplay).toEqual([{hooks: [{type: "command", command: 'node "${CLAUDE_PLUGIN_ROOT}/dist/display.js"', timeout: 2}]}])
|
|
for (const event of ["PermissionRequest", "Elicitation"]) expect(hooks[event]).toEqual([{hooks: [{type: "command", command: cli("hook ask"), timeout: 86400}]}])
|
|
expect(hooks.StopFailure).toEqual([{hooks: [{type: "command", command: cli("hook turn"), async: true}]}])
|
|
expect(hooks.Notification).toEqual([{matcher: "permission_prompt|worker_permission_prompt|elicitation_dialog|elicitation_url_dialog|agent_needs_input|quota_auto_resume_stale|quota_auto_resume_disabled", hooks: [{type: "command", command: cli("hook turn"), async: true}]}])
|
|
})
|
|
|
|
it("ships the build, its bundled dependencies and the plugin files in the package, without a lockfile", () => {
|
|
expect(packageJson.files).toEqual(["dist", "README.md", ".claude-plugin", ".mcp.json", "hooks", "plugin"])
|
|
expect(packageJson.bundleDependencies).toBe(true)
|
|
})
|
|
|
|
it("allows a tool call", async () => {
|
|
const stdout = await new Promise<string>((resolve, reject) => {
|
|
const child = spawn(process.execPath, [join(__dirname, "../../plugin/allow.js")], {stdio: ["ignore", "pipe", "inherit"]})
|
|
let text = ""
|
|
child.stdout.on("data", chunk => (text += chunk))
|
|
child.on("error", reject)
|
|
child.on("close", () => resolve(text))
|
|
})
|
|
expect(JSON.parse(stdout)).toEqual({hookSpecificOutput: {hookEventName: "PreToolUse", permissionDecision: "allow"}})
|
|
})
|
|
|
|
it("lists the plugin in the marketplace with an npm source", () => {
|
|
const marketplace = JSON.parse(readFileSync(join(__dirname, "../../../../.claude-plugin/marketplace.json"), "utf8"))
|
|
expect(marketplace.name).toBe("simplex-chat")
|
|
expect(marketplace.plugins).toEqual([expect.objectContaining({name: "simplex", source: {source: "npm", package: "@simplex-chat/mcp"}})])
|
|
})
|
|
})
|