@abacus-ai/cli 2.0.0-canary.1 → 2.0.0-canary.3

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.
Files changed (197) hide show
  1. package/dist/index.mjs +450 -422
  2. package/package.json +4 -1
  3. package/.oxlintrc.json +0 -8
  4. package/resources/abacus.ico +0 -0
  5. package/resources/entitlements.plist +0 -9
  6. package/src/__e2e__/README.md +0 -196
  7. package/src/__e2e__/agent-interactions.e2e.test.tsx +0 -61
  8. package/src/__e2e__/cli-commands.e2e.test.tsx +0 -77
  9. package/src/__e2e__/conversation-throttle.e2e.test.ts +0 -453
  10. package/src/__e2e__/conversation.e2e.test.tsx +0 -56
  11. package/src/__e2e__/diff-preview.e2e.test.tsx +0 -3399
  12. package/src/__e2e__/file-creation.e2e.test.tsx +0 -149
  13. package/src/__e2e__/helpers/test-helpers.ts +0 -449
  14. package/src/__e2e__/keyboard-navigation.e2e.test.tsx +0 -34
  15. package/src/__e2e__/llm-models.e2e.test.ts +0 -402
  16. package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +0 -71
  17. package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +0 -167
  18. package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +0 -185
  19. package/src/__e2e__/repl.e2e.test.tsx +0 -78
  20. package/src/__e2e__/shell-compatibility.e2e.test.tsx +0 -76
  21. package/src/__e2e__/theme-mcp.e2e.test.tsx +0 -98
  22. package/src/__e2e__/tool-permissions.e2e.test.tsx +0 -66
  23. package/src/args.ts +0 -22
  24. package/src/components/__tests__/react-compiler.test.tsx +0 -78
  25. package/src/components/__tests__/status-indicator.test.tsx +0 -403
  26. package/src/components/composer/__tests__/bash-runner.test.tsx +0 -263
  27. package/src/components/composer/agent-mode-indicator.tsx +0 -63
  28. package/src/components/composer/bash-runner.tsx +0 -54
  29. package/src/components/composer/commands/default-commands.tsx +0 -615
  30. package/src/components/composer/commands/handler.tsx +0 -59
  31. package/src/components/composer/commands/picker.tsx +0 -273
  32. package/src/components/composer/commands/registry.ts +0 -233
  33. package/src/components/composer/commands/types.ts +0 -33
  34. package/src/components/composer/context.tsx +0 -88
  35. package/src/components/composer/file-mention-picker.tsx +0 -83
  36. package/src/components/composer/help.tsx +0 -44
  37. package/src/components/composer/index.tsx +0 -1007
  38. package/src/components/composer/mentions.ts +0 -57
  39. package/src/components/composer/message-queue.tsx +0 -70
  40. package/src/components/composer/mode-panel.tsx +0 -35
  41. package/src/components/composer/modes/__tests__/bash-handler.test.tsx +0 -755
  42. package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +0 -1108
  43. package/src/components/composer/modes/bash-handler.tsx +0 -132
  44. package/src/components/composer/modes/bash-renderer.tsx +0 -175
  45. package/src/components/composer/modes/default-handlers.tsx +0 -33
  46. package/src/components/composer/modes/index.ts +0 -41
  47. package/src/components/composer/modes/types.ts +0 -21
  48. package/src/components/composer/persistent-shell.ts +0 -283
  49. package/src/components/composer/process.ts +0 -65
  50. package/src/components/composer/types.ts +0 -9
  51. package/src/components/composer/use-mention-search.ts +0 -68
  52. package/src/components/error-boundry.tsx +0 -60
  53. package/src/components/exit-message.tsx +0 -29
  54. package/src/components/expanded-view.tsx +0 -74
  55. package/src/components/file-completion.tsx +0 -127
  56. package/src/components/header.tsx +0 -47
  57. package/src/components/logo.tsx +0 -37
  58. package/src/components/segments.tsx +0 -356
  59. package/src/components/status-indicator.tsx +0 -306
  60. package/src/components/tool-group-summary.tsx +0 -263
  61. package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +0 -319
  62. package/src/components/tool-permissions/diff-preview.tsx +0 -359
  63. package/src/components/tool-permissions/index.ts +0 -5
  64. package/src/components/tool-permissions/permission-options.tsx +0 -401
  65. package/src/components/tool-permissions/permission-preview-header.tsx +0 -57
  66. package/src/components/tool-permissions/tool-permission-ui.tsx +0 -420
  67. package/src/components/tools/agent/ask-user-question.tsx +0 -107
  68. package/src/components/tools/agent/enter-plan-mode.tsx +0 -55
  69. package/src/components/tools/agent/exit-plan-mode.tsx +0 -83
  70. package/src/components/tools/agent/handoff-to-main.tsx +0 -27
  71. package/src/components/tools/agent/subagent.tsx +0 -37
  72. package/src/components/tools/agent/todo-write.tsx +0 -104
  73. package/src/components/tools/browser/close-tab.tsx +0 -58
  74. package/src/components/tools/browser/computer.tsx +0 -70
  75. package/src/components/tools/browser/get-interactive-elements.tsx +0 -54
  76. package/src/components/tools/browser/get-tab-content.tsx +0 -51
  77. package/src/components/tools/browser/navigate-to.tsx +0 -59
  78. package/src/components/tools/browser/new-tab.tsx +0 -60
  79. package/src/components/tools/browser/perform-action.tsx +0 -63
  80. package/src/components/tools/browser/refresh-tab.tsx +0 -43
  81. package/src/components/tools/browser/switch-tab.tsx +0 -58
  82. package/src/components/tools/filesystem/delete-file.tsx +0 -104
  83. package/src/components/tools/filesystem/edit.tsx +0 -220
  84. package/src/components/tools/filesystem/list-dir.tsx +0 -78
  85. package/src/components/tools/filesystem/read-file.tsx +0 -180
  86. package/src/components/tools/filesystem/upload-image.tsx +0 -76
  87. package/src/components/tools/ide/ide-diagnostics.tsx +0 -62
  88. package/src/components/tools/index.ts +0 -91
  89. package/src/components/tools/mcp/mcp-tool.tsx +0 -158
  90. package/src/components/tools/search/fetch-url.tsx +0 -73
  91. package/src/components/tools/search/file-search.tsx +0 -78
  92. package/src/components/tools/search/grep.tsx +0 -90
  93. package/src/components/tools/search/semantic-search.tsx +0 -66
  94. package/src/components/tools/search/web-search.tsx +0 -71
  95. package/src/components/tools/shared/index.tsx +0 -48
  96. package/src/components/tools/shared/zod-coercion.ts +0 -35
  97. package/src/components/tools/terminal/bash-tool-output.tsx +0 -188
  98. package/src/components/tools/terminal/get-terminal-output.tsx +0 -91
  99. package/src/components/tools/terminal/run-in-terminal.tsx +0 -131
  100. package/src/components/tools/types.ts +0 -16
  101. package/src/components/tools.tsx +0 -68
  102. package/src/components/ui/__tests__/divider.test.tsx +0 -61
  103. package/src/components/ui/__tests__/gradient.test.tsx +0 -125
  104. package/src/components/ui/__tests__/input.test.tsx +0 -166
  105. package/src/components/ui/__tests__/select.test.tsx +0 -273
  106. package/src/components/ui/__tests__/shimmer.test.tsx +0 -99
  107. package/src/components/ui/blinking-indicator.tsx +0 -27
  108. package/src/components/ui/divider.tsx +0 -162
  109. package/src/components/ui/gradient.tsx +0 -56
  110. package/src/components/ui/input.tsx +0 -228
  111. package/src/components/ui/select.tsx +0 -151
  112. package/src/components/ui/shimmer.tsx +0 -76
  113. package/src/context/agent-mode.tsx +0 -95
  114. package/src/context/extension-file.tsx +0 -136
  115. package/src/context/network-activity.tsx +0 -45
  116. package/src/context/notification.tsx +0 -62
  117. package/src/context/shell-size.tsx +0 -49
  118. package/src/context/shell-title.tsx +0 -38
  119. package/src/entrypoints/print-mode.ts +0 -312
  120. package/src/entrypoints/repl.tsx +0 -389
  121. package/src/hooks/use-agent.ts +0 -15
  122. package/src/hooks/use-api-client.ts +0 -1
  123. package/src/hooks/use-available-height.ts +0 -8
  124. package/src/hooks/use-cleanup.ts +0 -29
  125. package/src/hooks/use-interrupt-manager.ts +0 -242
  126. package/src/hooks/use-models.ts +0 -22
  127. package/src/index.ts +0 -217
  128. package/src/lib/__tests__/ansi.test.ts +0 -255
  129. package/src/lib/__tests__/cli.test.ts +0 -122
  130. package/src/lib/__tests__/commands.test.ts +0 -325
  131. package/src/lib/__tests__/constants.test.ts +0 -15
  132. package/src/lib/__tests__/focusables.test.ts +0 -25
  133. package/src/lib/__tests__/fs.test.ts +0 -231
  134. package/src/lib/__tests__/markdown.test.tsx +0 -348
  135. package/src/lib/__tests__/mcpCommandHandler.test.ts +0 -173
  136. package/src/lib/__tests__/mcpManagement.test.ts +0 -38
  137. package/src/lib/__tests__/path-paste.test.ts +0 -144
  138. package/src/lib/__tests__/path.test.ts +0 -300
  139. package/src/lib/__tests__/queries.test.ts +0 -39
  140. package/src/lib/__tests__/standaloneMcpService.test.ts +0 -71
  141. package/src/lib/__tests__/text-buffer.test.ts +0 -328
  142. package/src/lib/__tests__/text-utils.test.ts +0 -32
  143. package/src/lib/__tests__/timing.test.ts +0 -78
  144. package/src/lib/__tests__/utils.test.ts +0 -238
  145. package/src/lib/__tests__/vim-buffer-actions.test.ts +0 -154
  146. package/src/lib/ansi.ts +0 -150
  147. package/src/lib/cli-push-server.ts +0 -112
  148. package/src/lib/cli.ts +0 -44
  149. package/src/lib/clipboard.ts +0 -226
  150. package/src/lib/command-utils.ts +0 -93
  151. package/src/lib/commands.ts +0 -270
  152. package/src/lib/constants.ts +0 -3
  153. package/src/lib/extension-connection.ts +0 -181
  154. package/src/lib/focusables.ts +0 -7
  155. package/src/lib/fs.ts +0 -533
  156. package/src/lib/markdown/code-block.tsx +0 -63
  157. package/src/lib/markdown/index.ts +0 -4
  158. package/src/lib/markdown/link.tsx +0 -19
  159. package/src/lib/markdown/markdown.tsx +0 -372
  160. package/src/lib/markdown/types.ts +0 -15
  161. package/src/lib/mcpCommandHandler.ts +0 -121
  162. package/src/lib/mcpManagement.ts +0 -44
  163. package/src/lib/path-paste.ts +0 -185
  164. package/src/lib/path.ts +0 -179
  165. package/src/lib/queries.ts +0 -15
  166. package/src/lib/standaloneMcpService.ts +0 -688
  167. package/src/lib/status-utils.ts +0 -237
  168. package/src/lib/test-utils.tsx +0 -72
  169. package/src/lib/text-buffer.ts +0 -2415
  170. package/src/lib/text-utils.ts +0 -272
  171. package/src/lib/timing.ts +0 -63
  172. package/src/lib/types.ts +0 -295
  173. package/src/lib/utils.ts +0 -182
  174. package/src/lib/vim-buffer-actions.ts +0 -732
  175. package/src/providers/agent.tsx +0 -1063
  176. package/src/providers/api-client.tsx +0 -43
  177. package/src/services/logger.ts +0 -85
  178. package/src/terminal/detection.ts +0 -187
  179. package/src/terminal/exit.ts +0 -279
  180. package/src/terminal/notification.ts +0 -83
  181. package/src/terminal/progress.ts +0 -201
  182. package/src/terminal/setup.ts +0 -797
  183. package/src/terminal/types.ts +0 -51
  184. package/src/theme/context.tsx +0 -57
  185. package/src/theme/index.ts +0 -4
  186. package/src/theme/themed.tsx +0 -35
  187. package/src/theme/themes.json +0 -546
  188. package/src/theme/types.ts +0 -110
  189. package/src/tools/types.ts +0 -59
  190. package/src/tools/utils/__tests__/zod-coercion.test.ts +0 -33
  191. package/src/tools/utils/tool-ui-components.tsx +0 -649
  192. package/src/tools/utils/zod-coercion.ts +0 -35
  193. package/tsconfig.json +0 -16
  194. package/tsconfig.node.json +0 -29
  195. package/tsconfig.test.json +0 -27
  196. package/tsdown.config.ts +0 -17
  197. package/vitest.config.ts +0 -76
@@ -1,149 +0,0 @@
1
- import React from "react";
2
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
3
-
4
- import { stripAnsi } from "../lib/ansi.js";
5
- import { sleep } from "../lib/utils.js";
6
- import { renderWithProviders, waitForFrame } from "./helpers/test-helpers.js";
7
-
8
- // Mock the shell-size context to provide consistent terminal dimensions in tests
9
- vi.mock("../context/shell-size.js", async () => {
10
- const { createContext } = await import("react");
11
- const ShellSizeContext = createContext<{ width: number; height: number } | null>({
12
- width: 120,
13
- height: 40,
14
- });
15
- return {
16
- ShellSizeContext,
17
- ShellSizeProvider: ({ children }: { children: React.ReactNode }) => children,
18
- useShellSize: () => ({ width: 120, height: 40 }),
19
- };
20
- });
21
-
22
- import { simulateText, simulateEnter, simulateKeypress } from "./helpers/test-helpers.js";
23
-
24
- describe.sequential("File Creation Permission E2E Tests", () => {
25
- beforeEach(() => {
26
- vi.spyOn(process, "exit").mockImplementation(() => {
27
- throw new Error("process.exit called");
28
- });
29
- });
30
-
31
- afterEach(() => {
32
- vi.restoreAllMocks();
33
- });
34
-
35
- it("should show file creation permission dialog with options", async () => {
36
- const { App } = await import("../entrypoints/repl.js");
37
- const { Timing } = await import("../lib/timing.js");
38
-
39
- const timing = new Timing();
40
-
41
- const { lastFrame, stdin, unmount } = renderWithProviders(React.createElement(App, { timing }));
42
-
43
- // Wait for FULL TUI to render - look for the input prompt indicator
44
- await waitForFrame(
45
- lastFrame,
46
- (frame) => {
47
- const plain = stripAnsi(frame);
48
- return plain.includes("for shortcuts") || plain.includes("shift+tab");
49
- },
50
- 30000,
51
- );
52
- await sleep(100);
53
-
54
- // Type the message using jar's stdin.write()
55
- const message = "Create a helloWorld.py file";
56
- simulateText(stdin, message);
57
- await waitForFrame(lastFrame, (frame) => stripAnsi(frame).includes("helloWorld.py"), 5000);
58
-
59
- simulateEnter(stdin);
60
-
61
- // Wait for the permission dialog to appear (increase timeout for CI)
62
- // The mock has a 2500ms delay before sending the tool request
63
- // IMPORTANT: Only wait for '1. Yes' which is unique to the permission dialog
64
- // Do NOT use 'helloWorld.py' as that matches the user's input message too early
65
- await waitForFrame(
66
- lastFrame,
67
- (frame) => {
68
- const plain = stripAnsi(frame);
69
- return plain.includes("1. Yes") || plain.includes("Tab to add additional instructions");
70
- },
71
- 60000,
72
- );
73
-
74
- let frame = stripAnsi(lastFrame() || "");
75
- expect(frame).toContain("helloWorld.py");
76
- expect(frame).toContain("1. Yes");
77
- expect(frame).toContain("2. Yes, and enable auto-edit mode");
78
- expect(frame).toContain("3. No");
79
- expect(frame).toContain("Tab to add additional instructions");
80
- expect(frame).toMatch(/Esc to (reject|cancel)/);
81
-
82
- // Press Enter to accept
83
- simulateEnter(stdin);
84
- await sleep(100);
85
-
86
- unmount();
87
- }, 120000);
88
-
89
- it("should allow adding instructions via Tab key", async () => {
90
- const { App } = await import("../entrypoints/repl.js");
91
- const { Timing } = await import("../lib/timing.js");
92
-
93
- const timing = new Timing();
94
-
95
- const { lastFrame, stdin, unmount } = renderWithProviders(React.createElement(App, { timing }));
96
-
97
- // Wait for FULL TUI to render - look for the input prompt indicator
98
- await waitForFrame(
99
- lastFrame,
100
- (frame) => {
101
- const plain = stripAnsi(frame);
102
- return plain.includes("for shortcuts") || plain.includes("shift+tab");
103
- },
104
- 30000,
105
- );
106
- await sleep(100);
107
-
108
- simulateText(stdin, "Create a helloWorld.py file");
109
- await waitForFrame(lastFrame, (frame) => stripAnsi(frame).includes("helloWorld.py"), 5000);
110
-
111
- simulateEnter(stdin);
112
-
113
- // Wait for the permission dialog to appear (increase timeout for CI)
114
- // The mock has a 2500ms delay before sending the tool request
115
- // IMPORTANT: Only wait for permission dialog text, not 'helloWorld.py' which matches user input
116
- await waitForFrame(
117
- lastFrame,
118
- (frame) => {
119
- const plain = stripAnsi(frame);
120
- return plain.includes("Tab to add additional instructions");
121
- },
122
- 60000,
123
- );
124
-
125
- let frame = stripAnsi(lastFrame() || "");
126
- expect(frame).toContain("helloWorld.py");
127
- expect(frame).toContain("Tab to add additional instructions");
128
-
129
- simulateKeypress(stdin, "\t");
130
- await waitForFrame(
131
- lastFrame,
132
- (f) => stripAnsi(f).includes("Type here to tell AbacusAI what to do differently"),
133
- 5000,
134
- );
135
-
136
- frame = stripAnsi(lastFrame() || "");
137
- expect(frame).toContain("Type here to tell AbacusAI what to do differently");
138
-
139
- simulateText(stdin, "its good");
140
- await waitForFrame(lastFrame, (f) => stripAnsi(f).includes("1. Yes, its good"), 5000);
141
-
142
- frame = stripAnsi(lastFrame() || "");
143
- expect(frame).toContain("1. Yes, its good");
144
- expect(frame).not.toContain("Tab to add additional instructions");
145
- expect(frame).toMatch(/Esc to (reject|cancel)/);
146
-
147
- unmount();
148
- }, 120000);
149
- });
@@ -1,449 +0,0 @@
1
- import type { ClientLogger, HeadersProvider } from "@codellm/api";
2
-
3
- import { AbacusClient, type SSEEvent } from "@codellm/api";
4
- import { AuthManager } from "@codellm/auth";
5
- import { renderForTest } from "@codellm/jar";
6
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
7
- import React, { type ReactElement } from "react";
8
- import { vi, type Mock } from "vitest";
9
-
10
- /** Maps each function property of T to Mock<fn>, keeping non-function props as-is. */
11
- type MockOf<T> = {
12
- [K in keyof T]: T[K] extends (...args: any[]) => any ? Mock<T[K]> : T[K];
13
- };
14
-
15
- import type {
16
- FileSystemTools,
17
- ITerminalService,
18
- IAbacusBrowserService,
19
- ICommand,
20
- ICommandResult,
21
- } from "../../lib/types.js";
22
- import type { ToolExecutionContext } from "../../tools/types.ts";
23
-
24
- import { AgentMode } from "../../components/composer/types.ts";
25
- import { AgentModeProvider } from "../../context/agent-mode.js";
26
- import { ExtensionFileProvider } from "../../context/extension-file.js";
27
- import { NetworkActivityProvider } from "../../context/network-activity.js";
28
- import { NotificationProvider } from "../../context/notification.js";
29
- import { ShellSizeContext } from "../../context/shell-size.js";
30
- import { ShellTitleProvider } from "../../context/shell-title.js";
31
- import { AgentProvider } from "../../providers/agent.js";
32
- import { ApiClientProvider } from "../../providers/api-client.js";
33
- import { ThemeProvider } from "../../theme/index.js";
34
-
35
- // MockShellSizeProvider for tests - provides consistent terminal dimensions via the real ShellSizeContext
36
- function MockShellSizeProvider({ children }: React.PropsWithChildren) {
37
- const value = { width: 120, height: 40 };
38
- return React.createElement(ShellSizeContext.Provider, { value }, children);
39
- }
40
-
41
- export interface E2ETestContext {
42
- lastFrame: () => string;
43
- stdin: {
44
- write: (data: string) => void;
45
- };
46
- frames: string[];
47
- unmount: () => void;
48
- }
49
-
50
- /**
51
- * Render a React element for E2E tests using jar's reconciler.
52
- * Returns a context with `lastFrame()`, `frames`, `stdin.write()`, and `unmount()`.
53
- */
54
- export function renderE2E(component: ReactElement): E2ETestContext {
55
- return renderForTest(component);
56
- }
57
-
58
- /**
59
- * Render a React element wrapped in all required test providers (QueryClient, API client,
60
- * ShellSize, ShellTitle, Theme, Agent, etc.).
61
- *
62
- * Use this when testing components that rely on app-level contexts (e.g. App from repl.js),
63
- * instead of renderE2E() which does not supply any providers.
64
- *
65
- * @example
66
- * const { lastFrame, stdin, unmount } = renderWithProviders(
67
- * React.createElement(App, { timing })
68
- * );
69
- */
70
- export function renderWithProviders(component: ReactElement): E2ETestContext {
71
- const Wrapper = createTestWrapper();
72
- return renderForTest(React.createElement(Wrapper, { children: component }));
73
- }
74
-
75
- export function simulateKeypress(stdin: { write: (data: string) => void }, key: string) {
76
- stdin.write(key);
77
- }
78
-
79
- export function simulateEnter(stdin: { write: (data: string) => void }) {
80
- stdin.write("\r");
81
- }
82
-
83
- export function simulateText(stdin: { write: (data: string) => void }, text: string) {
84
- for (const char of text) {
85
- stdin.write(char);
86
- }
87
- }
88
-
89
- export function simulateCtrlC(stdin: { write: (data: string) => void }) {
90
- stdin.write("\x03");
91
- }
92
-
93
- export function simulateEscape(stdin: { write: (data: string) => void }) {
94
- stdin.write("\x1b");
95
- }
96
-
97
- export function simulateUpArrow(stdin: { write: (data: string) => void }) {
98
- stdin.write("\x1b[A");
99
- }
100
-
101
- export function simulateDownArrow(stdin: { write: (data: string) => void }) {
102
- stdin.write("\x1b[B");
103
- }
104
-
105
- export function simulateRightArrow(stdin: { write: (data: string) => void }) {
106
- stdin.write("\x1b[C");
107
- }
108
-
109
- export function simulateLeftArrow(stdin: { write: (data: string) => void }) {
110
- stdin.write("\x1b[D");
111
- }
112
-
113
- export function waitForFrame(
114
- lastFrame: () => string,
115
- predicate: (frame: string) => boolean,
116
- timeout = 5000,
117
- ): Promise<void> {
118
- return new Promise((resolve, reject) => {
119
- const startTime = Date.now();
120
- const interval = setInterval(() => {
121
- const frame = lastFrame();
122
- if (predicate(frame)) {
123
- clearInterval(interval);
124
- resolve();
125
- } else if (Date.now() - startTime > timeout) {
126
- clearInterval(interval);
127
- reject(new Error(`Timeout waiting for frame matching predicate. Last frame:\n${frame}`));
128
- }
129
- }, 50);
130
- });
131
- }
132
-
133
- export function mockApiClient(): { chat: Mock; listModels: Mock } {
134
- return {
135
- chat: vi.fn().mockResolvedValue({
136
- choices: [
137
- {
138
- message: {
139
- content: "Mock response",
140
- },
141
- },
142
- ],
143
- }),
144
- listModels: vi.fn().mockResolvedValue([{ id: "test-model", name: "Test Model" }]),
145
- };
146
- }
147
-
148
- export function mockConfigService(): { get: Mock; set: Mock; has: Mock } {
149
- return {
150
- get: vi.fn().mockImplementation((key: string) => {
151
- const config: Record<string, any> = {
152
- apiKey: "test-api-key",
153
- model: "test-model",
154
- };
155
- return config[key];
156
- }),
157
- set: vi.fn(),
158
- has: vi.fn().mockReturnValue(true),
159
- };
160
- }
161
-
162
- const mockHeadersProvider: HeadersProvider = {
163
- getHeaders: vi.fn().mockResolvedValue({ APIKEY: "test-api-key" }),
164
- };
165
-
166
- const mockLogger: ClientLogger = {
167
- error: vi.fn(),
168
- debug: vi.fn(),
169
- warn: vi.fn(),
170
- };
171
-
172
- export function createMockAbacusClient() {
173
- const client = new AbacusClient(mockHeadersProvider, mockLogger);
174
-
175
- client.getUserInfo = vi.fn().mockResolvedValue({ result: { email: "test@test.com" } });
176
- client.getConversationsList = vi.fn().mockResolvedValue({ result: [] });
177
- client.listExternalApplications = vi.fn().mockResolvedValue({ success: true, result: [] });
178
- client.recordUserAction = vi.fn().mockResolvedValue({});
179
- client.setUrl = vi.fn().mockResolvedValue(undefined);
180
- client.setChatWebDomain = vi.fn().mockResolvedValue(undefined);
181
- client.getChatWebDomain = vi.fn().mockResolvedValue(null);
182
- client.clearDeploymentConversation = vi.fn().mockResolvedValue(null);
183
- client.getCodeEdit = vi.fn().mockResolvedValue(null);
184
- client.listLLMModels = vi.fn().mockResolvedValue(null);
185
- client.getConstantsAutocomplete = vi.fn().mockResolvedValue(null);
186
- client.getCodeAutocompleteResponse = vi.fn().mockResolvedValue(null);
187
- client.getAutocompleteEditPrediction = vi.fn().mockResolvedValue(null);
188
- client.resetEndpoints = vi.fn().mockResolvedValue(undefined);
189
- client.getDeploymentConversation = vi
190
- .fn()
191
- .mockResolvedValue({ success: true, result: { history: [] } });
192
- client.createCodellmDeploymentConversation = vi
193
- .fn()
194
- .mockResolvedValue({ success: true, result: { deploymentConversationId: "test-convo-id" } });
195
-
196
- // Mock streamAgentMessage as an async generator that yields SSE events
197
- // Use setTimeout delays to ensure React useEffect hooks have run first
198
- client.streamAgentMessage = vi.fn().mockImplementation(function () {
199
- async function* generate(): AsyncGenerator<SSEEvent> {
200
- // Delay to ensure all React useEffect hooks have run
201
- await new Promise((r) => setTimeout(r, 2000));
202
-
203
- // First event: text segment
204
- yield {
205
- segment: "I will create a file helloWorld.py for you.",
206
- counter: 1,
207
- message_id: "test-message-id",
208
- };
209
-
210
- // Small delay to ensure proper processing
211
- await new Promise((r) => setTimeout(r, 500));
212
-
213
- // Second event: tool request
214
- yield {
215
- toolUseRequest: {
216
- id: "tool-1",
217
- type: "builtin",
218
- name: "edit",
219
- input: {
220
- targetFile: "helloWorld.py",
221
- codeEdit: 'print("Hello, World!")',
222
- overwriteFile: true,
223
- instructions: "Creating helloWorld.py file",
224
- },
225
- },
226
- counter: 2,
227
- message_id: "test-message-id",
228
- };
229
- }
230
- return generate();
231
- });
232
-
233
- // Mock streamChatMessage as an async generator
234
- client.streamChatMessage = vi.fn().mockImplementation(function () {
235
- async function* generate(): AsyncGenerator<SSEEvent> {
236
- await new Promise((r) => setTimeout(r, 2000));
237
- yield {
238
- segment: "I will create a file helloWorld.py for you.",
239
- counter: 1,
240
- message_id: "test-message-id",
241
- };
242
- }
243
- return generate();
244
- });
245
-
246
- return client as AbacusClient & {
247
- getUserInfo: Mock<typeof client.getUserInfo>;
248
- getConversationsList: Mock<typeof client.getConversationsList>;
249
- listExternalApplications: Mock<typeof client.listExternalApplications>;
250
- recordUserAction: Mock<typeof client.recordUserAction>;
251
- setUrl: Mock<typeof client.setUrl>;
252
- setChatWebDomain: Mock<typeof client.setChatWebDomain>;
253
- getChatWebDomain: Mock<typeof client.getChatWebDomain>;
254
- clearDeploymentConversation: Mock<typeof client.clearDeploymentConversation>;
255
- getCodeEdit: Mock<typeof client.getCodeEdit>;
256
- listLLMModels: Mock<typeof client.listLLMModels>;
257
- getConstantsAutocomplete: Mock<typeof client.getConstantsAutocomplete>;
258
- getCodeAutocompleteResponse: Mock<typeof client.getCodeAutocompleteResponse>;
259
- getAutocompleteEditPrediction: Mock<typeof client.getAutocompleteEditPrediction>;
260
- resetEndpoints: Mock<typeof client.resetEndpoints>;
261
- getDeploymentConversation: Mock<typeof client.getDeploymentConversation>;
262
- createCodellmDeploymentConversation: Mock<typeof client.createCodellmDeploymentConversation>;
263
- streamAgentMessage: Mock<typeof client.streamAgentMessage>;
264
- streamChatMessage: Mock<typeof client.streamChatMessage>;
265
- };
266
- }
267
-
268
- export function createMockNotificationService(): { error: ReturnType<typeof vi.fn> } {
269
- return {
270
- error: vi.fn(),
271
- };
272
- }
273
-
274
- type MockToolExcecutionContext = Omit<
275
- ToolExecutionContext,
276
- "fileSystemTools" | "terminalService" | "abacusBrowserService" | "apiClient"
277
- > & {
278
- fileSystemTools: ReturnType<typeof createMockFileSystemTools>;
279
- terminalService: ReturnType<typeof createMockTerminalService>;
280
- abacusBrowserService: ReturnType<typeof createMockBrowserService>;
281
- apiClient: ReturnType<typeof createMockAbacusClient>;
282
- };
283
-
284
- export function createMockContext(
285
- overrides?: Partial<MockToolExcecutionContext>,
286
- ): MockToolExcecutionContext {
287
- return {
288
- fileSystemTools: createMockFileSystemTools(),
289
- terminalService: createMockTerminalService(),
290
- abacusBrowserService: createMockBrowserService(),
291
- apiClient: createMockAbacusClient(),
292
- mcpService: undefined,
293
- extensionConnection: undefined,
294
-
295
- abortController: new AbortController(),
296
- workspacePath: "/test/workspace",
297
- conversationId: "test-conversation",
298
- agentMode: AgentMode.Normal,
299
- toolCallId: "test-tool-call",
300
- status: "pending",
301
- vsCodeAppliedChanges: false,
302
-
303
- uploadedDocs: new Set(),
304
- allowEditingPaths: [],
305
-
306
- addDiff: vi.fn().mockReturnValue(undefined),
307
- onOutputUpdate: vi.fn().mockReturnValue(undefined),
308
- ...overrides,
309
- } satisfies MockToolExcecutionContext;
310
- }
311
-
312
- export function createMockAuthManager(): MockOf<HeadersProvider> {
313
- return {
314
- getHeaders: vi.fn().mockResolvedValue({ APIKEY: "test-api-key" }),
315
- } satisfies HeadersProvider;
316
- }
317
-
318
- export function createMockFileSystemTools(): MockOf<FileSystemTools> {
319
- return {
320
- ls: vi.fn().mockResolvedValue(""),
321
- mkdir: vi.fn().mockResolvedValue({ undo: vi.fn() }),
322
- view: vi.fn().mockResolvedValue(""),
323
- readRawFile: vi.fn().mockResolvedValue(""),
324
- create: vi.fn().mockResolvedValue({ undo: vi.fn() }),
325
- readFile: vi.fn().mockResolvedValue(""),
326
- deleteFile: vi.fn().mockResolvedValue(undefined),
327
- listDir: vi.fn().mockResolvedValue(""),
328
- strReplace: vi.fn().mockResolvedValue({ undo: vi.fn() }),
329
- grep: vi.fn().mockResolvedValue({
330
- matches: [],
331
- metadata: {
332
- offset: 0,
333
- limit: 0,
334
- totalMatches: 0,
335
- hasMore: false,
336
- },
337
- }),
338
- grepFile: vi.fn().mockResolvedValue([]),
339
- grepTextFile: vi.fn().mockResolvedValue([]),
340
- } satisfies FileSystemTools;
341
- }
342
-
343
- type MockTerminalServiceOpts = {
344
- executedCommand?: ICommand;
345
- output?: ICommandResult[];
346
- };
347
-
348
- export function createMockTerminalService(
349
- opts: MockTerminalServiceOpts = {},
350
- ): MockOf<ITerminalService> {
351
- return {
352
- executeCommand: vi.fn().mockResolvedValue(
353
- opts.executedCommand ?? {
354
- result: {
355
- get: vi.fn().mockResolvedValue({ stdout: "", stderr: "", exitCode: 0 }),
356
- },
357
- },
358
- ),
359
- getOutput: vi.fn().mockReturnValue(opts.output ?? []),
360
- stopCommand: vi.fn().mockResolvedValue(true),
361
- closeTerminal: vi.fn().mockResolvedValue(undefined),
362
- dispose: vi.fn(),
363
- } satisfies ITerminalService;
364
- }
365
-
366
- export function createMockBrowserService(): MockOf<IAbacusBrowserService> {
367
- return {
368
- navigateTo: vi.fn().mockResolvedValue(undefined),
369
- openTab: vi.fn().mockResolvedValue(1),
370
- switchActiveTab: vi.fn().mockResolvedValue(undefined),
371
- closeTab: vi.fn().mockResolvedValue(undefined),
372
- refreshTab: vi.fn().mockResolvedValue(undefined),
373
- getTabContent: vi.fn().mockResolvedValue({
374
- text: "",
375
- metadata: { offset: 0, limit: 0, totalLength: 0, hasMore: false },
376
- }),
377
- do: vi.fn().mockResolvedValue({ content: { text: "", images: [] } }),
378
- getInteractiveElements: vi.fn().mockResolvedValue(""),
379
- doOnElementId: vi.fn().mockResolvedValue({ content: { text: "", images: [] } }),
380
- } satisfies IAbacusBrowserService;
381
- }
382
-
383
- export interface TestWrapperProps {
384
- children: ReactElement;
385
- }
386
-
387
- export function createTestWrapper(): React.FC<TestWrapperProps> {
388
- const queryClient = new QueryClient({
389
- defaultOptions: {
390
- queries: {
391
- retry: false,
392
- },
393
- },
394
- });
395
- const apiClient = createMockAbacusClient();
396
- // Create a minimal AuthManager-shaped mock for test contexts
397
- const mockSecureStorage = {
398
- getSecret: vi.fn().mockResolvedValue(null),
399
- setSecret: vi.fn().mockResolvedValue(undefined),
400
- deleteSecret: vi.fn().mockResolvedValue(undefined),
401
- };
402
- const mockAuthManager = new AuthManager(mockSecureStorage);
403
-
404
- return function TestWrapper({ children }: TestWrapperProps) {
405
- return React.createElement(
406
- ThemeProvider,
407
- null,
408
- React.createElement(
409
- ApiClientProvider,
410
- { client: apiClient, authManager: mockAuthManager },
411
- React.createElement(
412
- QueryClientProvider,
413
- { client: queryClient },
414
- React.createElement(
415
- MockShellSizeProvider,
416
- null,
417
- React.createElement(
418
- ShellTitleProvider,
419
- null,
420
- React.createElement(
421
- NotificationProvider,
422
- null,
423
- React.createElement(
424
- ExtensionFileProvider,
425
- null,
426
- React.createElement(
427
- NetworkActivityProvider,
428
- null,
429
- React.createElement(
430
- AgentModeProvider,
431
- null,
432
- React.createElement(
433
- AgentProvider,
434
- {
435
- apiClient,
436
- },
437
- children,
438
- ),
439
- ),
440
- ),
441
- ),
442
- ),
443
- ),
444
- ),
445
- ),
446
- ),
447
- );
448
- };
449
- }
@@ -1,34 +0,0 @@
1
- import React from "react";
2
- import { describe, it, expect } from "vitest";
3
-
4
- import { App } from "../entrypoints/repl.js";
5
- import { Timing } from "../lib/timing.js";
6
- import {
7
- renderWithProviders,
8
- simulateText,
9
- simulateEscape,
10
- waitForFrame,
11
- } from "./helpers/test-helpers.js";
12
-
13
- describe.concurrent("Keyboard Navigation E2E Tests", () => {
14
- it("double ESC resets composer", async () => {
15
- const timing = new Timing();
16
-
17
- const { lastFrame, stdin, unmount } = renderWithProviders(React.createElement(App, { timing }));
18
-
19
- await waitForFrame(lastFrame, (frame) => frame.length > 0, 5000);
20
-
21
- simulateText(stdin, "Some text in composer");
22
-
23
- const frameBeforeEsc = lastFrame();
24
- expect(frameBeforeEsc.length).toBeGreaterThan(0);
25
-
26
- simulateEscape(stdin);
27
- simulateEscape(stdin);
28
-
29
- const frameAfterEsc = lastFrame();
30
- expect(frameAfterEsc.length).toBeGreaterThan(0);
31
-
32
- unmount();
33
- });
34
- });