|
1 | 1 | import { describe, it, expect, afterEach } from "vitest"; |
2 | | -import { writeFile, mkdir, rm, readFile } from "node:fs/promises"; |
| 2 | +import { writeFile, mkdir, rm, readFile, access } from "node:fs/promises"; |
3 | 3 | import { join } from "node:path"; |
4 | 4 | import { tmpdir } from "node:os"; |
5 | 5 | import { runSetup, runRemove } from "../src/setup.js"; |
@@ -90,3 +90,125 @@ describe("runRemove", () => { |
90 | 90 | expect(JSON.parse(restored).mcpServers.myserver.command).toBe("my-mcp"); |
91 | 91 | }); |
92 | 92 | }); |
| 93 | + |
| 94 | +describe("slash commands", () => { |
| 95 | + const testDir = join(tmpdir(), `flight-slash-${Date.now()}`); |
| 96 | + const commandsDir = join(testDir, ".claude", "commands"); |
| 97 | + const expectedFiles = [ |
| 98 | + "flight.md", |
| 99 | + "flight-log.md", |
| 100 | + "flight-review.md", |
| 101 | + "flight-compare.md", |
| 102 | + "flight-annotate.md", |
| 103 | + ]; |
| 104 | + |
| 105 | + afterEach(async () => { |
| 106 | + try { await rm(testDir, { recursive: true }); } catch { /* ignore */ } |
| 107 | + }); |
| 108 | + |
| 109 | + it("installs all five slash command files when slashCommands: true", async () => { |
| 110 | + const claudeDir = join(testDir, ".claude"); |
| 111 | + await mkdir(claudeDir, { recursive: true }); |
| 112 | + await writeFile(join(claudeDir, "settings.json"), JSON.stringify({})); |
| 113 | + |
| 114 | + await runSetup( |
| 115 | + { |
| 116 | + homeDir: testDir, |
| 117 | + settingsPath: join(claudeDir, "settings.json"), |
| 118 | + claudeCodeConfigPath: join(testDir, ".claude.json"), |
| 119 | + }, |
| 120 | + { hooks: false, proxy: false, pd: false, slashCommands: true, banner: true }, |
| 121 | + ); |
| 122 | + |
| 123 | + for (const filename of expectedFiles) { |
| 124 | + const filePath = join(commandsDir, filename); |
| 125 | + await expect(access(filePath)).resolves.toBeUndefined(); |
| 126 | + } |
| 127 | + }); |
| 128 | + |
| 129 | + it("each command body references flight logs (not flight log)", async () => { |
| 130 | + const claudeDir = join(testDir, ".claude"); |
| 131 | + await mkdir(claudeDir, { recursive: true }); |
| 132 | + await writeFile(join(claudeDir, "settings.json"), JSON.stringify({})); |
| 133 | + |
| 134 | + await runSetup( |
| 135 | + { |
| 136 | + homeDir: testDir, |
| 137 | + settingsPath: join(claudeDir, "settings.json"), |
| 138 | + claudeCodeConfigPath: join(testDir, ".claude.json"), |
| 139 | + }, |
| 140 | + { hooks: false, proxy: false, pd: false, slashCommands: true, banner: true }, |
| 141 | + ); |
| 142 | + |
| 143 | + for (const filename of expectedFiles) { |
| 144 | + const body = await readFile(join(commandsDir, filename), "utf-8"); |
| 145 | + // No body should reference the old "flight log " pattern (singular, with trailing space) |
| 146 | + expect(body).not.toMatch(/`flight log /); |
| 147 | + } |
| 148 | + }); |
| 149 | + |
| 150 | + it("command bodies reference the correct CLI verbs", async () => { |
| 151 | + const claudeDir = join(testDir, ".claude"); |
| 152 | + await mkdir(claudeDir, { recursive: true }); |
| 153 | + await writeFile(join(claudeDir, "settings.json"), JSON.stringify({})); |
| 154 | + |
| 155 | + await runSetup( |
| 156 | + { |
| 157 | + homeDir: testDir, |
| 158 | + settingsPath: join(claudeDir, "settings.json"), |
| 159 | + claudeCodeConfigPath: join(testDir, ".claude.json"), |
| 160 | + }, |
| 161 | + { hooks: false, proxy: false, pd: false, slashCommands: true, banner: true }, |
| 162 | + ); |
| 163 | + |
| 164 | + const flightBody = await readFile(join(commandsDir, "flight.md"), "utf-8"); |
| 165 | + expect(flightBody).toContain("flight logs audit"); |
| 166 | + |
| 167 | + const flightLogBody = await readFile(join(commandsDir, "flight-log.md"), "utf-8"); |
| 168 | + expect(flightLogBody).toContain("flight logs verbose"); |
| 169 | + |
| 170 | + const reviewBody = await readFile(join(commandsDir, "flight-review.md"), "utf-8"); |
| 171 | + expect(reviewBody).toContain("flight show $ARGUMENTS"); |
| 172 | + expect(reviewBody).toContain("flight logs verbose $ARGUMENTS"); |
| 173 | + |
| 174 | + const compareBody = await readFile(join(commandsDir, "flight-compare.md"), "utf-8"); |
| 175 | + expect(compareBody).toContain("flight experiment diff $ARGUMENTS"); |
| 176 | + |
| 177 | + const annotateBody = await readFile(join(commandsDir, "flight-annotate.md"), "utf-8"); |
| 178 | + expect(annotateBody).toContain("flight logs verbose $ARGUMENTS"); |
| 179 | + expect(annotateBody).toContain("flight annotate <turn-id> --label <label> --type turn"); |
| 180 | + }); |
| 181 | + |
| 182 | + it("removes all five slash command files on runRemove", async () => { |
| 183 | + const claudeDir = join(testDir, ".claude"); |
| 184 | + await mkdir(claudeDir, { recursive: true }); |
| 185 | + await writeFile(join(claudeDir, "settings.json"), JSON.stringify({})); |
| 186 | + |
| 187 | + // Install first |
| 188 | + await runSetup( |
| 189 | + { |
| 190 | + homeDir: testDir, |
| 191 | + settingsPath: join(claudeDir, "settings.json"), |
| 192 | + claudeCodeConfigPath: join(testDir, ".claude.json"), |
| 193 | + }, |
| 194 | + { hooks: false, proxy: false, pd: false, slashCommands: true, banner: true }, |
| 195 | + ); |
| 196 | + |
| 197 | + // Verify they exist |
| 198 | + for (const filename of expectedFiles) { |
| 199 | + await expect(access(join(commandsDir, filename))).resolves.toBeUndefined(); |
| 200 | + } |
| 201 | + |
| 202 | + // Remove |
| 203 | + await runRemove({ |
| 204 | + homeDir: testDir, |
| 205 | + settingsPath: join(claudeDir, "settings.json"), |
| 206 | + claudeCodeConfigPath: join(testDir, ".claude.json"), |
| 207 | + }); |
| 208 | + |
| 209 | + // Verify they're gone |
| 210 | + for (const filename of expectedFiles) { |
| 211 | + await expect(access(join(commandsDir, filename))).rejects.toThrow(); |
| 212 | + } |
| 213 | + }); |
| 214 | +}); |
0 commit comments