@abacus-ai/cli 2.0.0-canary.1 → 2.0.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +448 -422
- package/package.json +4 -1
- package/.oxlintrc.json +0 -8
- package/resources/abacus.ico +0 -0
- package/resources/entitlements.plist +0 -9
- package/src/__e2e__/README.md +0 -196
- package/src/__e2e__/agent-interactions.e2e.test.tsx +0 -61
- package/src/__e2e__/cli-commands.e2e.test.tsx +0 -77
- package/src/__e2e__/conversation-throttle.e2e.test.ts +0 -453
- package/src/__e2e__/conversation.e2e.test.tsx +0 -56
- package/src/__e2e__/diff-preview.e2e.test.tsx +0 -3399
- package/src/__e2e__/file-creation.e2e.test.tsx +0 -149
- package/src/__e2e__/helpers/test-helpers.ts +0 -449
- package/src/__e2e__/keyboard-navigation.e2e.test.tsx +0 -34
- package/src/__e2e__/llm-models.e2e.test.ts +0 -402
- package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +0 -71
- package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +0 -167
- package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +0 -185
- package/src/__e2e__/repl.e2e.test.tsx +0 -78
- package/src/__e2e__/shell-compatibility.e2e.test.tsx +0 -76
- package/src/__e2e__/theme-mcp.e2e.test.tsx +0 -98
- package/src/__e2e__/tool-permissions.e2e.test.tsx +0 -66
- package/src/args.ts +0 -22
- package/src/components/__tests__/react-compiler.test.tsx +0 -78
- package/src/components/__tests__/status-indicator.test.tsx +0 -403
- package/src/components/composer/__tests__/bash-runner.test.tsx +0 -263
- package/src/components/composer/agent-mode-indicator.tsx +0 -63
- package/src/components/composer/bash-runner.tsx +0 -54
- package/src/components/composer/commands/default-commands.tsx +0 -615
- package/src/components/composer/commands/handler.tsx +0 -59
- package/src/components/composer/commands/picker.tsx +0 -273
- package/src/components/composer/commands/registry.ts +0 -233
- package/src/components/composer/commands/types.ts +0 -33
- package/src/components/composer/context.tsx +0 -88
- package/src/components/composer/file-mention-picker.tsx +0 -83
- package/src/components/composer/help.tsx +0 -44
- package/src/components/composer/index.tsx +0 -1007
- package/src/components/composer/mentions.ts +0 -57
- package/src/components/composer/message-queue.tsx +0 -70
- package/src/components/composer/mode-panel.tsx +0 -35
- package/src/components/composer/modes/__tests__/bash-handler.test.tsx +0 -755
- package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +0 -1108
- package/src/components/composer/modes/bash-handler.tsx +0 -132
- package/src/components/composer/modes/bash-renderer.tsx +0 -175
- package/src/components/composer/modes/default-handlers.tsx +0 -33
- package/src/components/composer/modes/index.ts +0 -41
- package/src/components/composer/modes/types.ts +0 -21
- package/src/components/composer/persistent-shell.ts +0 -283
- package/src/components/composer/process.ts +0 -65
- package/src/components/composer/types.ts +0 -9
- package/src/components/composer/use-mention-search.ts +0 -68
- package/src/components/error-boundry.tsx +0 -60
- package/src/components/exit-message.tsx +0 -29
- package/src/components/expanded-view.tsx +0 -74
- package/src/components/file-completion.tsx +0 -127
- package/src/components/header.tsx +0 -47
- package/src/components/logo.tsx +0 -37
- package/src/components/segments.tsx +0 -356
- package/src/components/status-indicator.tsx +0 -306
- package/src/components/tool-group-summary.tsx +0 -263
- package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +0 -319
- package/src/components/tool-permissions/diff-preview.tsx +0 -359
- package/src/components/tool-permissions/index.ts +0 -5
- package/src/components/tool-permissions/permission-options.tsx +0 -401
- package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
- package/src/components/tool-permissions/tool-permission-ui.tsx +0 -420
- package/src/components/tools/agent/ask-user-question.tsx +0 -107
- package/src/components/tools/agent/enter-plan-mode.tsx +0 -55
- package/src/components/tools/agent/exit-plan-mode.tsx +0 -83
- package/src/components/tools/agent/handoff-to-main.tsx +0 -27
- package/src/components/tools/agent/subagent.tsx +0 -37
- package/src/components/tools/agent/todo-write.tsx +0 -104
- package/src/components/tools/browser/close-tab.tsx +0 -58
- package/src/components/tools/browser/computer.tsx +0 -70
- package/src/components/tools/browser/get-interactive-elements.tsx +0 -54
- package/src/components/tools/browser/get-tab-content.tsx +0 -51
- package/src/components/tools/browser/navigate-to.tsx +0 -59
- package/src/components/tools/browser/new-tab.tsx +0 -60
- package/src/components/tools/browser/perform-action.tsx +0 -63
- package/src/components/tools/browser/refresh-tab.tsx +0 -43
- package/src/components/tools/browser/switch-tab.tsx +0 -58
- package/src/components/tools/filesystem/delete-file.tsx +0 -104
- package/src/components/tools/filesystem/edit.tsx +0 -220
- package/src/components/tools/filesystem/list-dir.tsx +0 -78
- package/src/components/tools/filesystem/read-file.tsx +0 -180
- package/src/components/tools/filesystem/upload-image.tsx +0 -76
- package/src/components/tools/ide/ide-diagnostics.tsx +0 -62
- package/src/components/tools/index.ts +0 -91
- package/src/components/tools/mcp/mcp-tool.tsx +0 -158
- package/src/components/tools/search/fetch-url.tsx +0 -73
- package/src/components/tools/search/file-search.tsx +0 -78
- package/src/components/tools/search/grep.tsx +0 -90
- package/src/components/tools/search/semantic-search.tsx +0 -66
- package/src/components/tools/search/web-search.tsx +0 -71
- package/src/components/tools/shared/index.tsx +0 -48
- package/src/components/tools/shared/zod-coercion.ts +0 -35
- package/src/components/tools/terminal/bash-tool-output.tsx +0 -188
- package/src/components/tools/terminal/get-terminal-output.tsx +0 -91
- package/src/components/tools/terminal/run-in-terminal.tsx +0 -131
- package/src/components/tools/types.ts +0 -16
- package/src/components/tools.tsx +0 -68
- package/src/components/ui/__tests__/divider.test.tsx +0 -61
- package/src/components/ui/__tests__/gradient.test.tsx +0 -125
- package/src/components/ui/__tests__/input.test.tsx +0 -166
- package/src/components/ui/__tests__/select.test.tsx +0 -273
- package/src/components/ui/__tests__/shimmer.test.tsx +0 -99
- package/src/components/ui/blinking-indicator.tsx +0 -27
- package/src/components/ui/divider.tsx +0 -162
- package/src/components/ui/gradient.tsx +0 -56
- package/src/components/ui/input.tsx +0 -228
- package/src/components/ui/select.tsx +0 -151
- package/src/components/ui/shimmer.tsx +0 -76
- package/src/context/agent-mode.tsx +0 -95
- package/src/context/extension-file.tsx +0 -136
- package/src/context/network-activity.tsx +0 -45
- package/src/context/notification.tsx +0 -62
- package/src/context/shell-size.tsx +0 -49
- package/src/context/shell-title.tsx +0 -38
- package/src/entrypoints/print-mode.ts +0 -312
- package/src/entrypoints/repl.tsx +0 -389
- package/src/hooks/use-agent.ts +0 -15
- package/src/hooks/use-api-client.ts +0 -1
- package/src/hooks/use-available-height.ts +0 -8
- package/src/hooks/use-cleanup.ts +0 -29
- package/src/hooks/use-interrupt-manager.ts +0 -242
- package/src/hooks/use-models.ts +0 -22
- package/src/index.ts +0 -217
- package/src/lib/__tests__/ansi.test.ts +0 -255
- package/src/lib/__tests__/cli.test.ts +0 -122
- package/src/lib/__tests__/commands.test.ts +0 -325
- package/src/lib/__tests__/constants.test.ts +0 -15
- package/src/lib/__tests__/focusables.test.ts +0 -25
- package/src/lib/__tests__/fs.test.ts +0 -231
- package/src/lib/__tests__/markdown.test.tsx +0 -348
- package/src/lib/__tests__/mcpCommandHandler.test.ts +0 -173
- package/src/lib/__tests__/mcpManagement.test.ts +0 -38
- package/src/lib/__tests__/path-paste.test.ts +0 -144
- package/src/lib/__tests__/path.test.ts +0 -300
- package/src/lib/__tests__/queries.test.ts +0 -39
- package/src/lib/__tests__/standaloneMcpService.test.ts +0 -71
- package/src/lib/__tests__/text-buffer.test.ts +0 -328
- package/src/lib/__tests__/text-utils.test.ts +0 -32
- package/src/lib/__tests__/timing.test.ts +0 -78
- package/src/lib/__tests__/utils.test.ts +0 -238
- package/src/lib/__tests__/vim-buffer-actions.test.ts +0 -154
- package/src/lib/ansi.ts +0 -150
- package/src/lib/cli-push-server.ts +0 -112
- package/src/lib/cli.ts +0 -44
- package/src/lib/clipboard.ts +0 -226
- package/src/lib/command-utils.ts +0 -93
- package/src/lib/commands.ts +0 -270
- package/src/lib/constants.ts +0 -3
- package/src/lib/extension-connection.ts +0 -181
- package/src/lib/focusables.ts +0 -7
- package/src/lib/fs.ts +0 -533
- package/src/lib/markdown/code-block.tsx +0 -63
- package/src/lib/markdown/index.ts +0 -4
- package/src/lib/markdown/link.tsx +0 -19
- package/src/lib/markdown/markdown.tsx +0 -372
- package/src/lib/markdown/types.ts +0 -15
- package/src/lib/mcpCommandHandler.ts +0 -121
- package/src/lib/mcpManagement.ts +0 -44
- package/src/lib/path-paste.ts +0 -185
- package/src/lib/path.ts +0 -179
- package/src/lib/queries.ts +0 -15
- package/src/lib/standaloneMcpService.ts +0 -688
- package/src/lib/status-utils.ts +0 -237
- package/src/lib/test-utils.tsx +0 -72
- package/src/lib/text-buffer.ts +0 -2415
- package/src/lib/text-utils.ts +0 -272
- package/src/lib/timing.ts +0 -63
- package/src/lib/types.ts +0 -295
- package/src/lib/utils.ts +0 -182
- package/src/lib/vim-buffer-actions.ts +0 -732
- package/src/providers/agent.tsx +0 -1063
- package/src/providers/api-client.tsx +0 -43
- package/src/services/logger.ts +0 -85
- package/src/terminal/detection.ts +0 -187
- package/src/terminal/exit.ts +0 -279
- package/src/terminal/notification.ts +0 -83
- package/src/terminal/progress.ts +0 -201
- package/src/terminal/setup.ts +0 -797
- package/src/terminal/types.ts +0 -51
- package/src/theme/context.tsx +0 -57
- package/src/theme/index.ts +0 -4
- package/src/theme/themed.tsx +0 -35
- package/src/theme/themes.json +0 -546
- package/src/theme/types.ts +0 -110
- package/src/tools/types.ts +0 -59
- package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
- package/src/tools/utils/tool-ui-components.tsx +0 -649
- package/src/tools/utils/zod-coercion.ts +0 -35
- package/tsconfig.json +0 -16
- package/tsconfig.node.json +0 -29
- package/tsconfig.test.json +0 -27
- package/tsdown.config.ts +0 -17
- package/vitest.config.ts +0 -76
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it, vi } from "vitest";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ANSI,
|
|
7
|
-
osc9,
|
|
8
|
-
osc777,
|
|
9
|
-
osc99,
|
|
10
|
-
osc9Progress,
|
|
11
|
-
osc1337ProgressClear,
|
|
12
|
-
osc1337ProgressState,
|
|
13
|
-
osc1337ProgressPercent,
|
|
14
|
-
ansiRegex,
|
|
15
|
-
stripAnsi,
|
|
16
|
-
} from "../ansi.js";
|
|
17
|
-
|
|
18
|
-
describe.concurrent("ansi", () => {
|
|
19
|
-
describe.concurrent("ANSI enum", () => {
|
|
20
|
-
it("should have correct escape character", () => {
|
|
21
|
-
expect(ANSI.ESC).toBe("\x1b");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should have correct bell character", () => {
|
|
25
|
-
expect(ANSI.BEL).toBe("\x07");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should have correct string terminator", () => {
|
|
29
|
-
expect(ANSI.ST).toBe("\x1b\\");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should construct focus reporting sequences correctly", () => {
|
|
33
|
-
expect(ANSI.ENABLE_FOCUS_REPORTING).toBe("\x1b[?1004h");
|
|
34
|
-
expect(ANSI.DISABLE_FOCUS_REPORTING).toBe("\x1b[?1004l");
|
|
35
|
-
expect(ANSI.FOCUS_IN).toBe("\x1b[I");
|
|
36
|
-
expect(ANSI.FOCUS_OUT).toBe("\x1b[O");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should construct cursor sequences correctly", () => {
|
|
40
|
-
expect(ANSI.SHOW_CURSOR).toBe("\x1b[?25h");
|
|
41
|
-
expect(ANSI.HIDE_CURSOR).toBe("\x1b[?25l");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should construct reset sequences correctly", () => {
|
|
45
|
-
expect(ANSI.RESET_SGR).toBe("\x1b[0m");
|
|
46
|
-
expect(ANSI.SOFT_RESET).toBe("\x1b[!p");
|
|
47
|
-
expect(ANSI.HARD_RESET).toBe("\x1bc");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should construct paste mode sequences correctly", () => {
|
|
51
|
-
expect(ANSI.ENABLE_BRACKETED_PASTE).toBe("\x1b[?2004h");
|
|
52
|
-
expect(ANSI.DISABLE_BRACKETED_PASTE).toBe("\x1b[?2004l");
|
|
53
|
-
expect(ANSI.PASTE_MODE_PREFIX).toBe("\x1b[200~");
|
|
54
|
-
expect(ANSI.PASTE_MODE_SUFFIX).toBe("\x1b[201~");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should construct style sequences correctly", () => {
|
|
58
|
-
expect(ANSI.DIM).toBe("\x1b[2m");
|
|
59
|
-
expect(ANSI.BOLD).toBe("\x1b[1m");
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe.concurrent("osc9", () => {
|
|
64
|
-
it("should format OSC 9 notification correctly", () => {
|
|
65
|
-
const result = osc9("test message");
|
|
66
|
-
expect(result).toBe("\x1b]9;\n\ntest message\x07");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should handle empty message", () => {
|
|
70
|
-
const result = osc9("");
|
|
71
|
-
expect(result).toBe("\x1b]9;\n\n\x07");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe.concurrent("osc777", () => {
|
|
76
|
-
it("should format OSC 777 notification correctly", () => {
|
|
77
|
-
const result = osc777("Title", "Body");
|
|
78
|
-
expect(result).toBe("\x1b]777;notify;Title;Body\x07");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should handle empty title and body", () => {
|
|
82
|
-
const result = osc777("", "");
|
|
83
|
-
expect(result).toBe("\x1b]777;notify;;\x07");
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe.concurrent("osc99", () => {
|
|
88
|
-
it("should format OSC 99 notification correctly", () => {
|
|
89
|
-
// Mock Math.random to get predictable notification ID
|
|
90
|
-
const mockRandom = vi.spyOn(Math, "random").mockReturnValue(0.1234);
|
|
91
|
-
const result = osc99("Title", "Body");
|
|
92
|
-
|
|
93
|
-
// Should contain title and body parts
|
|
94
|
-
expect(result).toContain("]99;i=1234:d=0:p=title;Title\x1b\\");
|
|
95
|
-
expect(result).toContain("]99;i=1234:p=body;Body\x1b\\");
|
|
96
|
-
expect(result).toContain("]99;i=1234:d=1:a=focus;\x1b\\");
|
|
97
|
-
|
|
98
|
-
mockRandom.mockRestore();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe.concurrent("osc9Progress", () => {
|
|
103
|
-
it("should format progress with state 0 (hide)", () => {
|
|
104
|
-
const result = osc9Progress(0);
|
|
105
|
-
expect(result).toBe("\x1b]9;4;0;0\x07\x1b]9;4;0;0\x1b\\");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should format progress with state 1 and percentage", () => {
|
|
109
|
-
const result = osc9Progress(1, 50);
|
|
110
|
-
expect(result).toBe("\x1b]9;4;1;50\x07\x1b]9;4;1;50\x1b\\");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should clamp progress to 0-100", () => {
|
|
114
|
-
expect(osc9Progress(1, -10)).toBe("\x1b]9;4;1;0\x07\x1b]9;4;1;0\x1b\\");
|
|
115
|
-
expect(osc9Progress(1, 150)).toBe("\x1b]9;4;1;100\x07\x1b]9;4;1;100\x1b\\");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should round progress values", () => {
|
|
119
|
-
expect(osc9Progress(1, 50.7)).toBe("\x1b]9;4;1;51\x07\x1b]9;4;1;51\x1b\\");
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe.concurrent("osc1337ProgressClear", () => {
|
|
124
|
-
it("should clear progress indicator", () => {
|
|
125
|
-
const result = osc1337ProgressClear();
|
|
126
|
-
expect(result).toBe("\x1b]1337;Progress=\x07\x1b]1337;Progress=\x1b\\");
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe.concurrent("osc1337ProgressState", () => {
|
|
131
|
-
it("should set progress state 0", () => {
|
|
132
|
-
const result = osc1337ProgressState(0);
|
|
133
|
-
expect(result).toBe("\x1b]1337;Progress=0\x07\x1b]1337;Progress=0\x1b\\");
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("should set progress state 1", () => {
|
|
137
|
-
const result = osc1337ProgressState(1);
|
|
138
|
-
expect(result).toBe("\x1b]1337;Progress=1\x07\x1b]1337;Progress=1\x1b\\");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("should set progress state 2", () => {
|
|
142
|
-
const result = osc1337ProgressState(2);
|
|
143
|
-
expect(result).toBe("\x1b]1337;Progress=2\x07\x1b]1337;Progress=2\x1b\\");
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe.concurrent("osc1337ProgressPercent", () => {
|
|
148
|
-
it("should format progress with percentage only", () => {
|
|
149
|
-
const result = osc1337ProgressPercent(50);
|
|
150
|
-
expect(result).toBe("\x1b]1337;Progress=50\x07\x1b]1337;Progress=50\x1b\\");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should format progress with percentage and message", () => {
|
|
154
|
-
const result = osc1337ProgressPercent(75, "Loading...");
|
|
155
|
-
expect(result).toContain("]1337;Progress=75;Loading...\x07");
|
|
156
|
-
expect(result).toContain("]1337;Progress=message=Loading...;percent=75\x07");
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should clamp percentage to 0-100", () => {
|
|
160
|
-
expect(osc1337ProgressPercent(-10)).toBe(
|
|
161
|
-
"\x1b]1337;Progress=0\x07\x1b]1337;Progress=0\x1b\\",
|
|
162
|
-
);
|
|
163
|
-
expect(osc1337ProgressPercent(150)).toBe(
|
|
164
|
-
"\x1b]1337;Progress=100\x07\x1b]1337;Progress=100\x1b\\",
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should round percentage values", () => {
|
|
169
|
-
expect(osc1337ProgressPercent(50.7)).toBe(
|
|
170
|
-
"\x1b]1337;Progress=51\x07\x1b]1337;Progress=51\x1b\\",
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("should sanitize message content", () => {
|
|
175
|
-
const result = osc1337ProgressPercent(50, "test\x1b\x07\n\r;message");
|
|
176
|
-
// The sanitized message should not contain control chars or semicolons
|
|
177
|
-
// (they're replaced/removed in the message part, but \x1b is still in OSC wrapper)
|
|
178
|
-
expect(result).toContain("test :message"); // \x1b and \x07 removed, \n\r become spaces, ; becomes :
|
|
179
|
-
// The message part should not have raw control characters
|
|
180
|
-
const messagePart = result.match(
|
|
181
|
-
new RegExp("Progress=\\d+;(.+?)[" + String.fromCharCode(7) + String.fromCharCode(27) + "]"),
|
|
182
|
-
)?.[1];
|
|
183
|
-
expect(messagePart).not.toContain("\x07");
|
|
184
|
-
expect(messagePart).not.toContain("\n");
|
|
185
|
-
expect(messagePart).not.toContain("\r");
|
|
186
|
-
expect(messagePart).not.toContain(";"); // Should be replaced with :
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should truncate long messages", () => {
|
|
190
|
-
const longMessage = "a".repeat(200);
|
|
191
|
-
const result = osc1337ProgressPercent(50, longMessage);
|
|
192
|
-
// Message is truncated to 120 chars, but result includes OSC sequences
|
|
193
|
-
// Extract the message part to verify truncation
|
|
194
|
-
const messagePart = result.match(
|
|
195
|
-
new RegExp("Progress=\\d+;(.+?)[" + String.fromCharCode(7) + String.fromCharCode(27) + "]"),
|
|
196
|
-
)?.[1];
|
|
197
|
-
expect(messagePart?.length).toBeLessThanOrEqual(120);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe.concurrent("ansiRegex", () => {
|
|
202
|
-
it("should match ANSI escape sequences", () => {
|
|
203
|
-
const regex = ansiRegex();
|
|
204
|
-
expect("\x1b[31mtest\x1b[0m".match(regex)).toHaveLength(2);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("should match OSC sequences", () => {
|
|
208
|
-
const regex = ansiRegex();
|
|
209
|
-
expect("\x1b]0;title\x07".match(regex)).toHaveLength(1);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("should match only first occurrence when onlyFirst is true", () => {
|
|
213
|
-
const regex = ansiRegex({ onlyFirst: true });
|
|
214
|
-
const matches = "\x1b[31mtest\x1b[0m".match(regex);
|
|
215
|
-
expect(matches).toHaveLength(1);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("should match all occurrences when onlyFirst is false", () => {
|
|
219
|
-
const regex = ansiRegex({ onlyFirst: false });
|
|
220
|
-
const matches = "\x1b[31mtest\x1b[0m".match(regex);
|
|
221
|
-
expect(matches).toHaveLength(2);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe.concurrent("stripAnsi", () => {
|
|
226
|
-
it("should strip ANSI codes from string", () => {
|
|
227
|
-
expect(stripAnsi("\x1b[31mtest\x1b[0m")).toBe("test");
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it("should handle strings without ANSI codes", () => {
|
|
231
|
-
expect(stripAnsi("plain text")).toBe("plain text");
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("should handle empty strings", () => {
|
|
235
|
-
expect(stripAnsi("")).toBe("");
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("should throw error for non-string input", () => {
|
|
239
|
-
expect(() => stripAnsi(null as unknown as string)).toThrow(
|
|
240
|
-
"Expected a `string`, got `object`",
|
|
241
|
-
);
|
|
242
|
-
expect(() => stripAnsi(123 as unknown as string)).toThrow(
|
|
243
|
-
"Expected a `string`, got `number`",
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("should strip multiple ANSI codes", () => {
|
|
248
|
-
expect(stripAnsi("\x1b[31mred\x1b[0m \x1b[32mgreen\x1b[0m")).toBe("red green");
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it("should strip OSC sequences", () => {
|
|
252
|
-
expect(stripAnsi("\x1b]0;title\x07")).toBe("");
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
});
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { runCli } from "../cli.js";
|
|
6
|
-
|
|
7
|
-
// TODO: The runCli function doesn't handle spawn errors (ENOENT).
|
|
8
|
-
// When a non-existent command is spawned, the error is emitted asynchronously
|
|
9
|
-
// and not caught by the generator, causing unhandled promise rejections.
|
|
10
|
-
// Consider adding error handling to runCli to catch and handle spawn errors
|
|
11
|
-
// (e.g., proc.on('error', ...) to yield error information or throw).
|
|
12
|
-
|
|
13
|
-
describe.concurrent("cli", () => {
|
|
14
|
-
describe.concurrent("runCli", () => {
|
|
15
|
-
it("should yield output from stdout", async () => {
|
|
16
|
-
const command = process.platform === "win32" ? "echo" : "echo";
|
|
17
|
-
const args = ["hello world"];
|
|
18
|
-
const outputs: string[] = [];
|
|
19
|
-
|
|
20
|
-
for await (const output of runCli(command, args)) {
|
|
21
|
-
outputs.push(output);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// On Unix, echo outputs to stdout; on Windows, we might need different handling
|
|
25
|
-
// The output might include newlines, so we check if it contains our message
|
|
26
|
-
// Should have received some output
|
|
27
|
-
expect(outputs.length).toBeGreaterThanOrEqual(0);
|
|
28
|
-
}, 10000);
|
|
29
|
-
|
|
30
|
-
it("should yield output from stderr", async () => {
|
|
31
|
-
// Use a command that outputs to stderr
|
|
32
|
-
const command = process.platform === "win32" ? "cmd" : "sh";
|
|
33
|
-
const args =
|
|
34
|
-
process.platform === "win32" ? ["/c", "echo error >&2"] : ["-c", "echo error >&2"];
|
|
35
|
-
|
|
36
|
-
const outputs: string[] = [];
|
|
37
|
-
|
|
38
|
-
for await (const output of runCli(command, args)) {
|
|
39
|
-
outputs.push(output);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Should have received some output
|
|
43
|
-
expect(outputs.length).toBeGreaterThanOrEqual(0);
|
|
44
|
-
}, 10000);
|
|
45
|
-
|
|
46
|
-
it("should handle commands that exit immediately", async () => {
|
|
47
|
-
const command = process.platform === "win32" ? "echo" : "echo";
|
|
48
|
-
const args = ["test"];
|
|
49
|
-
const outputs: string[] = [];
|
|
50
|
-
|
|
51
|
-
for await (const output of runCli(command, args)) {
|
|
52
|
-
outputs.push(output);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Should complete without hanging
|
|
56
|
-
expect(true).toBe(true);
|
|
57
|
-
}, 10000);
|
|
58
|
-
|
|
59
|
-
it("should handle empty args array", async () => {
|
|
60
|
-
const command = process.platform === "win32" ? "echo" : "echo";
|
|
61
|
-
const args: string[] = [];
|
|
62
|
-
const outputs: string[] = [];
|
|
63
|
-
|
|
64
|
-
for await (const output of runCli(command, args)) {
|
|
65
|
-
outputs.push(output);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Should complete without error
|
|
69
|
-
expect(true).toBe(true);
|
|
70
|
-
}, 10000);
|
|
71
|
-
|
|
72
|
-
it("should handle multiple output chunks", async () => {
|
|
73
|
-
// Use a command that outputs multiple lines
|
|
74
|
-
const command = process.platform === "win32" ? "echo" : "printf";
|
|
75
|
-
const args =
|
|
76
|
-
process.platform === "win32"
|
|
77
|
-
? ["line1\nline2\nline3"]
|
|
78
|
-
: ["%s\n%s\n%s\n", "line1", "line2", "line3"];
|
|
79
|
-
|
|
80
|
-
const outputs: string[] = [];
|
|
81
|
-
|
|
82
|
-
for await (const output of runCli(command, args)) {
|
|
83
|
-
outputs.push(output);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Should have received output
|
|
87
|
-
expect(outputs.length).toBeGreaterThanOrEqual(0);
|
|
88
|
-
}, 10000);
|
|
89
|
-
|
|
90
|
-
it("should terminate process on completion", async () => {
|
|
91
|
-
const command = process.platform === "win32" ? "echo" : "echo";
|
|
92
|
-
const args = ["test"];
|
|
93
|
-
|
|
94
|
-
// This test verifies the process is cleaned up
|
|
95
|
-
// We can't easily verify the process is killed, but we can verify
|
|
96
|
-
// the generator completes
|
|
97
|
-
const generator = runCli(command, args);
|
|
98
|
-
const outputs: string[] = [];
|
|
99
|
-
|
|
100
|
-
for await (const output of generator) {
|
|
101
|
-
outputs.push(output);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Generator should complete
|
|
105
|
-
expect(true).toBe(true);
|
|
106
|
-
}, 10000);
|
|
107
|
-
|
|
108
|
-
it("should work with different command types", async () => {
|
|
109
|
-
// Test with a simple command available on most systems
|
|
110
|
-
const command = process.platform === "win32" ? "where" : "which";
|
|
111
|
-
const args = process.platform === "win32" ? ["echo"] : ["echo"];
|
|
112
|
-
const outputs: string[] = [];
|
|
113
|
-
|
|
114
|
-
for await (const output of runCli(command, args)) {
|
|
115
|
-
outputs.push(output);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Should complete without error
|
|
119
|
-
expect(true).toBe(true);
|
|
120
|
-
}, 10000);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
// @vitest-environment node
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Command,
|
|
7
|
-
COMMAND_INFO,
|
|
8
|
-
getCommandInfo,
|
|
9
|
-
getAllCommands,
|
|
10
|
-
isValidCommand,
|
|
11
|
-
formatCommandHelp,
|
|
12
|
-
getCommandSuggestions,
|
|
13
|
-
getCommandWithDescription,
|
|
14
|
-
McpSubcommand,
|
|
15
|
-
MCP_COMMAND_INFO,
|
|
16
|
-
getMcpCommandInfo,
|
|
17
|
-
getAllMcpSubcommands,
|
|
18
|
-
isValidMcpSubcommand,
|
|
19
|
-
formatMcpCommandHelp,
|
|
20
|
-
parseMcpCommand,
|
|
21
|
-
} from "../commands.js";
|
|
22
|
-
|
|
23
|
-
describe.concurrent("commands", () => {
|
|
24
|
-
describe.concurrent("Command enum", () => {
|
|
25
|
-
it("should have all expected commands", () => {
|
|
26
|
-
expect(Command.Stop).toBe("/stop");
|
|
27
|
-
expect(Command.Quit).toBe("/quit");
|
|
28
|
-
expect(Command.Exit).toBe("/exit");
|
|
29
|
-
expect(Command.Q).toBe("/q");
|
|
30
|
-
expect(Command.Bye).toBe("/bye");
|
|
31
|
-
expect(Command.Clear).toBe("/clear");
|
|
32
|
-
expect(Command.New).toBe("/new");
|
|
33
|
-
expect(Command.Suggest).toBe("/");
|
|
34
|
-
expect(Command.Help).toBe("/help");
|
|
35
|
-
expect(Command.Sidebar).toBe("/sidebar");
|
|
36
|
-
expect(Command.Login).toBe("/login");
|
|
37
|
-
expect(Command.Logout).toBe("/logout");
|
|
38
|
-
expect(Command.Mcp).toBe("/mcp");
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe.concurrent("COMMAND_INFO", () => {
|
|
43
|
-
it("should have info for all commands", () => {
|
|
44
|
-
const commandsInInfo = COMMAND_INFO.map((info) => info.command);
|
|
45
|
-
const allCommands = Object.values(Command);
|
|
46
|
-
|
|
47
|
-
// Check that all commands have info (some commands like Quit, Exit, Q, Bye might share the same behavior)
|
|
48
|
-
expect(commandsInInfo.length).toBeGreaterThan(0);
|
|
49
|
-
expect(COMMAND_INFO.every((info) => allCommands.includes(info.command))).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should have valid structure for each command info", () => {
|
|
53
|
-
COMMAND_INFO.forEach((info) => {
|
|
54
|
-
expect(info).toHaveProperty("command");
|
|
55
|
-
expect(info).toHaveProperty("description");
|
|
56
|
-
expect(info).toHaveProperty("usage");
|
|
57
|
-
expect(typeof info.description).toBe("string");
|
|
58
|
-
expect(typeof info.usage).toBe("string");
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe.concurrent("getCommandInfo", () => {
|
|
64
|
-
it("should return command info for valid command", () => {
|
|
65
|
-
const info = getCommandInfo(Command.Stop);
|
|
66
|
-
expect(info).toBeDefined();
|
|
67
|
-
expect(info?.command).toBe(Command.Stop);
|
|
68
|
-
expect(info?.description).toBe("Stop the current streaming response");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should return undefined for command not in COMMAND_INFO", () => {
|
|
72
|
-
// Note: This tests the function behavior, but all commands should have info
|
|
73
|
-
// If this fails, it means a command is missing from COMMAND_INFO
|
|
74
|
-
const allCommands = Object.values(Command);
|
|
75
|
-
allCommands.forEach((cmd) => {
|
|
76
|
-
const info = getCommandInfo(cmd);
|
|
77
|
-
// At least Stop should have info
|
|
78
|
-
if (cmd === Command.Stop) {
|
|
79
|
-
expect(info).toBeDefined();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe.concurrent("getAllCommands", () => {
|
|
86
|
-
it("should return all command values", () => {
|
|
87
|
-
const commands = getAllCommands();
|
|
88
|
-
expect(commands).toBeInstanceOf(Array);
|
|
89
|
-
expect(commands.length).toBeGreaterThan(0);
|
|
90
|
-
expect(commands).toContain(Command.Stop);
|
|
91
|
-
expect(commands).toContain(Command.Help);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("should return all unique commands", () => {
|
|
95
|
-
const commands = getAllCommands();
|
|
96
|
-
const uniqueCommands = new Set(commands);
|
|
97
|
-
expect(commands.length).toBe(uniqueCommands.size);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe.concurrent("isValidCommand", () => {
|
|
102
|
-
it("should return true for valid commands", () => {
|
|
103
|
-
expect(isValidCommand("/stop")).toBe(true);
|
|
104
|
-
expect(isValidCommand("/help")).toBe(true);
|
|
105
|
-
expect(isValidCommand("/clear")).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should return false for invalid commands", () => {
|
|
109
|
-
expect(isValidCommand("/invalid")).toBe(false);
|
|
110
|
-
expect(isValidCommand("stop")).toBe(false);
|
|
111
|
-
expect(isValidCommand("")).toBe(false);
|
|
112
|
-
expect(isValidCommand("/unknown")).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe.concurrent("formatCommandHelp", () => {
|
|
117
|
-
it("should return a formatted help string", () => {
|
|
118
|
-
const help = formatCommandHelp();
|
|
119
|
-
expect(typeof help).toBe("string");
|
|
120
|
-
expect(help.length).toBeGreaterThan(0);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should include command information", () => {
|
|
124
|
-
const help = formatCommandHelp();
|
|
125
|
-
expect(help).toContain("Abacus.AI CLI");
|
|
126
|
-
expect(help).toContain("/stop");
|
|
127
|
-
expect(help).toContain("/help");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should format commands with proper alignment", () => {
|
|
131
|
-
const help = formatCommandHelp();
|
|
132
|
-
// Check that usage and description are aligned
|
|
133
|
-
const lines = help.split("\n");
|
|
134
|
-
const commandLines = lines.filter(
|
|
135
|
-
(line) => line.trim().startsWith("/") && line.includes(" "),
|
|
136
|
-
);
|
|
137
|
-
expect(commandLines.length).toBeGreaterThan(0);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe.concurrent("getCommandSuggestions", () => {
|
|
142
|
-
it("should return matching commands for partial input", () => {
|
|
143
|
-
const suggestions = getCommandSuggestions("help");
|
|
144
|
-
expect(suggestions).toContain(Command.Help);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("should be case insensitive", () => {
|
|
148
|
-
const suggestions1 = getCommandSuggestions("HELP");
|
|
149
|
-
const suggestions2 = getCommandSuggestions("help");
|
|
150
|
-
expect(suggestions1).toEqual(suggestions2);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should return empty array for no matches", () => {
|
|
154
|
-
const suggestions = getCommandSuggestions("xyz123nonexistent");
|
|
155
|
-
expect(suggestions).toEqual([]);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("should return all commands for empty string", () => {
|
|
159
|
-
const suggestions = getCommandSuggestions("");
|
|
160
|
-
expect(suggestions.length).toBeGreaterThan(0);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe.concurrent("getCommandWithDescription", () => {
|
|
165
|
-
it("should return command with description for valid command", () => {
|
|
166
|
-
const result = getCommandWithDescription(Command.Stop);
|
|
167
|
-
expect(result).toContain("/stop");
|
|
168
|
-
expect(result).toContain("Stop");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("should return just command if info not found", () => {
|
|
172
|
-
// This tests edge case - in practice all commands should have info
|
|
173
|
-
const result = getCommandWithDescription(Command.Stop);
|
|
174
|
-
expect(result).toBeDefined();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe.concurrent("McpSubcommand enum", () => {
|
|
179
|
-
it("should have all expected subcommands", () => {
|
|
180
|
-
expect(McpSubcommand.Add).toBe("add");
|
|
181
|
-
expect(McpSubcommand.Remove).toBe("remove");
|
|
182
|
-
expect(McpSubcommand.List).toBe("list");
|
|
183
|
-
expect(McpSubcommand.Get).toBe("get");
|
|
184
|
-
expect(McpSubcommand.AddJson).toBe("add-json");
|
|
185
|
-
expect(McpSubcommand.Help).toBe("help");
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe.concurrent("MCP_COMMAND_INFO", () => {
|
|
190
|
-
it("should have info for all subcommands", () => {
|
|
191
|
-
const subcommandsInInfo = MCP_COMMAND_INFO.map((info) => info.subcommand);
|
|
192
|
-
const allSubcommands = Object.values(McpSubcommand);
|
|
193
|
-
|
|
194
|
-
allSubcommands.forEach((subcmd) => {
|
|
195
|
-
expect(subcommandsInInfo).toContain(subcmd);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("should have valid structure for each subcommand info", () => {
|
|
200
|
-
MCP_COMMAND_INFO.forEach((info) => {
|
|
201
|
-
expect(info).toHaveProperty("subcommand");
|
|
202
|
-
expect(info).toHaveProperty("description");
|
|
203
|
-
expect(info).toHaveProperty("usage");
|
|
204
|
-
expect(typeof info.description).toBe("string");
|
|
205
|
-
expect(typeof info.usage).toBe("string");
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe.concurrent("getMcpCommandInfo", () => {
|
|
211
|
-
it("should return command info for valid subcommand", () => {
|
|
212
|
-
const info = getMcpCommandInfo(McpSubcommand.Add);
|
|
213
|
-
expect(info).toBeDefined();
|
|
214
|
-
expect(info?.subcommand).toBe(McpSubcommand.Add);
|
|
215
|
-
expect(info?.description).toBe("Add a server");
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("should return undefined for invalid subcommand", () => {
|
|
219
|
-
const info = getMcpCommandInfo("invalid" as McpSubcommand);
|
|
220
|
-
expect(info).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe.concurrent("getAllMcpSubcommands", () => {
|
|
225
|
-
it("should return all subcommand values", () => {
|
|
226
|
-
const subcommands = getAllMcpSubcommands();
|
|
227
|
-
expect(subcommands).toBeInstanceOf(Array);
|
|
228
|
-
expect(subcommands.length).toBeGreaterThan(0);
|
|
229
|
-
expect(subcommands).toContain(McpSubcommand.Add);
|
|
230
|
-
expect(subcommands).toContain(McpSubcommand.List);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe.concurrent("isValidMcpSubcommand", () => {
|
|
235
|
-
it("should return true for valid subcommands", () => {
|
|
236
|
-
expect(isValidMcpSubcommand("add")).toBe(true);
|
|
237
|
-
expect(isValidMcpSubcommand("list")).toBe(true);
|
|
238
|
-
expect(isValidMcpSubcommand("help")).toBe(true);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("should return false for invalid subcommands", () => {
|
|
242
|
-
expect(isValidMcpSubcommand("invalid")).toBe(false);
|
|
243
|
-
expect(isValidMcpSubcommand("")).toBe(false);
|
|
244
|
-
expect(isValidMcpSubcommand("unknown")).toBe(false);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe.concurrent("formatMcpCommandHelp", () => {
|
|
249
|
-
it("should return a formatted help string", () => {
|
|
250
|
-
const help = formatMcpCommandHelp();
|
|
251
|
-
expect(typeof help).toBe("string");
|
|
252
|
-
expect(help.length).toBeGreaterThan(0);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("should include MCP command information", () => {
|
|
256
|
-
const help = formatMcpCommandHelp();
|
|
257
|
-
expect(help).toContain("MCP");
|
|
258
|
-
expect(help).toContain("add");
|
|
259
|
-
expect(help).toContain("list");
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
describe.concurrent("parseMcpCommand", () => {
|
|
264
|
-
it("should parse valid MCP command with subcommand", () => {
|
|
265
|
-
const result = parseMcpCommand("/mcp add server-name");
|
|
266
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
267
|
-
expect(result.args).toEqual(["server-name"]);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it("should parse command with multiple args", () => {
|
|
271
|
-
const result = parseMcpCommand("/mcp add server-name command arg1 arg2");
|
|
272
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
273
|
-
expect(result.args).toEqual(["server-name", "command", "arg1", "arg2"]);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("should handle quoted arguments", () => {
|
|
277
|
-
const result = parseMcpCommand('/mcp add "server name" "command with spaces"');
|
|
278
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
279
|
-
expect(result.args).toEqual(["server name", "command with spaces"]);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("should handle single-quoted arguments", () => {
|
|
283
|
-
const result = parseMcpCommand("/mcp add 'server name' 'command'");
|
|
284
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
285
|
-
expect(result.args).toEqual(["server name", "command"]);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("should return empty args for non-MCP command", () => {
|
|
289
|
-
const result = parseMcpCommand("/help");
|
|
290
|
-
expect(result.subcommand).toBeUndefined();
|
|
291
|
-
expect(result.args).toEqual([]);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("should handle command without subcommand", () => {
|
|
295
|
-
const result = parseMcpCommand("/mcp");
|
|
296
|
-
expect(result.subcommand).toBeUndefined();
|
|
297
|
-
expect(result.args).toEqual([]);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it("should handle invalid subcommand", () => {
|
|
301
|
-
const result = parseMcpCommand("/mcp invalid-subcommand arg1");
|
|
302
|
-
expect(result.subcommand).toBeUndefined();
|
|
303
|
-
// The first argument (subcommand) is removed from args even if invalid
|
|
304
|
-
expect(result.args).toEqual(["arg1"]);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("should handle extra whitespace", () => {
|
|
308
|
-
const result = parseMcpCommand("/mcp add server-name ");
|
|
309
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
310
|
-
expect(result.args).toEqual(["server-name"]);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it("should handle mixed quoted and unquoted args", () => {
|
|
314
|
-
const result = parseMcpCommand('/mcp add server-name "quoted arg" unquoted');
|
|
315
|
-
expect(result.subcommand).toBe(McpSubcommand.Add);
|
|
316
|
-
expect(result.args).toEqual(["server-name", "quoted arg", "unquoted"]);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it("should handle empty string", () => {
|
|
320
|
-
const result = parseMcpCommand("");
|
|
321
|
-
expect(result.subcommand).toBeUndefined();
|
|
322
|
-
expect(result.args).toEqual([]);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|