|
| 1 | +import { mkdtemp, readFile } from "node:fs/promises"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import { join } from "node:path"; |
| 4 | + |
| 5 | +import { describe, expect, it } from "bun:test"; |
| 6 | + |
| 7 | +import { runSkillCommand } from "../src/skill-command"; |
| 8 | +import type { ProjectService } from "../src/project-service"; |
| 9 | + |
| 10 | +function fixtureService(): ProjectService { |
| 11 | + return { |
| 12 | + config: { |
| 13 | + version: 1, |
| 14 | + servers: { |
| 15 | + slack: { |
| 16 | + transport: "stdio", |
| 17 | + command: "slack-mcp", |
| 18 | + tools: [], |
| 19 | + }, |
| 20 | + }, |
| 21 | + }, |
| 22 | + ensureServerReady: async () => { |
| 23 | + throw new Error("not used"); |
| 24 | + }, |
| 25 | + reauthenticateServer: async () => { |
| 26 | + throw new Error("not used"); |
| 27 | + }, |
| 28 | + save: async () => {}, |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +async function captureStdout(run: () => Promise<void>): Promise<string> { |
| 33 | + const originalWrite = process.stdout.write; |
| 34 | + let output = ""; |
| 35 | + process.stdout.write = ((chunk: string | Uint8Array) => { |
| 36 | + output += chunk.toString(); |
| 37 | + return true; |
| 38 | + }) as typeof process.stdout.write; |
| 39 | + |
| 40 | + try { |
| 41 | + await run(); |
| 42 | + return output; |
| 43 | + } finally { |
| 44 | + process.stdout.write = originalWrite; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +describe("mcpx skill command", () => { |
| 49 | + it("prints a temporary server skill without writing project files", async () => { |
| 50 | + const cwd = await mkdtemp(join(tmpdir(), "mcpx-skill-show-")); |
| 51 | + const output = await captureStdout(async () => { |
| 52 | + await runSkillCommand(fixtureService(), cwd, { show: "slack" }); |
| 53 | + }); |
| 54 | + |
| 55 | + expect(output).toContain('servers: ["slack"]'); |
| 56 | + expect(output).toContain("configured MCP servers"); |
| 57 | + expect(output).toContain('mcpx --schema=".slack"'); |
| 58 | + await expect( |
| 59 | + readFile(join(cwd, ".agents", "skills", "mcpx", "SKILL.md"), "utf8"), |
| 60 | + ).rejects.toThrow(); |
| 61 | + }); |
| 62 | + |
| 63 | + it("rejects mixing temporary show and project skill generation", async () => { |
| 64 | + const cwd = await mkdtemp(join(tmpdir(), "mcpx-skill-show-")); |
| 65 | + |
| 66 | + await expect( |
| 67 | + runSkillCommand(fixtureService(), cwd, { servers: "slack", show: "slack" }), |
| 68 | + ).rejects.toThrow("--show cannot be combined with --servers."); |
| 69 | + }); |
| 70 | +}); |
0 commit comments