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