-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chat: Fix "Ask Cody to Explain" (#3015)
## Description - Pass the correct arguments to the `cody.action.chat` command - Add type safety to avoid this mistake again closes #2970 ## Test plan 1. Try "Ask Cody to Explain" 2. Check there is no error <!-- Required. See https://sourcegraph.com/docs/dev/background-information/testing_principles. --> --------- Co-authored-by: Beatrix <[email protected]>
- Loading branch information
Showing
6 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as mockServer from '../fixtures/mock-server' | ||
|
||
import { sidebarExplorer, sidebarSignin } from './common' | ||
import { type DotcomUrlOverride, test as baseTest, assertEvents } from './helpers' | ||
|
||
const test = baseTest.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL }) | ||
|
||
test.beforeEach(() => { | ||
mockServer.resetLoggedEvents() | ||
}) | ||
|
||
const ERROR_DECORATION_SELECTOR = 'div.view-overlays[role="presentation"] div[class*="squiggly-error"]' | ||
|
||
test('code action: explain', async ({ page, sidebar }) => { | ||
// Sign into Cody | ||
await sidebarSignin(page, sidebar) | ||
|
||
// Open the Explorer view from the sidebar | ||
await sidebarExplorer(page).click() | ||
// Open the error.ts file from the tree view | ||
await page.getByRole('treeitem', { name: 'error.ts' }).locator('a').click() | ||
// Wait for error.ts to fully open | ||
await page.getByRole('tab', { name: 'error.ts' }).hover() | ||
|
||
// Remove the comment that suppresses the type error | ||
await page.getByText('// @ts-nocheck').click({ clickCount: 3 }) | ||
await page.keyboard.press('Backspace') | ||
|
||
// Activate the code action on the erred text | ||
const erredText = page.getByText('logNumber').nth(1) | ||
await page.waitForSelector(ERROR_DECORATION_SELECTOR) | ||
await erredText.click() | ||
await erredText.hover() | ||
await page.getByRole('button', { name: /Quick Fix/ }).click() | ||
// Get by text takes a very long time, it's faster to type and let the quick fix item be focused | ||
await page.keyboard.type('Explain') | ||
await page.keyboard.press('Enter') | ||
|
||
const expectedEvents = [ | ||
'CodyVSCodeExtension:chat-question:submitted', | ||
'CodyVSCodeExtension:chat-question:executed', | ||
] | ||
await assertEvents(mockServer.loggedEvents, expectedEvents) | ||
}) | ||
|
||
test('code action: fix', async ({ page, sidebar }) => { | ||
// Sign into Cody | ||
await sidebarSignin(page, sidebar) | ||
|
||
// Open the Explorer view from the sidebar | ||
await sidebarExplorer(page).click() | ||
// Open the error.ts file from the tree view | ||
await page.getByRole('treeitem', { name: 'error.ts' }).locator('a').click() | ||
// Wait for error.ts to fully open | ||
await page.getByRole('tab', { name: 'error.ts' }).hover() | ||
|
||
// Remove the comment that suppresses the type error | ||
await page.getByText('// @ts-nocheck').click({ clickCount: 3 }) | ||
await page.keyboard.press('Backspace') | ||
|
||
// Activate the code action on the erred text | ||
const erredText = page.getByText('logNumber').nth(1) | ||
await page.waitForSelector(ERROR_DECORATION_SELECTOR) | ||
await erredText.click() | ||
await erredText.hover() | ||
await page.getByRole('button', { name: /Quick Fix/ }).click() | ||
// Get by text takes a very long time, it's faster to type and let the quick fix item be focused | ||
await page.keyboard.type('Fix') | ||
await page.keyboard.press('Enter') | ||
|
||
const expectedEvents = [ | ||
'CodyVSCodeExtension:command:edit:executed', | ||
'CodyVSCodeExtension:fixupResponse:hasCode', | ||
'CodyVSCodeExtension:fixup:applied', | ||
] | ||
await assertEvents(mockServer.loggedEvents, expectedEvents) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @ts-nocheck | ||
const logNumber = (number: number) => { | ||
console.log('What a great number!', number) | ||
} | ||
|
||
const hasError = () => { | ||
const numbers = [1, 2, '3', 4, 5] | ||
numbers.forEach(logNumber) | ||
} |