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

feat: provide page snapshot as context to copilot #610

Merged
merged 6 commits into from
Feb 25, 2025

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Feb 11, 2025

Enables pageSnapshot: 'only-on-failure' for all test runs through the extension, and injects the page snapshot into the error message that Copilot uses to fix test failures.

Screenshot 2025-02-11 at 11 00 45

related to microsoft/playwright#34476

@Skn0tt Skn0tt requested a review from mxschmitt February 11, 2025 10:01
@Skn0tt Skn0tt self-assigned this Feb 11, 2025
@@ -551,6 +551,7 @@ export class TestModel extends DisposableBase {
connectWsEndpoint: showBrowser ? externalOptions.connectWsEndpoint : undefined,
updateSnapshots: noOverrideToUndefined(this._embedder.settingsModel.updateSnapshots.get()),
updateSourceMethod: noOverrideToUndefined(this._embedder.settingsModel.updateSourceMethod.get()),
pageSnapshot: 'only-on-failure',
Copy link
Member Author

@Skn0tt Skn0tt Feb 14, 2025

Choose a reason for hiding this comment

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

if we release with this as the default in @playwright/test, we can remove this override again.

src/extension.ts Outdated
@@ -520,7 +520,7 @@ export class Extension implements RunHooks {
}
},

onTestEnd: (test: reporterTypes.TestCase, result: reporterTypes.TestResult) => {
onTestEnd: async (test: reporterTypes.TestCase, result: reporterTypes.TestResult) => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are comfortable making onTestEnd async.

Copy link
Member Author

@Skn0tt Skn0tt Feb 14, 2025

Choose a reason for hiding this comment

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

Hmm, that's unfortunate. If we read the attachment from disk, that needs to be asynchronous. Do you think it'd be OK if we report only the test failures asynchronously?

Copy link
Member Author

Choose a reason for hiding this comment

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

how do you like 2dba9b5? Or should we make it an asynchronous inline function so the code stays colocated?

src/extension.ts Outdated
const snapshot = result.attachments.find(a => a.name === 'pageSnapshot');
if (snapshot && snapshot.path) {
const contents = await this._vscode.workspace.fs.readFile(this._vscode.Uri.file(snapshot.path));
aiContext = `### Page Snapshot at Failure\n${contents.toString()}`; // cannot use ``` codeblocks, vscode markdown does not support it
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need two \n to make a paragraph?

Copy link
Member Author

Choose a reason for hiding this comment

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

some renderers do, you're right. vscode didn't require it for some reason, but it still makes sense to make it two newlines in case vscode markdown rendering ever changes.

let aiContext: string | undefined;
const snapshot = result.attachments.find(a => a.name === 'pageSnapshot');
if (snapshot && snapshot.path) {
const contents = await this._vscode.workspace.fs.readFile(this._vscode.Uri.file(snapshot.path));
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether we should either limit the number of files we read here, or make pageSnapshot attachment content-based, not file-based.

Copy link
Member Author

Choose a reason for hiding this comment

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

It only ever reads one file per test, which should be fine.

If we make this content-based, there's a couple downsides:

  • it'll auto-print to terminal on some reporters, which is very noisy
  • it'll take up more memory for any consumer that holds on to old snapshots

Also, AI tools like Copilot won't be able to discover it from the file system. not yet sure if this a good or bad thing.

@Skn0tt Skn0tt merged commit fe881a4 into microsoft:main Feb 25, 2025
5 of 6 checks passed
Skn0tt added a commit that referenced this pull request Feb 28, 2025
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.

3 participants