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

composer-editor-mentions.test.ts

99 lines3.1 KB

1import { describe, expect, it } from "vitest";
2​
3import {
4 selectionTouchesMentionBoundary,
5 splitPromptIntoComposerSegments,
6} from "./composer-editor-mentions";
7import { INLINE_TERMINAL_CONTEXT_PLACEHOLDER } from "./lib/terminalContext";
8​
9describe("splitPromptIntoComposerSegments", () => {
10 it("splits mention tokens followed by whitespace into mention segments", () => {
11 expect(splitPromptIntoComposerSegments("Inspect @AGENTS.md please")).toEqual([
12 { type: "text", text: "Inspect " },
13 { type: "mention", path: "AGENTS.md" },
14 { type: "text", text: " please" },
15 ]);
16 });
17​
18 it("does not convert an incomplete trailing mention token", () => {
19 expect(splitPromptIntoComposerSegments("Inspect @AGENTS.md")).toEqual([
20 { type: "text", text: "Inspect @AGENTS.md" },
21 ]);
22 });
23​
24 it("keeps newlines around mention tokens", () => {
25 expect(splitPromptIntoComposerSegments("one\n@src/index.ts \ntwo")).toEqual([
26 { type: "text", text: "one\n" },
27 { type: "mention", path: "src/index.ts" },
28 { type: "text", text: " \ntwo" },
29 ]);
30 });
31​
32 it("keeps inline terminal context placeholders at their prompt positions", () => {
33 expect(
34 splitPromptIntoComposerSegments(
35 `Inspect ${INLINE_TERMINAL_CONTEXT_PLACEHOLDER}@AGENTS.md please`,
36 ),
37 ).toEqual([
38 { type: "text", text: "Inspect " },
39 { type: "terminal-context", context: null },
40 { type: "mention", path: "AGENTS.md" },
41 { type: "text", text: " please" },
42 ]);
43 });
44​
45 it("preserves consecutive terminal context placeholders without dropping positions", () => {
46 expect(
47 splitPromptIntoComposerSegments(
48 `${INLINE_TERMINAL_CONTEXT_PLACEHOLDER}${INLINE_TERMINAL_CONTEXT_PLACEHOLDER}tail`,
49 ),
50 ).toEqual([
51 { type: "terminal-context", context: null },
52 { type: "terminal-context", context: null },
53 { type: "text", text: "tail" },
54 ]);
55 });
56});
57​
58describe("selectionTouchesMentionBoundary", () => {
59 it("returns true when selection includes the whitespace after a mention", () => {
60 expect(
61 selectionTouchesMentionBoundary(
62 "hi @package.json there",
63 "hi @package.json".length,
64 "hi @package.json there".length,
65 ),
66 ).toBe(true);
67 });
68​
69 it("returns true when selection includes the whitespace before a mention", () => {
70 expect(
71 selectionTouchesMentionBoundary(
72 "hi there @package.json later",
73 "hi there".length,
74 "hi there ".length,
75 ),
76 ).toBe(true);
77 });
78​
79 it("returns false when selection starts after the mention boundary whitespace", () => {
80 expect(
81 selectionTouchesMentionBoundary(
82 "hi @package.json there",
83 "hi @package.json ".length,
84 "hi @package.json there".length,
85 ),
86 ).toBe(false);
87 });
88​
89 it("returns true when selection includes whitespace after a mention following a terminal placeholder", () => {
90 const prompt = `${INLINE_TERMINAL_CONTEXT_PLACEHOLDER}@AGENTS.md there`;
91 expect(
92 selectionTouchesMentionBoundary(
93 prompt,
94 `${INLINE_TERMINAL_CONTEXT_PLACEHOLDER}@AGENTS.md`.length,
95 prompt.length,
96 ),
97 ).toBe(true);
98 });
99});