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

composer-logic.test.ts

708 lines24.1 KB

1import { filterComposerPullRequestMatches } from "@t3tools/shared/composerPullRequestMatches";
2import { EnvironmentId, MessageId, ThreadId, type AssistantCitation } from "@t3tools/contracts";
3import {
4 collectAssistantCitations,
5 expandAssistantCitationsForProvider,
6 serializeAssistantCitation,
7} from "@t3tools/shared/assistantCitations";
8import { describe, expect, it } from "vite-plus/test";
9​
10import {
11 clampCollapsedComposerCursor,
12 collapseExpandedComposerCursor,
13 composerSubmissionIntentForEnter,
14 detectComposerTrigger,
15 expandCollapsedComposerCursor,
16 formatAssistantCitationForComposer,
17 isCollapsedCursorAdjacentToInlineToken,
18 parseStandaloneComposerSlashCommand,
19 replaceTextRange,
20} from "./composer-logic";
21import { formatTerminalContextReference } from "./lib/terminalContext";
22​
23const terminalReference = formatTerminalContextReference({
24 id: "ctx-1",
25 terminalLabel: "Terminal 1",
26 lineStart: 3,
27 lineEnd: 4,
28});
29​
30const citation: AssistantCitation = {
31 version: 1,
32 environmentId: EnvironmentId.make("environment-1"),
33 threadId: ThreadId.make("thread-1"),
34 messageId: MessageId.make("message-1"),
35 text: "Keep Unicode 👋 and punctuation (here).",
36 start: 3,
37 end: 40,
38 prefix: "前: ",
39 suffix: " 後",
40};
41const citationSource = serializeAssistantCitation(citation).replaceAll("+", "%20");
42​
43describe("formatAssistantCitationForComposer", () => {
44 it.each([undefined, "", " \n\t "])(
45 "keeps citation-only insertion for a blank comment %j",
46 (comment) => {
47 expect(formatAssistantCitationForComposer(citation, comment)).toBe(
48 `${serializeAssistantCitation(citation)} `,
49 );
50 },
51 );
52​
53 it("binds a multiline comment to its citation without adding standalone prompt text", () => {
54 const comment = 'What does "keep" mean? 👋\n Please show an example.';
55 const text = formatAssistantCitationForComposer(citation, ` ${comment}\n`);
56 const boundCitation = { ...citation, comment };
57 expect(text).toBe(`${serializeAssistantCitation(boundCitation)} `);
58 expect(collectAssistantCitations(text).map((entry) => entry.citation)).toEqual([boundCitation]);
59 expect(expandAssistantCitationsForProvider(text)).toMatch(/^\[assistant-quote-1\] \n\n/);
60 });
61});
62​
63describe("composerSubmissionIntentForEnter", () => {
64 it.each([
65 ["enter", "one line", false, "foreground"],
66 ["enter", "two\nlines", false, "foreground"],
67 ["mod-enter-multiline", "one line", false, "foreground"],
68 ["mod-enter-multiline", "two\nlines", false, null],
69 ["mod-enter-multiline", "two\nlines", true, "foreground"],
70 ["mod-enter", "one line", false, null],
71 ["mod-enter", "one line", true, "foreground"],
72 ] as const)("uses %s for %j with modifier=%s", (sendShortcut, prompt, modifierKey, expected) => {
73 expect(
74 composerSubmissionIntentForEnter({
75 isMobileViewport: false,
76 shiftKey: false,
77 modifierKey,
78 isDraftThread: false,
79 sendShortcut,
80 prompt,
81 }),
82 ).toBe(expected);
83 });
84​
85 it.each([
86 ["enter", false, "alternate"],
87 ["enter", true, null],
88 ["mod-enter-multiline", false, "foreground"],
89 ["mod-enter-multiline", true, "alternate"],
90 ["mod-enter", false, "foreground"],
91 ["mod-enter", true, "alternate"],
92 ] as const)(
93 "resolves running follow-ups with %s and shift=%s",
94 (sendShortcut, shiftKey, expected) => {
95 expect(
96 composerSubmissionIntentForEnter({
97 isMobileViewport: false,
98 shiftKey,
99 modifierKey: true,
100 isDraftThread: false,
101 isRunning: true,
102 sendShortcut,
103 prompt: "two\nlines",
104 }),
105 ).toBe(expected);
106 },
107 );
108​
109 it("submits plain Enter on desktop", () => {
110 expect(
111 composerSubmissionIntentForEnter({
112 isMobileViewport: false,
113 shiftKey: false,
114 modifierKey: false,
115 isDraftThread: true,
116 }),
117 ).toBe("foreground");
118 });
119​
120 it("inserts a newline for plain Enter on mobile", () => {
121 expect(
122 composerSubmissionIntentForEnter({
123 isMobileViewport: true,
124 shiftKey: false,
125 modifierKey: false,
126 isDraftThread: true,
127 }),
128 ).toBeNull();
129 });
130​
131 it("inserts a newline for Shift+Enter", () => {
132 expect(
133 composerSubmissionIntentForEnter({
134 isMobileViewport: false,
135 shiftKey: true,
136 modifierKey: false,
137 isDraftThread: true,
138 }),
139 ).toBeNull();
140 });
141​
142 it("submits a new thread in the background with Mod+Enter", () => {
143 expect(
144 composerSubmissionIntentForEnter({
145 isMobileViewport: false,
146 shiftKey: false,
147 modifierKey: true,
148 isDraftThread: true,
149 }),
150 ).toBe("background");
151 });
152​
153 it("keeps Mod+Enter in the foreground for an active thread", () => {
154 expect(
155 composerSubmissionIntentForEnter({
156 isMobileViewport: false,
157 shiftKey: false,
158 modifierKey: true,
159 isDraftThread: false,
160 }),
161 ).toBe("foreground");
162 });
163});
164​
165describe("detectComposerTrigger", () => {
166 it("detects @path trigger at cursor", () => {
167 const text = "Please check @src/com";
168 const trigger = detectComposerTrigger(text, text.length);
169​
170 expect(trigger).toEqual({
171 kind: "path",
172 query: "src/com",
173 rangeStart: "Please check ".length,
174 rangeEnd: text.length,
175 });
176 });
177​
178 it("detects slash command token while typing command name", () => {
179 const text = "/mo";
180 const trigger = detectComposerTrigger(text, text.length);
181​
182 expect(trigger).toEqual({
183 kind: "slash-command",
184 query: "mo",
185 rangeStart: 0,
186 rangeEnd: text.length,
187 });
188 });
189​
190 it("keeps /model as a slash command item", () => {
191 const text = "/model";
192 const trigger = detectComposerTrigger(text, text.length);
193​
194 expect(trigger).toEqual({
195 kind: "slash-command",
196 query: "model",
197 rangeStart: 0,
198 rangeEnd: text.length,
199 });
200 });
201​
202 it("does not keep a subcommand trigger active after /model arguments", () => {
203 const text = "/model spark";
204 const trigger = detectComposerTrigger(text, text.length);
205​
206 expect(trigger).toBeNull();
207 });
208​
209 it("detects non-model slash commands while typing", () => {
210 const text = "/pl";
211 const trigger = detectComposerTrigger(text, text.length);
212​
213 expect(trigger).toEqual({
214 kind: "slash-command",
215 query: "pl",
216 rangeStart: 0,
217 rangeEnd: text.length,
218 });
219 });
220​
221 it("keeps slash command detection active for provider commands", () => {
222 const text = "/rev";
223 const trigger = detectComposerTrigger(text, text.length);
224​
225 expect(trigger).toEqual({
226 kind: "slash-command",
227 query: "rev",
228 rangeStart: 0,
229 rangeEnd: text.length,
230 });
231 });
232​
233 it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
234 "detects %sskill trigger at cursor",
235 (prefix) => {
236 const text = `Use ${prefix}gh-fi`;
237 const trigger = detectComposerTrigger(text, text.length);
238​
239 expect(trigger).toEqual({
240 kind: "skill",
241 query: "gh-fi",
242 rangeStart: "Use ".length,
243 rangeEnd: text.length,
244 });
245 },
246 );
247​
248 it("detects a pull request number at a token boundary", () => {
249 const text = "Compare this with #8737";
250​
251 expect(detectComposerTrigger(text, text.length)).toEqual({
252 kind: "pull-request",
253 query: "8737",
254 rangeStart: "Compare this with ".length,
255 rangeEnd: text.length,
256 });
257 });
258​
259 it("opens pull request completion from a bare hash", () => {
260 const text = "Compare with #";
261​
262 expect(detectComposerTrigger(text, text.length)).toEqual({
263 kind: "pull-request",
264 query: "",
265 rangeStart: "Compare with ".length,
266 rangeEnd: text.length,
267 });
268 });
269​
270 it("detects a one-word pull request search", () => {
271 const text = "Compare with #composer";
272​
273 expect(detectComposerTrigger(text, text.length)).toEqual({
274 kind: "pull-request",
275 query: "composer",
276 rangeStart: "Compare with ".length,
277 rangeEnd: text.length,
278 });
279 });
280​
281 it("supports hyphenated pull request search terms", () => {
282 const text = "Find #inline-context";
283​
284 expect(detectComposerTrigger(text, text.length)).toEqual({
285 kind: "pull-request",
286 query: "inline-context",
287 rangeStart: "Find ".length,
288 rangeEnd: text.length,
289 });
290 });
291​
292 it("does not keep pull request completion active for headings or embedded hashes", () => {
293 expect(detectComposerTrigger("# Heading", "# Heading".length)).toBeNull();
294 expect(detectComposerTrigger("issue#123", "issue#123".length)).toBeNull();
295 });
296​
297 it("detects @path trigger in the middle of existing text", () => {
298 // User typed @ between "inspect " and "in this sentence"
299 const text = "Please inspect @in this sentence";
300 const cursorAfterAt = "Please inspect @".length;
301​
302 const trigger = detectComposerTrigger(text, cursorAfterAt);
303 expect(trigger).toEqual({
304 kind: "path",
305 query: "",
306 rangeStart: "Please inspect ".length,
307 rangeEnd: cursorAfterAt,
308 });
309 });
310​
311 it("detects @path trigger with query typed mid-text", () => {
312 // User typed @sr between "inspect " and "in this sentence"
313 const text = "Please inspect @srin this sentence";
314 const cursorAfterQuery = "Please inspect @sr".length;
315​
316 const trigger = detectComposerTrigger(text, cursorAfterQuery);
317 expect(trigger).toEqual({
318 kind: "path",
319 query: "sr",
320 rangeStart: "Please inspect ".length,
321 rangeEnd: cursorAfterQuery,
322 });
323 });
324​
325 it("detects trigger with true cursor even when regex-based mention detection would false-match", () => {
326 // MENTION_TOKEN_REGEX can false-match plain text like "@in" as a mention.
327 // The fix bypasses it by computing the expanded cursor from the Lexical node tree.
328 const text = "Please inspect @in this sentence";
329 const cursorAfterAt = "Please inspect @".length;
330​
331 const trigger = detectComposerTrigger(text, cursorAfterAt);
332 expect(trigger).not.toBeNull();
333 expect(trigger?.kind).toBe("path");
334 expect(trigger?.query).toBe("");
335 });
336});
337​
338describe("filterComposerPullRequestMatches", () => {
339 const entries = [
340 {
341 number: 7,
342 projectId: "project-1",
343 repository: "t3tools/t3code",
344 updatedAt: "2026-09-01T12:00:00.000Z",
345 },
346 {
347 number: 8987,
348 projectId: "project-1",
349 repository: "T3Tools/T3Code",
350 updatedAt: "2026-09-03T12:00:00.000Z",
351 },
352 {
353 number: 27,
354 projectId: "project-1",
355 repository: "t3tools/t3code",
356 updatedAt: "2026-09-02T12:00:00.000Z",
357 },
358 {
359 number: 27,
360 projectId: "project-1",
361 repository: "t3tools/t3code",
362 updatedAt: "2026-09-01T13:00:00.000Z",
363 },
364 {
365 number: 70,
366 projectId: "project-2",
367 repository: "t3tools/other",
368 updatedAt: "2026-09-04T12:00:00.000Z",
369 },
370 ];
371​
372 it("matches and de-duplicates number fragments within one repository, exact match first", () => {
373 expect(
374 filterComposerPullRequestMatches({
375 entries,
376 projectId: "project-1",
377 repository: "t3tools/t3code",
378 query: "7",
379 limit: 10,
380 }).map((entry) => entry.number),
381 ).toEqual([7, 8987, 27]);
382 });
383​
384 it("keeps an older exact match when newer substring matches would fill the limit", () => {
385 const exact = {
386 number: 7,
387 projectId: "project-1",
388 repository: "t3tools/t3code",
389 updatedAt: "2020-01-01T00:00:00.000Z",
390 };
391 const newerSubstringMatches = Array.from({ length: 12 }, (_unused, index) => ({
392 number: 700 + index,
393 projectId: "project-1",
394 repository: "t3tools/t3code",
395 updatedAt: `2026-09-${String(index + 1).padStart(2, "0")}T12:00:00.000Z`,
396 }));
397 const matches = filterComposerPullRequestMatches({
398 entries: [...newerSubstringMatches, exact],
399 projectId: "project-1",
400 repository: "t3tools/t3code",
401 query: "7",
402 limit: 10,
403 });
404 expect(matches[0]?.number).toBe(7);
405 expect(matches).toHaveLength(10);
406 });
407​
408 it("uses an empty query for a capped recent list", () => {
409 expect(
410 filterComposerPullRequestMatches({
411 entries,
412 projectId: "project-1",
413 repository: "t3tools/t3code",
414 query: "",
415 limit: 2,
416 }).map((entry) => entry.number),
417 ).toEqual([8987, 27]);
418 });
419});
420​
421describe("replaceTextRange", () => {
422 it("replaces a text range and returns new cursor", () => {
423 const replaced = replaceTextRange("hello @src", 6, 10, "");
424 expect(replaced).toEqual({
425 text: "hello ",
426 cursor: 6,
427 });
428 });
429});
430​
431describe("expandCollapsedComposerCursor", () => {
432 it("keeps cursor unchanged when no mention segment is present", () => {
433 expect(expandCollapsedComposerCursor("plain text", 5)).toBe(5);
434 });
435​
436 it("maps collapsed mention cursor to expanded text cursor", () => {
437 const text = "what's in my @AGENTS.md fsfdas";
438 const collapsedCursorAfterMention = "what's in my ".length + 2;
439 const expandedCursorAfterMention = "what's in my @AGENTS.md ".length;
440​
441 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
442 expandedCursorAfterMention,
443 );
444 });
445​
446 it("maps collapsed quoted mention cursor to expanded text cursor", () => {
447 const text = 'what is in @"My File.md" please';
448 const collapsedCursorAfterMention = "what is in ".length + 2;
449 const expandedCursorAfterMention = 'what is in @"My File.md" '.length;
450​
451 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
452 expandedCursorAfterMention,
453 );
454 });
455​
456 it("maps collapsed markdown file links to their expanded source offsets", () => {
457 const text = "what's in [AGENTS.md](AGENTS.md) please";
458 const collapsedCursorAfterMention = "what's in ".length + 2;
459 const expandedCursorAfterMention = "what's in [AGENTS.md](AGENTS.md) ".length;
460​
461 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
462 expandedCursorAfterMention,
463 );
464 });
465​
466 it("allows path trigger detection to close after selecting a mention", () => {
467 const text = "what's in my @AGENTS.md ";
468 const collapsedCursorAfterMention = "what's in my ".length + 2;
469 const expandedCursor = expandCollapsedComposerCursor(text, collapsedCursorAfterMention);
470​
471 expect(detectComposerTrigger(text, expandedCursor)).toBeNull();
472 });
473​
474 it.each(["$", "€", "𑿝"])("maps collapsed %s skill cursor to expanded text cursor", (prefix) => {
475 const text = `run ${prefix}review-follow-up then`;
476 const collapsedCursorAfterSkill = "run ".length + 2;
477 const expandedCursorAfterSkill = `run ${prefix}review-follow-up `.length;
478​
479 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterSkill)).toBe(
480 expandedCursorAfterSkill,
481 );
482 });
483});
484​
485describe("collapseExpandedComposerCursor", () => {
486 it("keeps cursor unchanged when no mention segment is present", () => {
487 expect(collapseExpandedComposerCursor("plain text", 5)).toBe(5);
488 });
489​
490 it("maps expanded mention cursor back to collapsed cursor", () => {
491 const text = "what's in my @AGENTS.md fsfdas";
492 const collapsedCursorAfterMention = "what's in my ".length + 2;
493 const expandedCursorAfterMention = "what's in my @AGENTS.md ".length;
494​
495 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
496 collapsedCursorAfterMention,
497 );
498 });
499​
500 it("maps expanded quoted mention cursor back to collapsed cursor", () => {
501 const text = 'what is in @"My File.md" please';
502 const collapsedCursorAfterMention = "what is in ".length + 2;
503 const expandedCursorAfterMention = 'what is in @"My File.md" '.length;
504​
505 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
506 collapsedCursorAfterMention,
507 );
508 });
509​
510 it("maps expanded markdown file link cursors back to collapsed offsets", () => {
511 const text = "what's in [AGENTS.md](AGENTS.md) please";
512 const collapsedCursorAfterMention = "what's in ".length + 2;
513 const expandedCursorAfterMention = "what's in [AGENTS.md](AGENTS.md) ".length;
514​
515 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
516 collapsedCursorAfterMention,
517 );
518 });
519​
520 it("keeps package-like text expanded when another mention already exists earlier", () => {
521 const text = "open @AGENTS.md then @src/index.ts ";
522 const expandedCursor = text.length;
523 const collapsedCursor = collapseExpandedComposerCursor(text, expandedCursor);
524​
525 expect(collapsedCursor).toBe("open ".length + 1 + " then @src/index.ts ".length);
526 expect(expandCollapsedComposerCursor(text, collapsedCursor)).toBe(expandedCursor);
527 });
528​
529 it("collapses only genuine mentions when package-like text exists earlier", () => {
530 const text = "install @scope/pkg then @README.md ";
531 const expandedCursor = text.length;
532 const collapsedCursor = collapseExpandedComposerCursor(text, expandedCursor);
533​
534 expect(collapsedCursor).toBe("install @scope/pkg then ".length + 1 + " ".length);
535 expect(expandCollapsedComposerCursor(text, collapsedCursor)).toBe(expandedCursor);
536 });
537​
538 it.each(["$", "€", "𑿝"])("maps expanded %s skill cursor back to collapsed cursor", (prefix) => {
539 const text = `run ${prefix}review-follow-up then`;
540 const collapsedCursorAfterSkill = "run ".length + 2;
541 const expandedCursorAfterSkill = `run ${prefix}review-follow-up `.length;
542​
543 expect(collapseExpandedComposerCursor(text, expandedCursorAfterSkill)).toBe(
544 collapsedCursorAfterSkill,
545 );
546 });
547});
548​
549it("preserves the caret before trailing text after mixed-width skill chips", () => {
550 const text = "𑿝ui a $review tail";
551 const expanded = "𑿝ui a $review ".length;
552 expect(collapseExpandedComposerCursor(text, expanded)).toBe(6);
553 expect(expandCollapsedComposerCursor(text, 6)).toBe(expanded);
554});
555​
556describe("clampCollapsedComposerCursor", () => {
557 it("clamps to collapsed prompt length when mentions are present", () => {
558 const text = "open @AGENTS.md then ";
559​
560 expect(clampCollapsedComposerCursor(text, text.length)).toBe(
561 "open ".length + 1 + " then ".length,
562 );
563 expect(clampCollapsedComposerCursor(text, Number.POSITIVE_INFINITY)).toBe(
564 "open ".length + 1 + " then ".length,
565 );
566 });
567});
568​
569describe("assistant citation cursor offsets", () => {
570 it("roundtrips every collapsed offset across citations, mentions, skills, and Unicode", () => {
571 const prefix = "👋(";
572 const between = "),雪";
573 const after = " @AGENTS.md $review ";
574 const text = `${prefix}${citationSource}${between}${citationSource}${after}${terminalReference}!`;
575 const collapsedLength = `${prefix}□${between}□ □ □ □!`.length;
576 const boundaries = [
577 [prefix.length, prefix.length],
578 [prefix.length + 1, prefix.length + citationSource.length],
579 [prefix.length + 1 + between.length, prefix.length + citationSource.length + between.length],
580 [
581 prefix.length + 2 + between.length,
582 prefix.length + citationSource.length * 2 + between.length,
583 ],
584 [collapsedLength, text.length],
585 ] as const;
586​
587 for (const [collapsed, expanded] of boundaries) {
588 expect(expandCollapsedComposerCursor(text, collapsed)).toBe(expanded);
589 expect(collapseExpandedComposerCursor(text, expanded)).toBe(collapsed);
590 }
591 for (let cursor = 0; cursor <= collapsedLength; cursor += 1) {
592 expect(
593 collapseExpandedComposerCursor(text, expandCollapsedComposerCursor(text, cursor)),
594 ).toBe(cursor);
595 }
596 expect(clampCollapsedComposerCursor(text, Number.POSITIVE_INFINITY)).toBe(collapsedLength);
597 });
598​
599 it("snaps serialized offsets inside a citation to the end of its chip", () => {
600 const prefix = "前👋";
601 const text = `${prefix}${citationSource}.`;
602​
603 for (const offset of [1, citationSource.length - 1, citationSource.length]) {
604 expect(collapseExpandedComposerCursor(text, prefix.length + offset)).toBe(prefix.length + 1);
605 }
606 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length, "right")).toBe(true);
607 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length + 1, "left")).toBe(true);
608 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length + 2, "left")).toBe(false);
609 });
610​
611 it("deletes one collapsed citation without changing its neighbor or surrounding punctuation", () => {
612 const text = `(${citationSource}),${citationSource}!`;
613 const result = replaceTextRange(
614 text,
615 expandCollapsedComposerCursor(text, 1),
616 expandCollapsedComposerCursor(text, 2),
617 "",
618 );
619​
620 expect(result).toEqual({ text: `(),${citationSource}!`, cursor: 1 });
621 expect(collapseExpandedComposerCursor(result.text, result.text.length)).toBe("(),□!".length);
622 });
623});
624​
625describe("replaceTextRange trailing space consumption", () => {
626 it("double space after insertion when replacement ends with space", () => {
627 // Simulates: "and then |@AG| summarize" where | marks replacement range
628 // The replacement is "@AGENTS.md " (with trailing space)
629 // But if we don't extend rangeEnd, the existing space stays
630 const text = "and then @AG summarize";
631 const rangeStart = "and then ".length;
632 const rangeEnd = "and then @AG".length;
633​
634 // Without consuming trailing space: double space
635 const withoutConsume = replaceTextRange(text, rangeStart, rangeEnd, "@AGENTS.md ");
636 expect(withoutConsume.text).toBe("and then @AGENTS.md summarize");
637​
638 // With consuming trailing space: single space
639 const extendedEnd = text[rangeEnd] === " " ? rangeEnd + 1 : rangeEnd;
640 const withConsume = replaceTextRange(text, rangeStart, extendedEnd, "@AGENTS.md ");
641 expect(withConsume.text).toBe("and then @AGENTS.md summarize");
642 });
643});
644​
645describe("isCollapsedCursorAdjacentToInlineToken", () => {
646 it("returns false when no mention exists", () => {
647 expect(isCollapsedCursorAdjacentToInlineToken("plain text", 6, "left")).toBe(false);
648 expect(isCollapsedCursorAdjacentToInlineToken("plain text", 6, "right")).toBe(false);
649 });
650​
651 it("keeps @query typing non-adjacent while no mention pill exists", () => {
652 const text = "hello @pac";
653 expect(isCollapsedCursorAdjacentToInlineToken(text, text.length, "left")).toBe(false);
654 expect(isCollapsedCursorAdjacentToInlineToken(text, text.length, "right")).toBe(false);
655 });
656​
657 it("detects left adjacency only when cursor is directly after a mention", () => {
658 const text = "open @AGENTS.md next";
659 const mentionStart = "open ".length;
660 const mentionEnd = mentionStart + 1;
661​
662 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd, "left")).toBe(true);
663 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart, "left")).toBe(false);
664 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd + 1, "left")).toBe(false);
665 });
666​
667 it("detects right adjacency only when cursor is directly before a mention", () => {
668 const text = "open @AGENTS.md next";
669 const mentionStart = "open ".length;
670 const mentionEnd = mentionStart + 1;
671​
672 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart, "right")).toBe(true);
673 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd, "right")).toBe(false);
674 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart - 1, "right")).toBe(false);
675 });
676​
677 it("treats context reference pills as inline tokens for adjacency checks", () => {
678 const text = `open ${terminalReference} next`;
679 const tokenStart = "open ".length;
680 const tokenEnd = tokenStart + 1;
681​
682 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenEnd, "left")).toBe(true);
683 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenStart, "right")).toBe(true);
684 });
685​
686 it("treats skill pills as inline tokens for adjacency checks", () => {
687 const text = "run $review-follow-up next";
688 const tokenStart = "run ".length;
689 const tokenEnd = tokenStart + 1;
690​
691 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenEnd, "left")).toBe(true);
692 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenStart, "right")).toBe(true);
693 });
694});
695​
696describe("parseStandaloneComposerSlashCommand", () => {
697 it("parses standalone /plan command", () => {
698 expect(parseStandaloneComposerSlashCommand(" /plan ")).toBe("plan");
699 });
700​
701 it("parses standalone /default command", () => {
702 expect(parseStandaloneComposerSlashCommand("/default")).toBe("default");
703 });
704​
705 it("ignores slash commands with extra message text", () => {
706 expect(parseStandaloneComposerSlashCommand("/plan explain this")).toBeNull();
707 });
708});