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

composerTrigger.test.ts

115 lines3.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 detectComposerTrigger,
5 parseSideChatCommand,
6 serializeComposerFileLink,
7} from "./composerTrigger.ts";
8​
9describe("detectComposerTrigger", () => {
10 it.each([
11 ["Run /tmp/build.sh", "Run /tmp/build.sh".length],
12 ["/etc/hosts", "/etc/hosts".length],
13 ["Use /etc/hosts now", "Use /et".length],
14 ["cmd /foo\\bar", "cmd /foo\\bar".length],
15 ["/Windows\\System32", "/Windows\\System32".length],
16 ])("keeps the path in %j out of the slash menu", (text, cursor) => {
17 expect(detectComposerTrigger(text, cursor)).toBeNull();
18 });
19​
20 it("keeps a slash in the line-leading model picker query", () => {
21 expect(detectComposerTrigger("/model openai/gpt", 17)).toMatchObject({
22 kind: "slash-model",
23 query: "openai/gpt",
24 });
25 });
26​
27 it.each(["/Model opus", "/MODEL opus"])(
28 "opens the model picker for capitalized %j the same as /model",
29 (text) => {
30 expect(detectComposerTrigger(text, text.length)).toMatchObject({
31 kind: "slash-model",
32 query: "opus",
33 });
34 },
35 );
36​
37 it.each(["Use /", "Use /review"])("detects the inline slash token in %j", (text) => {
38 expect(detectComposerTrigger(text, text.length)).toEqual({
39 kind: "slash-command",
40 query: text.slice(5),
41 rangeStart: 4,
42 rangeEnd: text.length,
43 });
44 });
45​
46 it.each(["Use/review", "https://example.com/review", "Use /review "])(
47 "does not trigger for %j",
48 (text) => expect(detectComposerTrigger(text, text.length)).toBeNull(),
49 );
50​
51 it.each(["$", "€", "𑿝"])("detects %s skill prefixes and their source range", (prefix) => {
52 const text = `Use ${prefix}review`;
53 expect(detectComposerTrigger(text, text.length)).toEqual({
54 kind: "skill",
55 query: "review",
56 rangeStart: 4,
57 rangeEnd: text.length,
58 });
59 });
60​
61 it.each([
62 "budget $9.99",
63 "only $.99",
64 "about €20",
65 "raise $10k",
66 "$1,000",
67 "£2e6",
68 "raise $10k.",
69 ])("does not open the skill menu for the amount in %j", (text) =>
70 expect(detectComposerTrigger(text, text.length)).toBeNull(),
71 );
72​
73 it.each(["$", "$1password", "$2fa"])("still detects the skill prefix %j", (text) => {
74 expect(detectComposerTrigger(text, text.length)).toMatchObject({
75 kind: "skill",
76 query: text.slice(1),
77 });
78 });
79});
80​
81describe("serializeComposerFileLink", () => {
82 it("encodes markdown-sensitive destination characters", () => {
83 expect(serializeComposerFileLink("docs/My File (draft).md")).toBe(
84 "[My File (draft).md](docs/My%20File%20%28draft%29.md)",
85 );
86 });
87​
88 it("supports windows paths", () => {
89 expect(serializeComposerFileLink("C:\\repo\\src\\index.ts")).toBe(
90 "[index.ts](C:%5Crepo%5Csrc%5Cindex.ts)",
91 );
92 });
93​
94 it("preserves paths that legitimately start with an at sign", () => {
95 expect(serializeComposerFileLink("@scope/package.json")).toBe(
96 "[package.json](@scope/package.json)",
97 );
98 });
99});
100​
101describe("parseSideChatCommand", () => {
102 it("reads an optional prompt after /side or /btw", () => {
103 expect(parseSideChatCommand("/side")).toEqual({ prompt: "" });
104 expect(parseSideChatCommand(" /SIDE why does this fail?\nline two ")).toEqual({
105 prompt: "why does this fail?\nline two",
106 });
107 expect(parseSideChatCommand("/btw check @src/a.ts")).toEqual({ prompt: "check @src/a.ts" });
108 });
109​
110 it("ignores other commands and inline mentions", () => {
111 expect(parseSideChatCommand("/sidebar")).toBeNull();
112 expect(parseSideChatCommand("/btwx")).toBeNull();
113 expect(parseSideChatCommand("ask /side later")).toBeNull();
114 });
115});