@abacus-ai/cli 1.106.25007 → 2.0.0-canary.0
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/.oxlintrc.json +8 -0
- package/dist/index.mjs +12603 -0
- package/package.json +7 -39
- package/resources/abacus.ico +0 -0
- package/resources/entitlements.plist +9 -0
- package/src/__e2e__/README.md +196 -0
- package/src/__e2e__/agent-interactions.e2e.test.tsx +61 -0
- package/src/__e2e__/cli-commands.e2e.test.tsx +77 -0
- package/src/__e2e__/conversation-throttle.e2e.test.ts +453 -0
- package/src/__e2e__/conversation.e2e.test.tsx +56 -0
- package/src/__e2e__/diff-preview.e2e.test.tsx +3399 -0
- package/src/__e2e__/file-creation.e2e.test.tsx +149 -0
- package/src/__e2e__/helpers/test-helpers.ts +450 -0
- package/src/__e2e__/keyboard-navigation.e2e.test.tsx +34 -0
- package/src/__e2e__/llm-models.e2e.test.ts +402 -0
- package/src/__e2e__/mcp/mcp-callback-flow.e2e.test.tsx +71 -0
- package/src/__e2e__/mcp/mcp-full-app-ui.e2e.test.tsx +167 -0
- package/src/__e2e__/mcp/mcp-ui-rendering.e2e.test.tsx +185 -0
- package/src/__e2e__/repl.e2e.test.tsx +78 -0
- package/src/__e2e__/shell-compatibility.e2e.test.tsx +76 -0
- package/src/__e2e__/theme-mcp.e2e.test.tsx +98 -0
- package/src/__e2e__/tool-permissions.e2e.test.tsx +66 -0
- package/src/args.ts +22 -0
- package/src/components/__tests__/react-compiler.test.tsx +78 -0
- package/src/components/__tests__/status-indicator.test.tsx +403 -0
- package/src/components/composer/__tests__/bash-runner.test.tsx +263 -0
- package/src/components/composer/agent-mode-indicator.tsx +63 -0
- package/src/components/composer/bash-runner.tsx +54 -0
- package/src/components/composer/commands/default-commands.tsx +615 -0
- package/src/components/composer/commands/handler.tsx +59 -0
- package/src/components/composer/commands/picker.tsx +273 -0
- package/src/components/composer/commands/registry.ts +233 -0
- package/src/components/composer/commands/types.ts +33 -0
- package/src/components/composer/context.tsx +88 -0
- package/src/components/composer/file-mention-picker.tsx +83 -0
- package/src/components/composer/help.tsx +44 -0
- package/src/components/composer/index.tsx +1006 -0
- package/src/components/composer/mentions.ts +57 -0
- package/src/components/composer/message-queue.tsx +70 -0
- package/src/components/composer/mode-panel.tsx +35 -0
- package/src/components/composer/modes/__tests__/bash-handler.test.tsx +755 -0
- package/src/components/composer/modes/__tests__/bash-renderer.test.tsx +1108 -0
- package/src/components/composer/modes/bash-handler.tsx +132 -0
- package/src/components/composer/modes/bash-renderer.tsx +175 -0
- package/src/components/composer/modes/default-handlers.tsx +33 -0
- package/src/components/composer/modes/index.ts +41 -0
- package/src/components/composer/modes/types.ts +21 -0
- package/src/components/composer/persistent-shell.ts +283 -0
- package/src/components/composer/process.ts +65 -0
- package/src/components/composer/types.ts +9 -0
- package/src/components/composer/use-mention-search.ts +68 -0
- package/src/components/error-boundry.tsx +60 -0
- package/src/components/exit-message.tsx +29 -0
- package/src/components/expanded-view.tsx +74 -0
- package/src/components/file-completion.tsx +127 -0
- package/src/components/header.tsx +47 -0
- package/src/components/logo.tsx +37 -0
- package/src/components/segments.tsx +356 -0
- package/src/components/status-indicator.tsx +306 -0
- package/src/components/tool-group-summary.tsx +263 -0
- package/src/components/tool-permissions/ask-user-question-permission-ui.tsx +312 -0
- package/src/components/tool-permissions/diff-preview.tsx +355 -0
- package/src/components/tool-permissions/index.ts +5 -0
- package/src/components/tool-permissions/permission-options.tsx +375 -0
- package/src/components/tool-permissions/permission-preview-header.tsx +57 -0
- package/src/components/tool-permissions/tool-permission-ui.tsx +398 -0
- package/src/components/tools/agent/ask-user-question.tsx +101 -0
- package/src/components/tools/agent/enter-plan-mode.tsx +49 -0
- package/src/components/tools/agent/exit-plan-mode.tsx +75 -0
- package/src/components/tools/agent/handoff-to-main.tsx +27 -0
- package/src/components/tools/agent/subagent.tsx +37 -0
- package/src/components/tools/agent/todo-write.tsx +104 -0
- package/src/components/tools/browser/close-tab.tsx +58 -0
- package/src/components/tools/browser/computer.tsx +70 -0
- package/src/components/tools/browser/get-interactive-elements.tsx +54 -0
- package/src/components/tools/browser/get-tab-content.tsx +51 -0
- package/src/components/tools/browser/navigate-to.tsx +59 -0
- package/src/components/tools/browser/new-tab.tsx +60 -0
- package/src/components/tools/browser/perform-action.tsx +63 -0
- package/src/components/tools/browser/refresh-tab.tsx +43 -0
- package/src/components/tools/browser/switch-tab.tsx +58 -0
- package/src/components/tools/filesystem/delete-file.tsx +104 -0
- package/src/components/tools/filesystem/edit.tsx +220 -0
- package/src/components/tools/filesystem/list-dir.tsx +78 -0
- package/src/components/tools/filesystem/read-file.tsx +180 -0
- package/src/components/tools/filesystem/upload-image.tsx +76 -0
- package/src/components/tools/ide/ide-diagnostics.tsx +62 -0
- package/src/components/tools/index.ts +91 -0
- package/src/components/tools/mcp/mcp-tool.tsx +158 -0
- package/src/components/tools/search/fetch-url.tsx +73 -0
- package/src/components/tools/search/file-search.tsx +78 -0
- package/src/components/tools/search/grep.tsx +90 -0
- package/src/components/tools/search/semantic-search.tsx +66 -0
- package/src/components/tools/search/web-search.tsx +71 -0
- package/src/components/tools/shared/index.tsx +48 -0
- package/src/components/tools/shared/zod-coercion.ts +35 -0
- package/src/components/tools/terminal/bash-tool-output.tsx +174 -0
- package/src/components/tools/terminal/get-terminal-output.tsx +85 -0
- package/src/components/tools/terminal/run-in-terminal.tsx +106 -0
- package/src/components/tools/types.ts +16 -0
- package/src/components/tools.tsx +66 -0
- package/src/components/ui/__tests__/divider.test.tsx +61 -0
- package/src/components/ui/__tests__/gradient.test.tsx +125 -0
- package/src/components/ui/__tests__/input.test.tsx +166 -0
- package/src/components/ui/__tests__/select.test.tsx +273 -0
- package/src/components/ui/__tests__/shimmer.test.tsx +99 -0
- package/src/components/ui/blinking-indicator.tsx +25 -0
- package/src/components/ui/divider.tsx +162 -0
- package/src/components/ui/gradient.tsx +56 -0
- package/src/components/ui/input.tsx +228 -0
- package/src/components/ui/select.tsx +151 -0
- package/src/components/ui/shimmer.tsx +84 -0
- package/src/context/agent-mode.tsx +95 -0
- package/src/context/extension-file.tsx +136 -0
- package/src/context/network-activity.tsx +45 -0
- package/src/context/notification.tsx +62 -0
- package/src/context/shell-size.tsx +49 -0
- package/src/context/shell-title.tsx +38 -0
- package/src/entrypoints/print-mode.ts +312 -0
- package/src/entrypoints/repl.tsx +401 -0
- package/src/hooks/use-agent.ts +15 -0
- package/src/hooks/use-api-client.ts +1 -0
- package/src/hooks/use-available-height.ts +8 -0
- package/src/hooks/use-cleanup.ts +29 -0
- package/src/hooks/use-interrupt-manager.ts +242 -0
- package/src/hooks/use-models.ts +22 -0
- package/src/index.ts +217 -0
- package/src/lib/__tests__/ansi.test.ts +255 -0
- package/src/lib/__tests__/cli.test.ts +122 -0
- package/src/lib/__tests__/commands.test.ts +325 -0
- package/src/lib/__tests__/constants.test.ts +15 -0
- package/src/lib/__tests__/focusables.test.ts +25 -0
- package/src/lib/__tests__/fs.test.ts +231 -0
- package/src/lib/__tests__/markdown.test.tsx +348 -0
- package/src/lib/__tests__/mcpCommandHandler.test.ts +173 -0
- package/src/lib/__tests__/mcpManagement.test.ts +38 -0
- package/src/lib/__tests__/path-paste.test.ts +144 -0
- package/src/lib/__tests__/path.test.ts +300 -0
- package/src/lib/__tests__/queries.test.ts +39 -0
- package/src/lib/__tests__/standaloneMcpService.test.ts +71 -0
- package/src/lib/__tests__/text-buffer.test.ts +328 -0
- package/src/lib/__tests__/text-utils.test.ts +32 -0
- package/src/lib/__tests__/timing.test.ts +78 -0
- package/src/lib/__tests__/utils.test.ts +238 -0
- package/src/lib/__tests__/vim-buffer-actions.test.ts +154 -0
- package/src/lib/ansi.ts +150 -0
- package/src/lib/cli-push-server.ts +112 -0
- package/src/lib/cli.ts +44 -0
- package/src/lib/clipboard.ts +226 -0
- package/src/lib/command-utils.ts +93 -0
- package/src/lib/commands.ts +270 -0
- package/src/lib/constants.ts +3 -0
- package/src/lib/extension-connection.ts +181 -0
- package/src/lib/focusables.ts +7 -0
- package/src/lib/fs.ts +533 -0
- package/src/lib/markdown/code-block.tsx +63 -0
- package/src/lib/markdown/index.ts +4 -0
- package/src/lib/markdown/link.tsx +19 -0
- package/src/lib/markdown/markdown.tsx +372 -0
- package/src/lib/markdown/types.ts +15 -0
- package/src/lib/mcpCommandHandler.ts +121 -0
- package/src/lib/mcpManagement.ts +44 -0
- package/src/lib/path-paste.ts +185 -0
- package/src/lib/path.ts +179 -0
- package/src/lib/queries.ts +15 -0
- package/src/lib/standaloneMcpService.ts +688 -0
- package/src/lib/status-utils.ts +237 -0
- package/src/lib/test-utils.tsx +72 -0
- package/src/lib/text-buffer.ts +2415 -0
- package/src/lib/text-utils.ts +272 -0
- package/src/lib/timing.ts +63 -0
- package/src/lib/types.ts +295 -0
- package/src/lib/utils.ts +182 -0
- package/src/lib/vim-buffer-actions.ts +732 -0
- package/src/providers/agent.tsx +1075 -0
- package/src/providers/api-client.tsx +43 -0
- package/src/services/logger.ts +85 -0
- package/src/terminal/detection.ts +187 -0
- package/src/terminal/exit.ts +279 -0
- package/src/terminal/notification.ts +83 -0
- package/src/terminal/progress.ts +201 -0
- package/src/terminal/setup.ts +797 -0
- package/src/terminal/suspend.ts +58 -0
- package/src/terminal/types.ts +51 -0
- package/src/theme/context.tsx +57 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/themed.tsx +35 -0
- package/src/theme/themes.json +546 -0
- package/src/theme/types.ts +110 -0
- package/src/tools/types.ts +59 -0
- package/src/tools/utils/__tests__/zod-coercion.test.ts +33 -0
- package/src/tools/utils/tool-ui-components.tsx +631 -0
- package/src/tools/utils/zod-coercion.ts +35 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +29 -0
- package/tsconfig.test.json +27 -0
- package/tsdown.config.ts +17 -0
- package/vitest.config.ts +76 -0
- package/README.md +0 -28
- package/dist/index.js +0 -26
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,450 @@
|
|
|
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
|
+
terminalTimeoutMs: undefined,
|
|
306
|
+
|
|
307
|
+
addDiff: vi.fn().mockReturnValue(undefined),
|
|
308
|
+
onOutputUpdate: vi.fn().mockReturnValue(undefined),
|
|
309
|
+
...overrides,
|
|
310
|
+
} satisfies MockToolExcecutionContext;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function createMockAuthManager(): MockOf<HeadersProvider> {
|
|
314
|
+
return {
|
|
315
|
+
getHeaders: vi.fn().mockResolvedValue({ APIKEY: "test-api-key" }),
|
|
316
|
+
} satisfies HeadersProvider;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function createMockFileSystemTools(): MockOf<FileSystemTools> {
|
|
320
|
+
return {
|
|
321
|
+
ls: vi.fn().mockResolvedValue(""),
|
|
322
|
+
mkdir: vi.fn().mockResolvedValue({ undo: vi.fn() }),
|
|
323
|
+
view: vi.fn().mockResolvedValue(""),
|
|
324
|
+
readRawFile: vi.fn().mockResolvedValue(""),
|
|
325
|
+
create: vi.fn().mockResolvedValue({ undo: vi.fn() }),
|
|
326
|
+
readFile: vi.fn().mockResolvedValue(""),
|
|
327
|
+
deleteFile: vi.fn().mockResolvedValue(undefined),
|
|
328
|
+
listDir: vi.fn().mockResolvedValue(""),
|
|
329
|
+
strReplace: vi.fn().mockResolvedValue({ undo: vi.fn() }),
|
|
330
|
+
grep: vi.fn().mockResolvedValue({
|
|
331
|
+
matches: [],
|
|
332
|
+
metadata: {
|
|
333
|
+
offset: 0,
|
|
334
|
+
limit: 0,
|
|
335
|
+
totalMatches: 0,
|
|
336
|
+
hasMore: false,
|
|
337
|
+
},
|
|
338
|
+
}),
|
|
339
|
+
grepFile: vi.fn().mockResolvedValue([]),
|
|
340
|
+
grepTextFile: vi.fn().mockResolvedValue([]),
|
|
341
|
+
} satisfies FileSystemTools;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
type MockTerminalServiceOpts = {
|
|
345
|
+
executedCommand?: ICommand;
|
|
346
|
+
output?: ICommandResult[];
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export function createMockTerminalService(
|
|
350
|
+
opts: MockTerminalServiceOpts = {},
|
|
351
|
+
): MockOf<ITerminalService> {
|
|
352
|
+
return {
|
|
353
|
+
executeCommand: vi.fn().mockResolvedValue(
|
|
354
|
+
opts.executedCommand ?? {
|
|
355
|
+
result: {
|
|
356
|
+
get: vi.fn().mockResolvedValue({ stdout: "", stderr: "", exitCode: 0 }),
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
),
|
|
360
|
+
getOutput: vi.fn().mockReturnValue(opts.output ?? []),
|
|
361
|
+
stopCommand: vi.fn().mockResolvedValue(true),
|
|
362
|
+
closeTerminal: vi.fn().mockResolvedValue(undefined),
|
|
363
|
+
dispose: vi.fn(),
|
|
364
|
+
} satisfies ITerminalService;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export function createMockBrowserService(): MockOf<IAbacusBrowserService> {
|
|
368
|
+
return {
|
|
369
|
+
navigateTo: vi.fn().mockResolvedValue(undefined),
|
|
370
|
+
openTab: vi.fn().mockResolvedValue(1),
|
|
371
|
+
switchActiveTab: vi.fn().mockResolvedValue(undefined),
|
|
372
|
+
closeTab: vi.fn().mockResolvedValue(undefined),
|
|
373
|
+
refreshTab: vi.fn().mockResolvedValue(undefined),
|
|
374
|
+
getTabContent: vi.fn().mockResolvedValue({
|
|
375
|
+
text: "",
|
|
376
|
+
metadata: { offset: 0, limit: 0, totalLength: 0, hasMore: false },
|
|
377
|
+
}),
|
|
378
|
+
do: vi.fn().mockResolvedValue({ content: { text: "", images: [] } }),
|
|
379
|
+
getInteractiveElements: vi.fn().mockResolvedValue(""),
|
|
380
|
+
doOnElementId: vi.fn().mockResolvedValue({ content: { text: "", images: [] } }),
|
|
381
|
+
} satisfies IAbacusBrowserService;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface TestWrapperProps {
|
|
385
|
+
children: ReactElement;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export function createTestWrapper(): React.FC<TestWrapperProps> {
|
|
389
|
+
const queryClient = new QueryClient({
|
|
390
|
+
defaultOptions: {
|
|
391
|
+
queries: {
|
|
392
|
+
retry: false,
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
const apiClient = createMockAbacusClient();
|
|
397
|
+
// Create a minimal AuthManager-shaped mock for test contexts
|
|
398
|
+
const mockSecureStorage = {
|
|
399
|
+
getSecret: vi.fn().mockResolvedValue(null),
|
|
400
|
+
setSecret: vi.fn().mockResolvedValue(undefined),
|
|
401
|
+
deleteSecret: vi.fn().mockResolvedValue(undefined),
|
|
402
|
+
};
|
|
403
|
+
const mockAuthManager = new AuthManager(mockSecureStorage);
|
|
404
|
+
|
|
405
|
+
return function TestWrapper({ children }: TestWrapperProps) {
|
|
406
|
+
return React.createElement(
|
|
407
|
+
ThemeProvider,
|
|
408
|
+
null,
|
|
409
|
+
React.createElement(
|
|
410
|
+
ApiClientProvider,
|
|
411
|
+
{ client: apiClient, authManager: mockAuthManager },
|
|
412
|
+
React.createElement(
|
|
413
|
+
QueryClientProvider,
|
|
414
|
+
{ client: queryClient },
|
|
415
|
+
React.createElement(
|
|
416
|
+
MockShellSizeProvider,
|
|
417
|
+
null,
|
|
418
|
+
React.createElement(
|
|
419
|
+
ShellTitleProvider,
|
|
420
|
+
null,
|
|
421
|
+
React.createElement(
|
|
422
|
+
NotificationProvider,
|
|
423
|
+
null,
|
|
424
|
+
React.createElement(
|
|
425
|
+
ExtensionFileProvider,
|
|
426
|
+
null,
|
|
427
|
+
React.createElement(
|
|
428
|
+
NetworkActivityProvider,
|
|
429
|
+
null,
|
|
430
|
+
React.createElement(
|
|
431
|
+
AgentModeProvider,
|
|
432
|
+
null,
|
|
433
|
+
React.createElement(
|
|
434
|
+
AgentProvider,
|
|
435
|
+
{
|
|
436
|
+
apiClient,
|
|
437
|
+
},
|
|
438
|
+
children,
|
|
439
|
+
),
|
|
440
|
+
),
|
|
441
|
+
),
|
|
442
|
+
),
|
|
443
|
+
),
|
|
444
|
+
),
|
|
445
|
+
),
|
|
446
|
+
),
|
|
447
|
+
),
|
|
448
|
+
);
|
|
449
|
+
};
|
|
450
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|