From df4207fd93cd38005329ea9b6b93b0d3e52e239d Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Wed, 15 Jan 2025 14:34:45 +0100 Subject: [PATCH 1/5] Fix missing current repo context in jetbrains --- vscode/src/repository/remoteRepos.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/vscode/src/repository/remoteRepos.ts b/vscode/src/repository/remoteRepos.ts index 9c5c64f477be..aa2408366142 100644 --- a/vscode/src/repository/remoteRepos.ts +++ b/vscode/src/repository/remoteRepos.ts @@ -50,13 +50,6 @@ export const remoteReposForAllWorkspaceFolders: Observable< return Observable.of([]) } - // NOTE(sqs): This check is to preserve prior behavior where agent/JetBrains did not use - // the old WorkspaceReposMonitor. We should make it so they can use it. See - // https://linear.app/sourcegraph/issue/CODY-3906/agent-allow-use-of-existing-fallback-that-looks-at-gitconfig-to-get. - if (!vscodeGitAPI) { - return Observable.of([]) - } - return combineLatest( ...workspaceFolders.map(folder => repoNameResolver.getRepoNamesContainingUri(folder.uri)) ).pipe( From 3a4f2a3371832848eb398195ec453201d5978b8d Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Wed, 15 Jan 2025 16:08:31 +0100 Subject: [PATCH 2/5] Add fallback if remote repo context is not found --- vscode/src/chat/initialContext.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vscode/src/chat/initialContext.ts b/vscode/src/chat/initialContext.ts index 91dca4aba224..8c60b7bcc790 100644 --- a/vscode/src/chat/initialContext.ts +++ b/vscode/src/chat/initialContext.ts @@ -228,7 +228,9 @@ export function getCorpusContextItemsForEditorState(): Observable< icon: 'folder', }) } - } else { + } + + if (items.length === 0) { // TODO(sqs): Support multi-root. Right now, this only supports the 1st workspace root. const workspaceFolder = vscode.workspace.workspaceFolders?.at(0) if (workspaceFolder) { From ec31d23e066e362df53c56cf857c42c6210fa1ca Mon Sep 17 00:00:00 2001 From: jamesmcnamara Date: Wed, 15 Jan 2025 11:48:53 -0800 Subject: [PATCH 3/5] fixed e2e test --- vscode/test/e2e/chat-atFile.test.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/vscode/test/e2e/chat-atFile.test.ts b/vscode/test/e2e/chat-atFile.test.ts index bf03aabab755..1c7fa496bf79 100644 --- a/vscode/test/e2e/chat-atFile.test.ts +++ b/vscode/test/e2e/chat-atFile.test.ts @@ -358,12 +358,26 @@ test.extend({ await selectLineRangeInEditorTab(page, 2, 5) const [, lastChatInput] = await createEmptyChatPanel(page) - await expect(chatInputMentions(lastChatInput)).toHaveText(['buzz.ts', 'buzz.ts:2-5'], { - timeout: 2_000, - }) + await expect(chatInputMentions(lastChatInput)).toContainText( + [ + 'buzz.ts', + 'buzz.ts:2-5', + // The repo context should appear in the chat, but depending + // on if you are running it locally or in CI, it may appear as + // sourcegraph/cody or workspace + /workspace|sourcegraph.cody/, + ], + { + timeout: 2_000, + } + ) await lastChatInput.press('x') await selectLineRangeInEditorTab(page, 7, 10) await executeCommandInPalette(page, 'Cody: Add Selection to Cody Chat') - await expect(chatInputMentions(lastChatInput)).toHaveText(['buzz.ts', 'buzz.ts:2-5', 'buzz.ts:7-10']) + await expect(chatInputMentions(lastChatInput)).toContainText([ + 'buzz.ts', + 'buzz.ts:2-5', + 'buzz.ts:7-10', + ]) }) From 299b542784c2fde60467aff0dd2e92cf4fdbb08b Mon Sep 17 00:00:00 2001 From: jamesmcnamara Date: Wed, 15 Jan 2025 12:40:15 -0800 Subject: [PATCH 4/5] fixed e2e test (again) --- vscode/test/e2e/chat-atFile.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode/test/e2e/chat-atFile.test.ts b/vscode/test/e2e/chat-atFile.test.ts index 1c7fa496bf79..9673da458706 100644 --- a/vscode/test/e2e/chat-atFile.test.ts +++ b/vscode/test/e2e/chat-atFile.test.ts @@ -326,8 +326,8 @@ test.extend({ await chatInput.pressSequentially('fizzb', { delay: 10 }) await expect(chatPanelFrame.getByRole('option', { name: 'fizzbuzz()' })).toBeVisible() await chatPanelFrame.getByRole('option', { name: 'fizzbuzz()' }).click() - await expect(chatInput).toHaveText('buzz.ts fizzbuzz() ') - await expect(chatInputMentions(chatInput)).toHaveText(['buzz.ts', 'fizzbuzz()']) + await expect(chatInput).toHaveText(/buzz.ts (workspace|sourcegraph.cody) fizzbuzz\(\) /) + await expect(chatInputMentions(chatInput)).toContainText(['buzz.ts', 'fizzbuzz()']) // Submit the message await chatInput.press('Enter') From e2114b7a2218c45d111b1f6e0aa46115ee40e0a2 Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Thu, 16 Jan 2025 10:48:18 +0100 Subject: [PATCH 5/5] Make tests more strict, bump timeout --- vscode/test/e2e/chat-atFile.test.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vscode/test/e2e/chat-atFile.test.ts b/vscode/test/e2e/chat-atFile.test.ts index 9673da458706..bd100ee2af0b 100644 --- a/vscode/test/e2e/chat-atFile.test.ts +++ b/vscode/test/e2e/chat-atFile.test.ts @@ -8,6 +8,7 @@ import { focusChatInputAtEnd, getContextCell, mentionMenu, + mentionMenuItems, openContextCell, openFileInEditorTab, openMentionsForProvider, @@ -31,7 +32,7 @@ test.extend({ 'cody.chat-question:executed', 'cody.chatResponse:noCode', ], -})('@-mention file in chat', async ({ page, sidebar }) => { +})('@-mention file in chat', async ({ page, sidebar, workspaceDirectory }) => { // This test requires that the window be focused in the OS window manager because it deals with // focus. await page.bringToFront() @@ -56,11 +57,10 @@ test.extend({ // We should only match the relative visible path, not parts of the full path outside of the workspace. // Eg. searching for "source" should not find all files if the project is inside `C:\Source`. - // TODO(dantup): After https://github.com/sourcegraph/cody/pull/2235 lands, add workspacedirectory to the test - // and assert that it contains `fixtures` to ensure this check isn't passing because the fixture folder no - // longer matches. + // Instead it should find Current Repository item. + await expect(workspaceDirectory).toContain('fixtures') await chatInput.fill('@fixtures') // fixture is in the test project folder name, but not in the relative paths. - await expect(atMentionMenuMessage(chatPanelFrame, 'No files found')).toBeVisible() + await expect(mentionMenuItems(chatPanelFrame)).toHaveText([/^Current Repository/]) // Includes dotfiles after just "." await chatInput.fill('@.') @@ -358,7 +358,7 @@ test.extend({ await selectLineRangeInEditorTab(page, 2, 5) const [, lastChatInput] = await createEmptyChatPanel(page) - await expect(chatInputMentions(lastChatInput)).toContainText( + await expect(chatInputMentions(lastChatInput)).toHaveText( [ 'buzz.ts', 'buzz.ts:2-5', @@ -368,16 +368,17 @@ test.extend({ /workspace|sourcegraph.cody/, ], { - timeout: 2_000, + timeout: 3_000, } ) await lastChatInput.press('x') await selectLineRangeInEditorTab(page, 7, 10) await executeCommandInPalette(page, 'Cody: Add Selection to Cody Chat') - await expect(chatInputMentions(lastChatInput)).toContainText([ + await expect(chatInputMentions(lastChatInput)).toHaveText([ 'buzz.ts', 'buzz.ts:2-5', + /workspace|sourcegraph.cody/, 'buzz.ts:7-10', ]) })