Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2import { ProviderDriverKind } from "@t3tools/contracts";
3
4vi.mock("../../state/queries", () => ({
5 useComposerPathSearch: () => ({ entries: [], isPending: false }),
6}));
7vi.mock("../../state/server", () => ({
8 serverEnvironment: { refreshProviders: Symbol("refreshProviders") },
9}));
10vi.mock("../../state/use-atom-command", () => ({
11 useAtomCommand: () => vi.fn(),
12}));
13
14import {
15 buildComposerSlashCommandItems,
16 resolveComposerCommandSelection,
17} from "./use-composer-command-menu";
18
19describe("mobile slash commands", () => {
20 const antigravity = {
21 driver: ProviderDriverKind.make("antigravity"),
22 showInteractionModeToggle: false,
23 slashCommands: [{ name: "plan", description: "Plan with Antigravity" }],
24 };
25
26 it.each([false, true])(
27 "keeps native /plan with legacy mode enabled=%s",
28 (allowInteractionMode) => {
29 const items = buildComposerSlashCommandItems({
30 query: "pl",
31 atMessageStart: true,
32 hasThread: true,
33 allowInteractionMode,
34 selectedProviderStatus: antigravity,
35 });
36
37 expect(items).toHaveLength(1);
38 expect(items[0]?.type).toBe("provider-slash-command");
39 const item = items[0];
40 if (!item) throw new Error("Expected the native plan command");
41 expect(
42 resolveComposerCommandSelection({
43 draftMessage: "/pl",
44 trigger: { rangeStart: 0, rangeEnd: 3 },
45 item,
46 allowInteractionMode,
47 }),
48 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
49 },
50 );
51
52 it("does not offer a native command inside the message", () => {
53 expect(
54 buildComposerSlashCommandItems({
55 query: "plan",
56 atMessageStart: false,
57 hasThread: false,
58 allowInteractionMode: true,
59 selectedProviderStatus: antigravity,
60 }),
61 ).toEqual([]);
62 });
63
64 it("still applies the T3 plan command for supported providers", () => {
65 const items = buildComposerSlashCommandItems({
66 query: "plan",
67 atMessageStart: true,
68 hasThread: true,
69 allowInteractionMode: true,
70 selectedProviderStatus: {
71 driver: ProviderDriverKind.make("codex"),
72 slashCommands: [],
73 },
74 });
75 const item = items[0];
76 if (!item) throw new Error("Expected the T3 plan command");
77 expect(
78 resolveComposerCommandSelection({
79 draftMessage: "/plan",
80 trigger: { rangeStart: 0, rangeEnd: 5 },
81 item,
82 allowInteractionMode: true,
83 }),
84 ).toEqual({ text: "", cursor: 0, interactionMode: "plan" });
85
86 // A provider switch can invalidate an open menu before a tap arrives.
87 expect(
88 resolveComposerCommandSelection({
89 draftMessage: "/plan",
90 trigger: { rangeStart: 0, rangeEnd: 5 },
91 item,
92 allowInteractionMode: false,
93 }),
94 ).toEqual({ text: "/plan ", cursor: 6, interactionMode: null });
95 });
96});