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

ClaudeSkillDispatch.test.ts

81 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
4​
5const SKILLS = new Set(["2spec", "implement", "review", "re-release-version"]);
6​
7describe("planClaudeSkillDispatch", () => {
8 it("leaves a prompt without a known skill untouched", () => {
9 expect(planClaudeSkillDispatch("fix the build", SKILLS)).toBeUndefined();
10 expect(planClaudeSkillDispatch("echo $HOME then $unknown", SKILLS)).toBeUndefined();
11 });
12​
13 it("moves a mid-prompt mention into a trailing slash command", () => {
14 expect(planClaudeSkillDispatch("ok, now $implement all the tickets", SKILLS)).toEqual({
15 leadingText: "ok, now",
16 commandText: "/implement all the tickets",
17 skillName: "implement",
18 });
19 });
20​
21 it("keeps a mention that opens the prompt as a single command block", () => {
22 expect(planClaudeSkillDispatch("$review\nfocus on auth", SKILLS)).toEqual({
23 leadingText: undefined,
24 commandText: "/review\nfocus on auth",
25 skillName: "review",
26 });
27 });
28​
29 it("dispatches a known skill whose name begins with a digit", () => {
30 expect(planClaudeSkillDispatch("use $2spec for this", SKILLS)).toEqual({
31 leadingText: "use",
32 commandText: "/2spec for this",
33 skillName: "2spec",
34 });
35 });
36​
37 it("dispatches the last mention and rewrites earlier ones inline", () => {
38 expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({
39 leadingText: "/review the diff, then",
40 commandText: "/implement the fixes",
41 skillName: "implement",
42 });
43 });
44​
45 it("dispatches currency-prefixed mentions and preserves their source boundaries", () => {
46 for (const symbol of ["€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
47 expect(
48 planClaudeSkillDispatch(
49 `${symbol}review the diff, then ${symbol}implement the fixes`,
50 SKILLS,
51 ),
52 ).toEqual({
53 leadingText: "/review the diff, then",
54 commandText: "/implement the fixes",
55 skillName: "implement",
56 });
57 expect(planClaudeSkillDispatch(`${symbol}2spec for this`, SKILLS)).toEqual({
58 leadingText: undefined,
59 commandText: "/2spec for this",
60 skillName: "2spec",
61 });
62 expect(planClaudeSkillDispatch(`5${symbol}review ${symbol}unknown`, SKILLS)).toBeUndefined();
63 }
64 });
65​
66 it("ignores a dollar token glued to other text", () => {
67 expect(planClaudeSkillDispatch("cost is 5$implement", SKILLS)).toBeUndefined();
68 });
69​
70 it("ignores currency amounts and compact monetary expressions", () => {
71 const skillsWithCurrency = new Set([...SKILLS, "20", "20k", "100M", "1e6"]);
72 for (const symbol of ["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"]) {
73 expect(
74 planClaudeSkillDispatch(
75 `pay ${symbol}20 ${symbol}20k ${symbol}100M ${symbol}1e6 tomorrow`,
76 skillsWithCurrency,
77 ),
78 ).toBeUndefined();
79 }
80 });
81});