Skip to content

impl: support for Toolbox 2.6.3 #124

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

impl: support for Toolbox 2.6.3 #124

wants to merge 16 commits into from

Conversation

fioan89
Copy link
Collaborator

@fioan89 fioan89 commented May 26, 2025

Toolbox 2.6.3 comes with a couple of new additions in the API which need the following changes:

  • finish support for URI handling. The available API up to TBX 2.6.3 was buggy in terms of URI handling. It didn't allow plugins to programmatically install remote ides and launch them. The launch operation only worked when the IDE was already installed and a project was already opened with the IDE.

    TBX 2.6.3 adds a new API, RemoteToolboxHelp which provides routines for listing the available
    IDEs on the remote, what is already installed and a command to install specific versions of the IDE.
    Additionally, there were fixes provided to the existing ClientHelper which now launches the JBClient
    if a project was not specified. An additional quirk I've discovered is that if we provide a project, and
    that project was not already opened (present in the Projects tab) the IDE still won't open. And there
    is no API available to query the available projects.

    This PR uses the new API to:

    • query the installed ides
    • check if the provided ide is in the list of already installed IDEs.
    • if that's not the case we query the available list of IDEs and the available versions
    • if the provided ide and build no., is in the available list we will schedule it for install
    • if not, we select the latest available build number for the provided product code.
    • wait for the remote IDE to be installed
    • and then download and launch the JBClient with a project path if it was provided.
    • update the minimum API requirement. Toolbox API is upgraded to 1.1.41749 which comes with new API additions and some deprecations. Kotlin stdlib was also increased to a newer patch version
  • use new environment state API. The CustomRemoteEnvironmentState is deprecated, and replaced by a new class CustomRemoteEnvironmentStateV2 which now supports i18n state labels

  • use the new ssh disconnect callback. Toolbox provides two callbacks, one before an SSH connection is established and another one which executes when the ssh connection is stopped. The latter was deprecated in the favor of a new callback that also provides hints on whether the user requested the disconnect.

  • use the new delete callback API. Toolbox provides a callback for scenarios that involve the env. deletion. This allows plugins to react and clean the internal state. With the new TBX API, the delete callback API is deprecated in the favor of a mutable state flow, a reactive approach that allows consumers to observe and react to state changes over time.

fioan89 added 13 commits May 27, 2025 00:01
Toolbox API is upgraded to 1.1.41749 which comes with new API additions and some
deprecations. Kotlin stdlib was also increased to a newer patch version
The CustomRemoteEnvironmentState is deprecated, and replaced by a new class CustomRemoteEnvironmentStateV2
which now supports i18n state labels
Toolbox provides two callbacks, one before an SSH connection is established and another one
which executes when the ssh connection is stopped. The latter was deprecated in the favor
of a new callback that also provides hints on whether the user requested the disconnect.
Toolbox provides a callback for scenarios that involve the env. deletion. This allows plugins to react
and clean the internal state. With the new TBX API, the delete callback API is deprecated in the favor
of a mutable state flow, a reactive approach that allows consumers to observe and react to state changes
over time.
The available API up to TBX 2.6.3 was buggy in terms of URI handling. It didn't allow plugins
to programmatically install remote ides and launch them. The launch operation only worked when
the IDE was already installed and a project was already opened with the IDE.

TBX 2.6.3 adds a new API, _RemoteToolboxHelp_ which provides routines for listing the available
IDEs on the remote, what is already installed and a command to install specific versions of the IDE.
Additionally, there were fixes provided to the existing _ClientHelper_ which now launches the JBClient
if a project was not specified. An additional quirk I've discovered is that if we provide a project, and
that project was not already opened (present in the Projects tab) the IDE still won't open. And there
is no API available to query the available projects.

This commit uses the new API to:
- query the installed ides
- check if the provided ide is in the list of already installed IDEs.
- if that's not the case we query the available list of IDEs and the available versions
- if the provided ide and build no., is in the available list we will schedule it for install
- if not, we select the latest available build number for the provided product code.
- wait for the remote IDE to be installed
- and then download and launch the JBClient with a project path if it was provided.
Refactored code around uri, token, workspace and rest client resolving by
encapsulating code in clearly named methods. Rest client resolving was overly-complicated
(code inherited from Gateway), with token being a mandatory parameter. Removed a lot of code
that asked the token from the user if it was missing.

Also, I decided to use a snackbar to show errors because of attached regression in TBX.
A bottom simple dialog is more pleasing to the eye than a dialog in the middle of a page.

https://youtrack.jetbrains.com/issue/TBX-14944/Pop-up-dialogs-are-only-displayed-on-the-main-envs-page
Refactored code around workspace and agent resolving.
Refactored code around cli initialization.
Refactored code around remote ide installation, local jbclient install and launch
Removed unused code and refactored unit tests to take into account that some of the methods are no longer
static, and that return type changed.
Rename class to be in sync with the class it tests
`folder` URI param needs to be a path to an IDEA project that was
already opened in the IDE. Or it should not be provided at all otherwise
the remote IDE won't start.
Switched the order of the steps, the agent and hist state is resolved
only after the workspace was resolved and after it was in a running
state. Otherwise URI handling during workspace startup could provide
misleading errors related to agent not existing or not being ready.
@fioan89 fioan89 marked this pull request as ready for review May 29, 2025 22:14
@fioan89 fioan89 requested review from matifali and f0ssel May 29, 2025 22:14
@fioan89
Copy link
Collaborator Author

fioan89 commented May 29, 2025

Test scenarios I've covered:

  • Run the URI with TBX stopped, and with no query params. TBX starts and logins with the last successful deployment
    jetbrains://gateway/com.coder.toolbox
    jetbrains://gateway/com.coder.toolbox?

  • URI without deployment URL. Plugin ask it for the URL

  • URI without token. Error snack bar is raised.

  • URI without workspace name. Error snack bar is raised.

  • URI with invalid or expired token. Error snack bar is raised.

  • URI with no agent id provided. We use the default agent if there is only one agent.

  • URI with correct agent id. Works as expected.

  • URI with invalid agent id. Error snack bar is raised.

  • URI while workspace is stopping. Error is raised.

  • URI while workspace is stopping. Error related to agent not being started was raised.

  • URI with no product code provided. TBX opens, up, Workspace is displayed and SSH connection is established

  • URI with no product code provided. Same behavior as above.

  • URI with invalid product code. Error is raised.

  • URI with invalid or a build number that is not available. The plugin automatically selects and install the latest available version for the provided product code. It also pops up an info snackbar.

  • URI with no folder provided. Remote IDE is launched with the last opened project or with the welcome screen.

  • URI with an invalid or path that is not already a project. The remote IDE is not launched.

  • URI with a path that exists and it is already an IDEA project. Remote IDE is launched, and project is opened.

fioan89 added 3 commits May 30, 2025 01:48
And only then start validating the parameters. Otherwise, we can
end up in a situation where we ask TBX to show a snackbar while TBX is not
yet visible/initialized. In that case the UI page doesn't show the snackbar
Toolbox already does that whe executing a URI while TBX is stopped. And during runtime
it seems that snackbars have the ability to request the window to be visible. Only the
rest of the dialogs need explicit request for the TBX window to be visible
This version is only supporting TBX 2.6.3 and above so it is worth at least a minor increase.
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

LGTM feature wise. Will defer code review to Garret.

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