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(uninstall): Delete cached credentials during re-install (CODY-1043) #5819

Merged
merged 21 commits into from
Oct 16, 2024

Conversation

jamesmcnamara
Copy link
Contributor

@jamesmcnamara jamesmcnamara commented Oct 5, 2024

This is the VSCode half of CODY-1043.

Unfortunately, we don't have access to any VSCode APIs during the uninstall script; it is just a raw node process that VSCode kicks off the next time VSCode is started after an uninstall (could be an arbitrary time after uninstalling). So the way we collected telemetry was to create files in the deactivation subroutine (which is run anytime the extension is stopped, i.e. when it is deactivated, VSCode is closed, the extension is upgraded or uninstalled) that stored all the config needed to boot telemetry and then we read those resources in the uninstall script.

Here we do basically the opposite. The uninstall script is run only when the user explicitly uninstalls the extension and closes and re-opens VSCode (importantly it does not run when the extension is upgraded). We create a marker file in the uninstallation process which we can check when the extension is initializing. When present, we delete the file and perform any cleanup from the previous installation (currently just deleting auth credentials and previous endpoints).

This also fixes some existing errors in the uninstall script (it isn't working today because the client capabilities aren't initialized), adds a check to the bundling step for the uninstaller that no vscode dependencies are transitively included (similar to the vscode-shim) and adds a re-install telemetry event.

Test plan

Finally added an E2E test for the uninstall flow. It took forever, but seeing as how it was broken for gosh knows how long and we didn't know indicates that it was necessary.

To manually test it:

  1. Build the VSIX bundle with pnpm -C vscode _build:vsix_for_test
  2. Start up VSCode and uninstall the Cody extension (or use the alternate editor, for instance I use VSCode Insiders day to day so I do this testing in VSCode).
  3. From the command palette run "Extension: Install from VSIX" and select vscode/dist/cody.e2e.vsix. Log into Cody normally.
  4. Close and reopen code. Verify that your credentials are cached.
  5. Uninstall Cody (click on the gear icon on the extension view and select uninstall).
  6. Fully close Code (not just the open window but the whole process)
  7. Re-open Code and re-install Cody from VSIX.
  8. Verify that credentials are cleared and you are presented with a fresh login screen.

Changelog

deletes auth credentials and endpoint history when the extension is reinstalled

@jamesmcnamara jamesmcnamara requested a review from a team October 5, 2024 01:19
pkukielka pushed a commit to sourcegraph/jetbrains that referenced this pull request Oct 15, 2024
)

This is the JetBrains half of the
[CODY-1043](https://linear.app/sourcegraph/issue/CODY-1043/bug-account-credentials-are-cached-between-installs),
the VSC half of it is in [this
PR](sourcegraph/cody#5819).

For VSCode I was able to write an E2E as there are electron & VSCode
test utilities for opening / closing instances of VSC and installing /
uninstalling plugins.

Does anyone know if we have similar utilities that we could use to write
a test for this behavior in JB?

The good news is that JB actually has proper APIs for this hook so the
complexity is much lower here.

## Test plan
I manually tested this by running `CODY_DIR='<my local cody>' ./gradlew
-PforceAgentBuild=true buildPlugin` and then opening the plugins menu
and installing a plugin from disk.

![image](https://github.com/user-attachments/assets/0b0c7482-9dce-4ce5-8f80-07b60857e1d9)

I logged in and then uninstalled from the same menu. After reinstalling,
it takes me back to the login screen and all previous endpoints are
cleared. When I log back into the same account I see my chat history is
removed.
Co-authored-by: Beatrix <68532117+abeatrix@users.noreply.github.com>
Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

I didn't test the uninstall step since we now have a test that covers it, but i've started the build locally and everything works as expected!

@jamesmcnamara jamesmcnamara merged commit e9a460e into main Oct 16, 2024
20 checks passed
@jamesmcnamara jamesmcnamara deleted the jsm/cody-1043-delete-creds-after-uninstall branch October 16, 2024 00:28
RXminuS pushed a commit that referenced this pull request Oct 16, 2024
…) (#5819)

This is the VSCode half of
[CODY-1043](https://linear.app/sourcegraph/issue/CODY-1043/bug-account-credentials-are-cached-between-installs).

Unfortunately, we don't have access to any VSCode APIs during the
uninstall script; it is just a raw node process that VSCode kicks off
the next time VSCode is started after an uninstall (could be an
arbitrary time after uninstalling). So the way we collected telemetry
was to create files in the deactivation subroutine (which is run anytime
the extension is stopped, i.e. when it is deactivated, VSCode is closed,
the extension is upgraded or uninstalled) that stored all the config
needed to boot telemetry and then we read those resources in the
uninstall script.

Here we do basically the opposite. The uninstall script is run only when
the user explicitly uninstalls the extension and closes and re-opens
VSCode (importantly it does not run when the extension is upgraded). We
create a marker file in the uninstallation process which we can check
when the extension is initializing. When present, we delete the file and
perform any cleanup from the previous installation (currently just
deleting auth credentials and previous endpoints).

This also fixes some existing errors in the uninstall script (it isn't
working today because the client capabilities aren't initialized), adds
a check to the bundling step for the uninstaller that no vscode
dependencies are transitively included (similar to the vscode-shim) and
adds a re-install telemetry event.

Finally added an E2E test for the uninstall flow. It took forever, but
seeing as how it was broken for gosh knows how long and we didn't know
indicates that it was necessary.

To manually test it:
1. Build the VSIX bundle with `pnpm -C vscode _build:vsix_for_test`
2. Start up VSCode and uninstall the Cody extension (or use the
alternate editor, for instance I use VSCode Insiders day to day so I do
this testing in VSCode).
3. From the command palette run "Extension: Install from VSIX" and
select `vscode/dist/cody.e2e.vsix`. Log into Cody normally.
4. Close and reopen code. Verify that your credentials are cached.
5. Uninstall Cody (click on the gear icon on the extension view and
select uninstall).
6. Fully close Code (not just the open window but the whole process)
7. Re-open Code and re-install Cody from VSIX.
8. Verify that credentials are cleared and you are presented with a
fresh login screen.

deletes auth credentials and endpoint history when the extension is
reinstalled

---------

Co-authored-by: Beatrix <68532117+abeatrix@users.noreply.github.com>
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