Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoedits e2e tests #6425

Merged
merged 25 commits into from
Dec 26, 2024
Merged

autoedits e2e tests #6425

merged 25 commits into from
Dec 26, 2024

Conversation

hitesh-1997
Copy link
Contributor

@hitesh-1997 hitesh-1997 commented Dec 19, 2024

Context

  1. End to end testing setup for the auto-edits
  2. https://playwright.dev/docs/test-snapshots is used to detect the differences in the rendering for the auto-edit diff view
  3. Closes https://linear.app/sourcegraph/issue/CODY-4570/implement-a-manual-trigger-command

Test plan

Added unit test and e2e tests

@hitesh-1997 hitesh-1997 marked this pull request as ready for review December 20, 2024 17:18
@hitesh-1997 hitesh-1997 force-pushed the hitesh/autoedit-e2e branch 2 times, most recently from ae45dbd to b3583e4 Compare December 20, 2024 19:12
@hitesh-1997 hitesh-1997 marked this pull request as draft December 24, 2024 11:37
@hitesh-1997 hitesh-1997 marked this pull request as ready for review December 25, 2024 17:00
@@ -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 () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's register this command in the registerAutoEdits function body.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}),
// 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using an approach similar to autocomplete? This would invoke the provideInlineCompletionItems method with appropriate parameters.

    public async manuallyTriggerCompletion(): Promise<void> {
        await vscode.commands.executeCommand('editor.action.inlineSuggest.hide')
        this.lastManualCompletionTimestamp = Date.now()
        await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice !!
This is much better, changed to the proposed implementation

*
* Currently these tests run only on macOS due to cross-platform rendering inconsistencies.
*
* Previous attempts and challenges encountered:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🤩

Comment on lines +1 to +2
"""
<<<<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep E2E tests closer to the real-world setup, we usually mock server responses in vscode/test/fixtures/mock-server.ts. Do you think we can do that for autoedits? If we rely on the /.api/completions/code endpoint for suggestions generation, it's already mocked in the mock server implementation.

Copy link
Contributor Author

@hitesh-1997 hitesh-1997 Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first approach I tried when implementing e2e tests. There are the painpoints in using the mock-server:

  1. The current mock-server has a hardcoded list of responses, which we check on case to case basis ior the mock list in case of ./api/completions/code endpoint, based on the content on the prompt. This setup is not very extensible if we want to add say 10-12 different image types from cody-chat-eval.
    I think the current setup has a downside that I doesn't do thought the adapter layer in e2e setup, but this gives us much more flexibility in adding new test cases and simply port over the examples from cody-chat-eval.
  2. Another pain-point would be that, the response returned from the server is a rewrite of <code_to_rewrite>, so in the hardcoded list above, we need to extract the logic either manually or we need to use the same setup i.e. mock-renderer, so in any case we would use the existing mock-renderer setup to get the response and extend the mock response list.

I think the current adapters are covered with extensive unit tests and should be fine to skip it in the e2e tests and follow the mock responses. Do you think we should continue with the setup we have in the PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the context! I agree; we can change it in a follow-up if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave this context as a comment in the test file for posterity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Added detailed comment in the test file

// Wait for the diff view to stabilize - required to reduce flakiness
await page.waitForTimeout(500)

await expect(page).toHaveScreenshot([snapshotPlatform, snapshotName], {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥✨

await expect(page).toHaveScreenshot([snapshotPlatform, snapshotName], {
maxDiffPixelRatio: 0.02,
maxDiffPixels: 1000,
clip: clip,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clip: clip,
clip,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thank you for implementing these tests.

hitesh-1997 added a commit that referenced this pull request Dec 26, 2024
## Context
1. Adding unit test case for the renderer manager
2. Build on top of #6425

## Test plan
Added unit test
@hitesh-1997 hitesh-1997 merged commit b06f903 into main Dec 26, 2024
20 of 21 checks passed
@hitesh-1997 hitesh-1997 deleted the hitesh/autoedit-e2e branch December 26, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants