Elffuss BraidHub

kikocis/continue public

b4db4cbf8943 · 20.6 KiBRawPermalink
1import { expect } from "chai";
2import {
3 By,
4 EditorView,
5 Key,
6 VSBrowser,
7 WebDriver,
8 WebElement,
9 WebView,
10 until,
11} from "vscode-extension-tester";
12
13import { GlobalActions } from "../actions/Global.actions";
14import { GUIActions } from "../actions/GUI.actions";
15import { DEFAULT_TIMEOUT } from "../constants";
16import { GUISelectors } from "../selectors/GUI.selectors";
17import { TestUtils } from "../TestUtils";
18
19describe("GUI Test", () => {
20 let view: WebView;
21 let driver: WebDriver;
22
23 before(async function () {
24 this.timeout(DEFAULT_TIMEOUT.XL);
25 // Uncomment this line for faster testing
26 await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
27 await GlobalActions.openTestWorkspace();
28 await GlobalActions.clearAllNotifications();
29 });
30
31 beforeEach(async function () {
32 this.timeout(DEFAULT_TIMEOUT.XL);
33
34 await GUIActions.toggleGui();
35
36 ({ view, driver } = await GUIActions.switchToReactIframe());
37 await GUIActions.selectModelFromDropdown(view, "TEST LLM");
38 });
39
40 afterEach(async function () {
41 this.timeout(DEFAULT_TIMEOUT.XL);
42
43 await view.switchBack();
44 await TestUtils.waitForSuccess(
45 async () => (await GUISelectors.getContinueExtensionBadge(view)).click(),
46 DEFAULT_TIMEOUT.XS,
47 );
48 await new EditorView().closeAllEditors();
49 });
50
51 describe("Onboarding", () => {
52 it.skip("should display correct panel description", async () => {
53 const description = await GUISelectors.getDescription(view);
54
55 expect(await description.getText()).has.string(
56 "Log in to quickly build your first custom AI code agent",
57 );
58 }).timeout(DEFAULT_TIMEOUT.XL);
59
60 // We no longer have a quick start button
61 it.skip(
62 "should display tutorial card after accepting onboarding quick start",
63 async () => {
64 // Get paragraph with text Best
65 const bestTab = await GUISelectors.getOnboardingTabButton(view, "Best");
66 await bestTab.click();
67
68 const anthropicInput = await TestUtils.waitForSuccess(
69 async () => await GUISelectors.getBestChatApiKeyInput(view),
70 );
71 anthropicInput.sendKeys("invalid_api_key");
72
73 const mistralInput =
74 await GUISelectors.getBestAutocompleteApiKeyInput(view);
75 mistralInput.sendKeys("invalid_api_key");
76
77 // Get button with text "Connect" and click it
78 const connectButton = await view.findWebElement(
79 By.xpath("//button[text()='Connect']"),
80 );
81 await connectButton.click();
82
83 await TestUtils.waitForSuccess(
84 async () => await GUISelectors.getTutorialCard(view),
85 );
86
87 // TODO validate that claude has been added to list
88
89 // Skip testing Quick Start because github auth opens external app and breaks test
90 // const quickStartButton = await view.findWebElement(
91 // By.xpath("//*[contains(text(), 'Get started using our API keys')]")
92 // );
93 // await quickStartButton.click();
94 // await view.switchBack();
95 // const allowButton = await TestUtils.waitForSuccess(
96 // async () => await driver.findElement(By.xpath(`//a[contains(text(), "Allow")]`))
97 // );
98 // await allowButton.click();
99 // ({ view, driver } = await GUIActions.switchToReactIframe());
100 },
101 ).timeout(DEFAULT_TIMEOUT.XL);
102 });
103
104 describe("Chat", () => {
105 it("Can submit message by pressing enter", async () => {
106 const [messageInput] = await GUISelectors.getMessageInputFields(view);
107 const messagePair = TestUtils.generateTestMessagePair();
108 await messageInput.sendKeys(messagePair.userMessage);
109 await messageInput.sendKeys(Key.ENTER);
110 await TestUtils.waitForSuccess(() =>
111 GUISelectors.getThreadMessageByText(view, messagePair.llmResponse),
112 );
113 });
114
115 it("Can submit message by button click", async () => {
116 const [messageInput] = await GUISelectors.getMessageInputFields(view);
117 const messagePair = TestUtils.generateTestMessagePair();
118 await messageInput.sendKeys(messagePair.userMessage);
119 (await GUISelectors.getSubmitInputButton(view)).click();
120 await TestUtils.waitForSuccess(() =>
121 GUISelectors.getThreadMessageByText(view, messagePair.llmResponse),
122 );
123 });
124
125 it("Can delete messages", async () => {
126 const { userMessage: userMessage0, llmResponse: llmResponse0 } =
127 TestUtils.generateTestMessagePair(0);
128 await GUIActions.sendMessage({
129 view,
130 message: userMessage0,
131 inputFieldIndex: 0,
132 });
133 await TestUtils.waitForSuccess(() =>
134 GUISelectors.getThreadMessageByText(view, llmResponse0),
135 );
136
137 const { userMessage: userMessage1, llmResponse: llmResponse1 } =
138 TestUtils.generateTestMessagePair(1);
139 await GUIActions.sendMessage({
140 view,
141 message: userMessage1,
142 inputFieldIndex: 1,
143 });
144 await TestUtils.waitForSuccess(() =>
145 GUISelectors.getThreadMessageByText(view, llmResponse1),
146 );
147
148 const { userMessage: userMessage2, llmResponse: llmResponse2 } =
149 TestUtils.generateTestMessagePair(2);
150 await GUIActions.sendMessage({
151 view,
152 message: userMessage2,
153 inputFieldIndex: 2,
154 });
155 await TestUtils.waitForSuccess(() =>
156 GUISelectors.getThreadMessageByText(view, llmResponse2),
157 );
158
159 // Delete the first assistant response (index 1) - this deletes both user msg 0 and assistant response 0
160 await (await GUISelectors.getNthMessageDeleteButton(view, 1)).click();
161 await TestUtils.expectNoElement(() =>
162 GUISelectors.getThreadMessageByText(view, llmResponse0),
163 );
164
165 // Delete the second assistant response (now at index 1) - this deletes both user msg 1 and assistant response 1
166 await (await GUISelectors.getNthMessageDeleteButton(view, 1)).click();
167 await TestUtils.expectNoElement(() =>
168 GUISelectors.getThreadMessageByText(view, llmResponse1),
169 );
170
171 // Delete the third assistant response (now at index 1) - this deletes both user msg 2 and assistant response 2
172 await (await GUISelectors.getNthMessageDeleteButton(view, 1)).click();
173 await TestUtils.expectNoElement(() =>
174 GUISelectors.getThreadMessageByText(view, llmResponse2),
175 );
176 }).timeout(DEFAULT_TIMEOUT.XL);
177
178 it("Can edit messages", async () => {
179 const { userMessage: userMessage0, llmResponse: llmResponse0 } =
180 TestUtils.generateTestMessagePair(0);
181 await GUIActions.sendMessage({
182 view,
183 message: userMessage0,
184 inputFieldIndex: 0,
185 });
186 await TestUtils.waitForSuccess(() =>
187 GUISelectors.getThreadMessageByText(view, llmResponse0),
188 );
189
190 const { userMessage: userMessage1, llmResponse: llmResponse1 } =
191 TestUtils.generateTestMessagePair(1);
192 await GUIActions.sendMessage({
193 view,
194 message: userMessage1,
195 inputFieldIndex: 1,
196 });
197 await TestUtils.waitForSuccess(() =>
198 GUISelectors.getThreadMessageByText(view, llmResponse1),
199 );
200
201 const { userMessage: userMessage2, llmResponse: llmResponse2 } =
202 TestUtils.generateTestMessagePair(2);
203 await GUIActions.sendMessage({
204 view,
205 message: userMessage2,
206 inputFieldIndex: 2,
207 });
208 await TestUtils.waitForSuccess(() =>
209 GUISelectors.getThreadMessageByText(view, llmResponse2),
210 );
211
212 const secondInputField = await GUISelectors.getMessageInputFieldAtIndex(
213 view,
214 1,
215 );
216 await secondInputField.clear();
217
218 const { userMessage: userMessage3, llmResponse: llmResponse3 } =
219 TestUtils.generateTestMessagePair(3);
220
221 await GUIActions.sendMessage({
222 view,
223 message: userMessage3,
224 inputFieldIndex: 1,
225 });
226 await GUISelectors.getThreadMessageByText(view, llmResponse0);
227
228 await TestUtils.waitForSuccess(() =>
229 GUISelectors.getThreadMessageByText(view, llmResponse3),
230 );
231 await Promise.all([
232 TestUtils.expectNoElement(() =>
233 GUISelectors.getThreadMessageByText(view, llmResponse1),
234 ),
235 TestUtils.expectNoElement(() =>
236 GUISelectors.getThreadMessageByText(view, llmResponse2),
237 ),
238 ]);
239 }).timeout(DEFAULT_TIMEOUT.XL);
240 });
241
242 describe("Agent with tools", () => {
243 beforeEach(async () => {
244 await GUIActions.selectModelFromDropdown(view, "TOOL MOCK LLM");
245 await GUIActions.selectModeFromDropdown(view, "Agent");
246 });
247
248 it("should display rules peek and show rule details", async () => {
249 // Send a message to trigger the model response
250 const [messageInput] = await GUISelectors.getMessageInputFields(view);
251 await messageInput.sendKeys("Hello");
252 await messageInput.sendKeys(Key.ENTER);
253
254 // Wait for the response to appear
255 await TestUtils.waitForSuccess(() =>
256 GUISelectors.getThreadMessageByText(view, "I'm going to call a tool:"),
257 );
258
259 // Verify that "1 rule" text appears
260 const rulesPeek = await TestUtils.waitForSuccess(() =>
261 GUISelectors.getRulesPeek(view),
262 );
263 const rulesPeekText = await rulesPeek.getText();
264 expect(rulesPeekText).to.include("1 rule");
265
266 // Click on the rules peek to expand it
267 await rulesPeek.click();
268
269 // Wait for the rule details to appear
270 const ruleItem = await TestUtils.waitForSuccess(() =>
271 GUISelectors.getFirstRulesPeekItem(view),
272 );
273
274 await TestUtils.waitForSuccess(async () => {
275 const text = await ruleItem.getText();
276 if (!text || text.trim() === "") {
277 throw new Error("Rule item text is empty");
278 }
279 return ruleItem;
280 });
281
282 // Verify the rule content
283 const ruleItemText = await ruleItem.getText();
284 expect(ruleItemText).to.include("Agent rule");
285 expect(ruleItemText).to.include("Always applied");
286 expect(ruleItemText).to.include("TEST_SYS_MSG");
287 }).timeout(DEFAULT_TIMEOUT.MD);
288
289 it("should render tool call", async () => {
290 const [messageInput] = await GUISelectors.getMessageInputFields(view);
291 await messageInput.sendKeys("Hello");
292 await messageInput.sendKeys(Key.ENTER);
293
294 const statusMessage = await TestUtils.waitForSuccess(
295 () => GUISelectors.getToolCallStatusMessage(view), // Defined in extensions/vscode/e2e/test-continue/config.json's TOOL MOCK LLM that we are calling the exact search tool
296 DEFAULT_TIMEOUT.SM,
297 );
298
299 expect(await statusMessage.getText()).contain(
300 "Continue viewed the git diff",
301 );
302 }).timeout(DEFAULT_TIMEOUT.MD * 100);
303
304 it("should call tool after approval", async () => {
305 await GUIActions.toggleToolPolicy(view, "view_diff", 2);
306
307 const [messageInput] = await GUISelectors.getMessageInputFields(view);
308 await messageInput.sendKeys("Hello");
309 await messageInput.sendKeys(Key.ENTER);
310
311 const acceptToolCallButton = await TestUtils.waitForSuccess(() =>
312 GUISelectors.getAcceptToolCallButton(view),
313 );
314 await acceptToolCallButton.click();
315
316 const statusMessage = await TestUtils.waitForSuccess(
317 () => GUISelectors.getToolCallStatusMessage(view), // Defined in extensions/vscode/e2e/test-continue/config.json's TOOL MOCK LLM that we are calling the exact search tool
318 DEFAULT_TIMEOUT.SM,
319 );
320
321 const text = await statusMessage.getText();
322 expect(text).contain("the git diff");
323 }).timeout(DEFAULT_TIMEOUT.XL);
324
325 it("should cancel tool", async () => {
326 await GUIActions.toggleToolPolicy(view, "view_diff", 2);
327
328 const [messageInput] = await GUISelectors.getMessageInputFields(view);
329 await messageInput.sendKeys("Hello");
330 await messageInput.sendKeys(Key.ENTER);
331
332 const cancelToolCallButton = await TestUtils.waitForSuccess(() =>
333 GUISelectors.getRejectToolCallButton(view),
334 );
335 await cancelToolCallButton.click();
336
337 const statusMessage = await TestUtils.waitForSuccess(
338 () => GUISelectors.getToolCallStatusMessage(view), // Defined in extensions/vscode/e2e/test-continue/config.json's TOOL MOCK LLM that we are calling the exact search tool
339 DEFAULT_TIMEOUT.SM,
340 );
341
342 const text = await statusMessage.getText();
343 expect(text).contain("Continue tried to view the git diff");
344 }).timeout(DEFAULT_TIMEOUT.XL);
345 });
346
347 describe("Context providers", () => {
348 it("should successfully use the terminal context provider", async () => {
349 await GUIActions.selectModelFromDropdown(view, "LAST MESSAGE MOCK LLM");
350
351 // Enter just the context provider in the input and send
352 const [messageInput] = await GUISelectors.getMessageInputFields(view);
353 await messageInput.sendKeys("@");
354 await messageInput.sendKeys("terminal");
355 await messageInput.sendKeys(Key.ENTER);
356 await messageInput.sendKeys(Key.ENTER);
357
358 // Check that the contents match what we expect (repeated back by the mock LLM)
359 await TestUtils.waitForSuccess(() => {
360 return GUISelectors.getThreadMessageByText(
361 view,
362 "Current terminal contents:",
363 );
364 });
365 }).timeout(DEFAULT_TIMEOUT.MD);
366 });
367
368 describe("should repeat back the system message", () => {
369 it("should repeat back the system message", async () => {
370 await GUIActions.selectModeFromDropdown(view, "Chat");
371 await GUIActions.selectModelFromDropdown(view, "SYSTEM MESSAGE MOCK LLM");
372 const [messageInput] = await GUISelectors.getMessageInputFields(view);
373 await messageInput.sendKeys("Hello");
374 await messageInput.sendKeys(Key.ENTER);
375 await TestUtils.waitForSuccess(() =>
376 GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG"),
377 );
378 }).timeout(DEFAULT_TIMEOUT.XL * 1000);
379 });
380
381 describe("Chat Paths", () => {
382 it("Send many messages → chat auto scrolls → go to history → open previous chat → it is scrolled to the bottom", async () => {
383 for (let i = 0; i <= 20; i++) {
384 const { userMessage, llmResponse } =
385 TestUtils.generateTestMessagePair(i);
386 await GUIActions.sendMessage({
387 view,
388 message: userMessage,
389 inputFieldIndex: i,
390 });
391 const response = await TestUtils.waitForSuccess(() =>
392 GUISelectors.getThreadMessageByText(view, llmResponse),
393 );
394
395 const viewportHeight = await driver.executeScript(
396 "return window.innerHeight",
397 );
398
399 const isInViewport = await driver.executeScript(
400 `
401 const rect = arguments[0].getBoundingClientRect();
402 return (
403 rect.top >= 0 &&
404 rect.bottom <= ${viewportHeight}
405 );
406 `,
407 response,
408 );
409
410 expect(isInViewport).to.eq(true);
411 }
412
413 await view.switchBack();
414
415 await (await GUISelectors.getHistoryNavButton(view)).click();
416 await GUIActions.switchToReactIframe();
417 TestUtils.waitForSuccess(async () => {
418 await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
419 });
420
421 const { llmResponse } = TestUtils.generateTestMessagePair(20);
422 const response = await TestUtils.waitForSuccess(() =>
423 GUISelectors.getThreadMessageByText(view, llmResponse),
424 );
425
426 const viewportHeight = await driver.executeScript(
427 "return window.innerHeight",
428 );
429
430 const isInViewport = await driver.executeScript(
431 `
432 const rect = arguments[0].getBoundingClientRect();
433 return (
434 rect.top >= 0 &&
435 rect.bottom <= ${viewportHeight}
436 );
437 `,
438 response,
439 );
440
441 expect(isInViewport).to.eq(true);
442 }).timeout(DEFAULT_TIMEOUT.XL * 1000);
443
444 it("Open chat and send message → press arrow up and arrow down to cycle through messages → submit another message → press arrow up and arrow down to cycle through messages", async () => {
445 await GUIActions.sendMessage({
446 view,
447 message: "MESSAGE 1",
448 inputFieldIndex: 0,
449 });
450
451 const input1 = await TestUtils.waitForSuccess(async () => {
452 return GUISelectors.getMessageInputFieldAtIndex(view, 1);
453 });
454 expect(await input1.getText()).to.equal("");
455
456 await input1.sendKeys(Key.ARROW_UP);
457 await driver.wait(
458 until.elementTextIs(input1, "MESSAGE 1"),
459 DEFAULT_TIMEOUT.SM,
460 );
461
462 await input1.sendKeys(Key.ARROW_DOWN); // First press - bring caret to the end of the message
463 await input1.sendKeys(Key.ARROW_DOWN); // Second press - trigger message change
464 await driver.wait(until.elementTextIs(input1, ""), DEFAULT_TIMEOUT.SM);
465
466 await GUIActions.sendMessage({
467 view,
468 message: "MESSAGE 2",
469 inputFieldIndex: 1,
470 });
471
472 const input2 = await TestUtils.waitForSuccess(async () => {
473 return GUISelectors.getMessageInputFieldAtIndex(view, 2);
474 });
475 expect(await input2.getText()).to.equal("");
476
477 await input2.sendKeys(Key.ARROW_UP);
478 await driver.wait(
479 until.elementTextIs(input2, "MESSAGE 2"),
480 DEFAULT_TIMEOUT.SM,
481 );
482
483 await input2.sendKeys(Key.ARROW_UP);
484 await driver.wait(
485 until.elementTextIs(input2, "MESSAGE 1"),
486 DEFAULT_TIMEOUT.SM,
487 );
488
489 await input2.sendKeys(Key.ARROW_DOWN); // First press - bring caret to the end of the message
490 await input2.sendKeys(Key.ARROW_DOWN); // Second press - trigger message change
491 await driver.wait(
492 until.elementTextIs(input2, "MESSAGE 2"),
493 DEFAULT_TIMEOUT.SM,
494 );
495
496 await input2.sendKeys(Key.ARROW_DOWN);
497 await driver.wait(until.elementTextIs(input2, ""), DEFAULT_TIMEOUT.SM);
498 }).timeout(DEFAULT_TIMEOUT.XL);
499
500 it("Open chat and type → open history → press new session button → chat opens, empty and in focus", async () => {
501 const originalTextInput = await GUISelectors.getMessageInputFieldAtIndex(
502 view,
503 0,
504 );
505 await originalTextInput.click();
506 await originalTextInput.sendKeys("Hello");
507 expect(await originalTextInput.getText()).to.equal("Hello");
508
509 await view.switchBack();
510
511 await (await GUISelectors.getHistoryNavButton(view)).click();
512 await GUIActions.switchToReactIframe();
513
514 await view.switchBack();
515 await (await GUISelectors.getNewSessionNavButton(view)).click();
516 await GUIActions.switchToReactIframe();
517
518 const newTextInput = await TestUtils.waitForSuccess(() =>
519 GUISelectors.getMessageInputFieldAtIndex(view, 0),
520 );
521 const activeElement: WebElement = await driver.switchTo().activeElement();
522 const newTextInputHtml = await newTextInput.getAttribute("outerHTML");
523 const activeElementHtml = await activeElement.getAttribute("outerHTML");
524 expect(newTextInputHtml).to.equal(activeElementHtml);
525
526 const textInputValue = await newTextInput.getText();
527 expect(textInputValue).to.equal("");
528 }).timeout(DEFAULT_TIMEOUT.XL);
529
530 it("chat → history → chat", async () => {
531 const messagePair1 = TestUtils.generateTestMessagePair(1);
532 await GUIActions.sendMessage({
533 view,
534 message: messagePair1.userMessage,
535 inputFieldIndex: 0,
536 });
537 await TestUtils.waitForSuccess(() =>
538 GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse),
539 );
540
541 const messagePair2 = TestUtils.generateTestMessagePair(2);
542 await GUIActions.sendMessage({
543 view,
544 message: messagePair2.userMessage,
545 inputFieldIndex: 1,
546 });
547 await TestUtils.waitForSuccess(() =>
548 GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse),
549 );
550
551 /**
552 * SWITCHING BACK AND FORTH
553 * We are switching back and forth here because the history is broken.
554 * It only updates once a another chat is opened, so we need to open a
555 * different chat first.
556 */
557 await view.switchBack();
558 await (await GUISelectors.getHistoryNavButton(view)).click();
559 await GUIActions.switchToReactIframe();
560
561 await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
562
563 await view.switchBack();
564 await (await GUISelectors.getHistoryNavButton(view)).click();
565 /**
566 * END OF SWITCHING BACK AND FORTH
567 */
568
569 await GUIActions.switchToReactIframe();
570 await (await GUISelectors.getNthHistoryTableRow(view, 0)).click();
571
572 await GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse);
573 await GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse);
574
575 const messagePair3 = TestUtils.generateTestMessagePair(3);
576 await GUIActions.sendMessage({
577 view,
578 message: messagePair3.userMessage,
579 inputFieldIndex: 2,
580 });
581 await TestUtils.waitForSuccess(() =>
582 GUISelectors.getThreadMessageByText(view, messagePair3.llmResponse),
583 );
584 }).timeout(DEFAULT_TIMEOUT.XL);
585 });
586});