Skip to content

Commit

Permalink
autoedits e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hitesh-1997 committed Dec 20, 2024
1 parent 9a648eb commit ae45dbd
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 60 deletions.
10 changes: 5 additions & 5 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
"command": "cody.command.insertCodeToNewFile",
"title": "Save Code to New File...",
"enablement": "cody.activated"
},
{
"command": "cody.command.autoedits-manual-trigger",
"title": "Autoedits Manual Trigger",
"enablement": "cody.activated && config.cody.experimental.autoedits.enabled"
}
],
"keybindings": [
Expand Down Expand Up @@ -759,11 +764,6 @@
"key": "escape",
"when": "editorTextFocus && cody.activated && cody.supersuggest.active"
},
{
"command": "cody.experimental.suggest",
"key": "ctrl+shift+enter",
"when": "cody.activated && config.cody.experimental.autoedits.enabled"
},
{
"command": "cody.supersuggest.testExample",
"key": "ctrl+alt+enter",
Expand Down
19 changes: 17 additions & 2 deletions vscode/src/autoedits/autoedits-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { AutoEditsDefaultRendererManager, type AutoEditsRendererManager } from '
import {
extractAutoEditResponseFromCurrentDocumentCommentTemplate,
shrinkReplacerTextToCodeToReplaceRange,
} from './renderer/renderer-testing'
} from './renderer/mock-renderer'
// import { shrinkPredictionUntilSuffix } from './shrink-prediction'

const AUTOEDITS_CONTEXT_STRATEGY = 'auto-edits'
Expand Down Expand Up @@ -84,6 +84,10 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
private readonly promptProvider: AutoeditsUserPromptStrategy = new ShortTermPromptStrategy()
private readonly filterPrediction = new FilterPredictionBasedOnRecentEdits()

/**
* Flag to enable mock responses from the current document template.
* This is also used in e2e tests to provide deterministic responses.
*/
private isMockResponseFromCurrentDocumentTemplateEnabled = vscode.workspace
.getConfiguration()
.get<boolean>('cody.experimental.autoedits.use-mock-responses', false)
Expand Down Expand Up @@ -120,6 +124,14 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v
vscode.window.onDidChangeTextEditorSelection(this.onSelectionChangeDebounced),
vscode.workspace.onDidChangeTextDocument(event => {
this.onDidChangeTextDocument(event)
}),
// Command used to trigger autoedits manually via command palette and is used by e2e test
vscode.commands.registerCommand('cody.command.autoedits-manual-trigger', async () => {
this.showAutoEdit(
vscode.window.activeTextEditor!.document!,
vscode.window.activeTextEditor!.selection.active,
new AbortController().signal
)
})
)
}
Expand Down Expand Up @@ -278,7 +290,10 @@ export class AutoeditsProvider implements vscode.InlineCompletionItemProvider, v

let response: string | undefined = undefined
if (this.isMockResponseFromCurrentDocumentTemplateEnabled) {
const responseMetadata = extractAutoEditResponseFromCurrentDocumentCommentTemplate()
const responseMetadata = extractAutoEditResponseFromCurrentDocumentCommentTemplate(
options.document,
options.position
)

if (responseMetadata) {
response = shrinkReplacerTextToCodeToReplaceRange(responseMetadata, codeToReplace)
Expand Down
27 changes: 27 additions & 0 deletions vscode/src/autoedits/prompt/test-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dedent from 'dedent'
import { getCurrentDocContext } from '../../completions/get-current-doc-context'
import { documentAndPosition } from '../../completions/test-helpers'
import { type CodeToReplaceData, getCurrentFilePromptComponents } from '../prompt/prompt-utils'

export function createCodeToReplaceDataForTest(
code: TemplateStringsArray,
...values: unknown[]
): CodeToReplaceData {
const { document, position } = documentAndPosition(dedent(code, values))
const docContext = getCurrentDocContext({
document,
position,
maxPrefixLength: 100,
maxSuffixLength: 100,
})

return getCurrentFilePromptComponents({
docContext,
position,
document,
maxPrefixLinesInArea: 2,
maxSuffixLinesInArea: 2,
codeToRewritePrefixLines: 1,
codeToRewriteSuffixLines: 1,
}).codeToReplace
}
Loading

0 comments on commit ae45dbd

Please sign in to comment.