Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ClaudeSkillDispatch.test.ts

92 lines3.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { planClaudeSkillDispatch, type ClaudeSkillTarget } from "./ClaudeSkillDispatch.ts";
4​
5const skillPath = (name: string) => `/home/me/.claude/skills/${name}/SKILL.md`;
6​
7const skillMap = (names: Iterable<string>) =>
8 new Map<string, ClaudeSkillTarget>([...names].map((name) => [name, { path: skillPath(name) }]));
9​
10const SKILLS = skillMap(["2spec", "implement", "review", "re-release-version"]);
11​
12describe("planClaudeSkillDispatch", () => {
13 // regression: #9128 skills picked from the composer did not run
14 it("leaves a prompt without a known skill untouched", () => {
15 expect(planClaudeSkillDispatch("fix the build", SKILLS)).toBeUndefined();
16 expect(planClaudeSkillDispatch("echo $HOME then $unknown", SKILLS)).toBeUndefined();
17 });
18​
19 it("keeps the whole request ahead of a mid-prompt slash command", () => {
20 expect(planClaudeSkillDispatch("ok, now $implement all the tickets", SKILLS)).toEqual({
21 leadingText: "ok, now /implement all the tickets",
22 commandText: "/implement all the tickets",
23 skillName: "implement",
24 });
25 });
26​
27 it("keeps a mention that opens the prompt as a single command block", () => {
28 expect(planClaudeSkillDispatch("$review\nfocus on auth", SKILLS)).toEqual({
29 leadingText: undefined,
30 commandText: "/review\nfocus on auth",
31 skillName: "review",
32 });
33 });
34​
35 it("dispatches the last mention and rewrites earlier ones inline", () => {
36 expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({
37 leadingText: "/review the diff, then /implement the fixes",
38 commandText: "/implement the fixes",
39 skillName: "implement",
40 });
41 });
42​
43 it("dispatches currency-prefixed mentions and preserves their source boundaries", () => {
44 for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
45 expect(
46 planClaudeSkillDispatch(
47 `${symbol}review the diff, then ${symbol}implement the fixes`,
48 SKILLS,
49 ),
50 ).toEqual({
51 leadingText: "/review the diff, then /implement the fixes",
52 commandText: "/implement the fixes",
53 skillName: "implement",
54 });
55 expect(planClaudeSkillDispatch(`${symbol}2spec for this`, SKILLS)).toEqual({
56 leadingText: undefined,
57 commandText: "/2spec for this",
58 skillName: "2spec",
59 });
60 expect(planClaudeSkillDispatch(`5${symbol}review ${symbol}unknown`, SKILLS)).toBeUndefined();
61 }
62 });
63​
64 it("ignores currency amounts and compact monetary expressions", () => {
65 const skillsWithCurrency = skillMap([...SKILLS.keys(), "20", "20k", "100M", "1e6"]);
66 for (const symbol of ["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
67 expect(
68 planClaudeSkillDispatch(
69 `pay ${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6 tomorrow`,
70 skillsWithCurrency,
71 ),
72 ).toBeUndefined();
73 }
74 });
75​
76 it("bounds notes for repeated user-only skills and leaves the native dispatch unannotated", () => {
77 const skills = new Map([
78 ["interrogate", { path: skillPath("interrogate"), userInvocationOnly: true }],
79 ["implement", { path: skillPath("implement"), userInvocationOnly: true }],
80 ]);
81 expect(
82 planClaudeSkillDispatch(
83 "$interrogate then $interrogate then $implement and $implement the fixes",
84 skills,
85 ),
86 ).toEqual({
87 leadingText: `/interrogate [The user invoked this skill. Follow the instructions at: ${skillPath("interrogate")}] then /interrogate then /implement and /implement the fixes`,
88 commandText: "/implement the fixes",
89 skillName: "implement",
90 });
91 });
92});