Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { collectComposerInlineTokens } from "./composerInlineTokens.ts";
4
5describe("collectComposerInlineTokens", () => {
6 it("collects file links, mentions, and skills with source ranges", () => {
7 const text = "Use $ui and inspect [Chat.tsx](src/Chat.tsx) with @AGENTS.md please";
8
9 expect(collectComposerInlineTokens(text)).toEqual([
10 {
11 type: "skill",
12 value: "ui",
13 source: "$ui",
14 start: 4,
15 end: 7,
16 },
17 {
18 type: "mention",
19 value: "src/Chat.tsx",
20 source: "[Chat.tsx](src/Chat.tsx)",
21 start: 20,
22 end: 44,
23 },
24 {
25 type: "mention",
26 value: "AGENTS.md",
27 source: "@AGENTS.md",
28 start: 50,
29 end: 60,
30 },
31 ]);
32 });
33
34 it("does not convert incomplete trailing tokens", () => {
35 expect(collectComposerInlineTokens("Use $ui")).toEqual([]);
36 expect(collectComposerInlineTokens("Inspect @AGENTS.md")).toEqual([]);
37 });
38
39 it("keeps the delimiter after a token outside its source range", () => {
40 const text = "Inspect [package.json](package.json) next";
41
42 expect(collectComposerInlineTokens(text)).toEqual([
43 {
44 type: "mention",
45 value: "package.json",
46 source: "[package.json](package.json)",
47 start: 8,
48 end: 36,
49 },
50 ]);
51 expect(text.slice(36)).toBe(" next");
52 });
53
54 it("preserves a confirmed pill when only its trailing delimiter is removed", () => {
55 const withDelimiter = "[package.json](package.json) ";
56 const confirmed = collectComposerInlineTokens(withDelimiter);
57
58 expect(
59 collectComposerInlineTokens(withDelimiter.trimEnd(), { preserveTrailingFrom: confirmed }),
60 ).toEqual([
61 {
62 type: "mention",
63 value: "package.json",
64 source: "[package.json](package.json)",
65 start: 0,
66 end: 28,
67 },
68 ]);
69 });
70
71 it("does not preserve a pill after its source is edited", () => {
72 const confirmed = collectComposerInlineTokens("[package.json](package.json) ");
73
74 expect(
75 collectComposerInlineTokens("[package.json](package-json)", {
76 preserveTrailingFrom: confirmed,
77 }),
78 ).toEqual([]);
79 });
80
81 it("ignores normal web links", () => {
82 expect(collectComposerInlineTokens("Read [docs](https://example.com) first")).toEqual([]);
83 });
84});