Elffuss BraidHub

kikocis/continue public

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