Skip to content

Update Wsh Command#1715

Merged
oneirocosm merged 9 commits intomainfrom
sylvie/update-cmd
Jan 11, 2025
Merged

Update Wsh Command#1715
oneirocosm merged 9 commits intomainfrom
sylvie/update-cmd

Conversation

@oneirocosm
Copy link
Contributor

This adds an RPC command for updating wsh on a remote machine without starting a new session. It is not being used yet, but will be used for connections using a single server in the future.

This will theoretically allow updates to happen seamlessly without
requiring a separate session.
This reduces a bit of duplication, both now, and for a future change.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces a series of updates to the WSH (Wave Shell) system, primarily focusing on enhancing server functionality and adding a new update mechanism. Key changes include the introduction of a singleServerRouter boolean flag in the command-line interface, which allows the server to operate in a single mode. The serverRun function is modified to incorporate this new flag, determining the server's operational path based on its value.

Additionally, a new RemoteInfo type is defined to facilitate the transfer of client-related information, and the ConnUpdateWshCommand method is added across various components, enabling WSH updates. The update process includes checks for the current WSH version, retrieval of client details, and execution of updates as necessary, with error handling implemented throughout. These modifications collectively enhance the functionality and robustness of the WSH system's connection and update management.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
pkg/wshrpc/wshserver/wshserver.go (1)

702-734: Add logging and use constants for WSL prefix.

The implementation looks good but could benefit from the following improvements:

  1. Add logging for better observability
  2. Use a constant for the "wsl://" prefix

Apply this diff to improve the implementation:

+const wslPrefix = "wsl://"
+
 func (ws *WshServer) ConnUpdateWshCommand(ctx context.Context, updateInfo wshrpc.RemoteInfo) (bool, error) {
 	connName := updateInfo.ConnName
+	log.Printf("checking if wsh update is needed for %s", connName)
 	// check version number, return now if update not necessary
 	upToDate, _, err := conncontroller.IsWshVersionUpToDate(updateInfo.ClientVersion)
 	if err != nil {
 		return false, fmt.Errorf("unable to compare wsh version: %w", err)
 	}
 	if upToDate {
+		log.Printf("wsh is up to date for %s", connName)
 		// no need to update
 		return false, nil
 	}
+	log.Printf("wsh update needed for %s", connName)

 	// todo: need to add user input code here for validation

-	if strings.HasPrefix(connName, "wsl://") {
+	if strings.HasPrefix(connName, wslPrefix) {
 		return false, fmt.Errorf("cannot use this command for wsl connections")
 	}
 	connOpts, err := remote.ParseOpts(connName)
 	if err != nil {
 		return false, fmt.Errorf("error parsing connection name: %w", err)
 	}
 	conn := conncontroller.GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
 	if conn == nil {
 		return false, fmt.Errorf("connection not found: %s", connName)
 	}
 	err = conn.UpdateWsh(ctx, connName, &conncontroller.WshInstallOpts{Force: true, NoUserPrompt: true})
 	if err != nil {
 		return false, fmt.Errorf("update failed: %w", err)
 	}
+	log.Printf("successfully updated wsh for %s", connName)

 	// todo: need to add code for modifying configs?
 	return true, nil
 }

Track the TODO items.

There are two TODO items that need to be addressed:

  1. Add user input code for validation
  2. Add code for modifying configs

Would you like me to open GitHub issues to track these tasks?

pkg/wshutil/wshutil.go (1)

541-550: Consider adding error handling for environment variable.

The function assumes the SHELL environment variable exists. While this is typically true on Unix-like systems, it might not be set in all environments.

Consider this improvement:

func GetInfo(rpcContext wshrpc.RpcContext) wshrpc.RemoteInfo {
+    shell := os.Getenv("SHELL")
+    if shell == "" {
+        shell = "/bin/sh"  // provide a sensible default
+    }
    return wshrpc.RemoteInfo{
        ConnName:      rpcContext.Conn,
        ClientArch:    runtime.GOARCH,
        ClientOs:      runtime.GOOS,
        ClientVersion: wavebase.WaveVersion,
-        Shell:         os.Getenv("SHELL"),
+        Shell:         shell,
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b26d233 and 5d78007.

📒 Files selected for processing (8)
  • cmd/wsh/cmd/wshcmd-connserver.go (4 hunks)
  • frontend/app/store/wshclientapi.ts (1 hunks)
  • frontend/types/gotypes.d.ts (1 hunks)
  • pkg/remote/conncontroller/conncontroller.go (3 hunks)
  • pkg/wshrpc/wshclient/wshclient.go (1 hunks)
  • pkg/wshrpc/wshrpctypes.go (3 hunks)
  • pkg/wshrpc/wshserver/wshserver.go (1 hunks)
  • pkg/wshutil/wshutil.go (2 hunks)
👮 Files not reviewed due to content moderation or server errors (1)
  • cmd/wsh/cmd/wshcmd-connserver.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/remote/conncontroller/conncontroller.go

382-382: ineffectual assignment to opts

(ineffassign)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (4)
pkg/wshrpc/wshrpctypes.go (1)

87-87: LGTM!

The command constant follows the established naming pattern and its value is consistent with other commands in the codebase.

pkg/remote/conncontroller/conncontroller.go (1)

231-231: LGTM!

Exporting IsWshVersionUpToDate is appropriate as it's now used by the wshserver package.

frontend/app/store/wshclientapi.ts (1)

60-64: Well-structured implementation following established patterns!

The new command follows the consistent pattern used throughout the codebase for RPC commands.

pkg/wshrpc/wshclient/wshclient.go (1)

76-80: Clean implementation following the established pattern!

The new command function is well-structured and consistent with other RPC command implementations in the file.

Comment on lines +505 to +511
type RemoteInfo struct {
ConnName string `json:"host"`
ClientArch string `json:"clientarch"`
ClientOs string `json:"clientos"`
ClientVersion string `json:"string"`
Shell string `json:"shell"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect JSON tag for ClientVersion field.

The JSON tag for ClientVersion is incorrectly set to "string" instead of "clientversion". Also, consider grouping related fields together.

Apply this diff to fix the JSON tag and improve field grouping:

 type RemoteInfo struct {
 	ConnName      string `json:"host"`
+	Shell         string `json:"shell"`
 	ClientArch    string `json:"clientarch"`
 	ClientOs      string `json:"clientos"`
-	ClientVersion string `json:"string"`
-	Shell         string `json:"shell"`
+	ClientVersion string `json:"clientversion"`
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type RemoteInfo struct {
ConnName string `json:"host"`
ClientArch string `json:"clientarch"`
ClientOs string `json:"clientos"`
ClientVersion string `json:"string"`
Shell string `json:"shell"`
}
type RemoteInfo struct {
ConnName string `json:"host"`
Shell string `json:"shell"`
ClientArch string `json:"clientarch"`
ClientOs string `json:"clientos"`
ClientVersion string `json:"clientversion"`
}

Comment on lines +380 to +400
func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, opts *WshInstallOpts) error {
if opts == nil {
opts = &WshInstallOpts{}
}
client := conn.GetClient()
if client == nil {
return fmt.Errorf("client is nil")
}
clientOs, clientArch, err := remote.GetClientPlatform(ctx, genconn.MakeSSHShellClient(client))
if err != nil {
return err
}
// should be able to GetClientPlatform in other ways, but this works for now
err = remote.CpWshToRemote(ctx, client, clientOs, clientArch)
if err != nil {
return fmt.Errorf("error installing wsh to remote: %w", err)
}
log.Printf("successfully installed wsh on %s\n", conn.GetName())
return nil

}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix ineffectual assignment and improve error handling.

The function has the following issues:

  1. The assignment to opts at line 382 is ineffectual as it's immediately overwritten.
  2. The error message from GetClientPlatform should be more descriptive.

Apply this diff to fix the issues:

 func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, opts *WshInstallOpts) error {
-	if opts == nil {
-		opts = &WshInstallOpts{}
-	}
 	client := conn.GetClient()
 	if client == nil {
 		return fmt.Errorf("client is nil")
 	}
 	clientOs, clientArch, err := remote.GetClientPlatform(ctx, genconn.MakeSSHShellClient(client))
 	if err != nil {
-		return err
+		return fmt.Errorf("failed to detect client platform: %w", err)
 	}
-	// should be able to GetClientPlatform in other ways, but this works for now
 	err = remote.CpWshToRemote(ctx, client, clientOs, clientArch)
 	if err != nil {
 		return fmt.Errorf("error installing wsh to remote: %w", err)
 	}
 	log.Printf("successfully installed wsh on %s\n", conn.GetName())
 	return nil
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, opts *WshInstallOpts) error {
if opts == nil {
opts = &WshInstallOpts{}
}
client := conn.GetClient()
if client == nil {
return fmt.Errorf("client is nil")
}
clientOs, clientArch, err := remote.GetClientPlatform(ctx, genconn.MakeSSHShellClient(client))
if err != nil {
return err
}
// should be able to GetClientPlatform in other ways, but this works for now
err = remote.CpWshToRemote(ctx, client, clientOs, clientArch)
if err != nil {
return fmt.Errorf("error installing wsh to remote: %w", err)
}
log.Printf("successfully installed wsh on %s\n", conn.GetName())
return nil
}
func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, opts *WshInstallOpts) error {
client := conn.GetClient()
if client == nil {
return fmt.Errorf("client is nil")
}
clientOs, clientArch, err := remote.GetClientPlatform(ctx, genconn.MakeSSHShellClient(client))
if err != nil {
return fmt.Errorf("failed to detect client platform: %w", err)
}
err = remote.CpWshToRemote(ctx, client, clientOs, clientArch)
if err != nil {
return fmt.Errorf("error installing wsh to remote: %w", err)
}
log.Printf("successfully installed wsh on %s\n", conn.GetName())
return nil
}
🧰 Tools
🪛 golangci-lint (1.62.2)

382-382: ineffectual assignment to opts

(ineffassign)

Comment on lines +749 to +755
// wshrpc.UpdateInfo
type UpdateInfo = {
host: string;
clientarch: string;
clientos: string;
string: string;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix field name in UpdateInfo type.

The string field should be renamed to clientversion to match the corrected Go struct.

Apply this diff to fix the field name:

 type UpdateInfo = {
     host: string;
     clientarch: string;
     clientos: string;
-    string: string;
+    clientversion: string;
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// wshrpc.UpdateInfo
type UpdateInfo = {
host: string;
clientarch: string;
clientos: string;
string: string;
};
// wshrpc.UpdateInfo
type UpdateInfo = {
host: string;
clientarch: string;
clientos: string;
clientversion: string;
};

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
pkg/remote/conncontroller/conncontroller.go (1)

380-393: Improve error handling and logging.

The function has the following suggestions:

  1. Add more descriptive error messages
  2. Use the connection's Infof method for consistent logging
  3. Consider validating the RemoteInfo fields before use

Apply this diff to improve the implementation:

 func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, remoteInfo *wshrpc.RemoteInfo) error {
-	log.Printf("attempting to update wsh for connection %v", remoteInfo)
+	conn.Infof(ctx, "attempting to update wsh for connection %s (os:%s arch:%s version:%s)\n",
+		remoteInfo.ConnName, remoteInfo.ClientOs, remoteInfo.ClientArch, remoteInfo.ClientVersion)
+
+	if remoteInfo.ClientOs == "" || remoteInfo.ClientArch == "" {
+		return fmt.Errorf("invalid remote info: missing os or arch information")
+	}
+
 	client := conn.GetClient()
 	if client == nil {
-		return fmt.Errorf("client is nil")
+		return fmt.Errorf("cannot update wsh: ssh client is not connected")
 	}
+
 	err := remote.CpWshToRemote(ctx, client, remoteInfo.ClientOs, remoteInfo.ClientArch)
 	if err != nil {
 		return fmt.Errorf("error installing wsh to remote: %w", err)
 	}
-	log.Printf("successfully installed wsh on %s\n", conn.GetName())
+	conn.Infof(ctx, "successfully updated wsh on %s\n", conn.GetName())
 	return nil
 }
pkg/wshrpc/wshserver/wshserver.go (2)

715-715: Track TODOs with GitHub issues.

There are two TODO comments that need to be tracked:

  1. Add user input code for validation
  2. Add code for modifying configs

Would you like me to create GitHub issues to track these TODOs?

Also applies to: 733-733


702-735: Improve error handling and add validation.

The implementation could be improved with:

  1. More descriptive error messages
  2. Validation of RemoteInfo fields
  3. Consistent logging

Apply this diff to improve the implementation:

 func (ws *WshServer) ConnUpdateWshCommand(ctx context.Context, remoteInfo wshrpc.RemoteInfo) (bool, error) {
 	connName := remoteInfo.ConnName
+	if connName == "" {
+		return false, fmt.Errorf("invalid remote info: missing connection name")
+	}
+
+	log.Printf("checking wsh version for connection %s (current: %s)", connName, remoteInfo.ClientVersion)
+
 	// check version number, return now if update not necessary
 	upToDate, _, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
 	if err != nil {
 		return false, fmt.Errorf("unable to compare wsh version: %w", err)
 	}
 	if upToDate {
 		// no need to update
-		log.Printf("wsh update is not needed for connection %s", connName)
+		log.Printf("wsh is already up to date for connection %s", connName)
 		return false, nil
 	}

 	// todo: need to add user input code here for validation

 	if strings.HasPrefix(connName, "wsl://") {
-		return false, fmt.Errorf("cannot use this command for wsl connections")
+		return false, fmt.Errorf("wsh update is not supported for WSL connections")
 	}
 	connOpts, err := remote.ParseOpts(connName)
 	if err != nil {
 		return false, fmt.Errorf("error parsing connection name: %w", err)
 	}
 	conn := conncontroller.GetConn(ctx, connOpts, false, &wshrpc.ConnKeywords{})
 	if conn == nil {
 		return false, fmt.Errorf("connection not found: %s", connName)
 	}
+
+	log.Printf("attempting to update wsh for connection %s", connName)
 	err = conn.UpdateWsh(ctx, connName, &remoteInfo)
 	if err != nil {
-		return false, fmt.Errorf("update failed: %w", err)
+		return false, fmt.Errorf("wsh update failed for connection %s: %w", connName, err)
 	}

 	// todo: need to add code for modifying configs?
+	log.Printf("successfully updated wsh for connection %s", connName)
 	return true, nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8fd717 and c7a7905.

📒 Files selected for processing (3)
  • pkg/remote/conncontroller/conncontroller.go (3 hunks)
  • pkg/wshrpc/wshrpctypes.go (3 hunks)
  • pkg/wshrpc/wshserver/wshserver.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (4)
pkg/wshrpc/wshrpctypes.go (3)

87-87: LGTM!

The command constant follows the established naming convention and is appropriately placed with other connection-related commands.


167-167: LGTM!

The interface method signature is consistent with other connection-related methods.


505-511: ⚠️ Potential issue

Fix incorrect JSON tag and improve field grouping.

The struct has the following issues:

  1. The JSON tag for ClientVersion is incorrect, it should be "clientversion" instead of "string".
  2. Related fields should be grouped together.

Apply this diff to fix the JSON tag and improve field grouping:

 type RemoteInfo struct {
 	ConnName      string `json:"host"`
+	Shell         string `json:"shell"`
 	ClientArch    string `json:"clientarch"`
 	ClientOs      string `json:"clientos"`
-	ClientVersion string `json:"string"`
-	Shell         string `json:"shell"`
+	ClientVersion string `json:"clientversion"`
 }

Likely invalid or redundant comment.

pkg/remote/conncontroller/conncontroller.go (1)

231-231: LGTM!

The function is well-structured and uses proper semantic versioning for comparison.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
pkg/remote/conncontroller/conncontroller.go (1)

380-394: ⚠️ Potential issue

Add validation for remoteInfo fields in UpdateWsh

Ensure that remoteInfo.ClientOs and remoteInfo.ClientArch are not empty before proceeding, to prevent potential errors in remote.CpWshToRemote.

Apply this diff to add validation:

     client := conn.GetClient()
     if client == nil {
         return fmt.Errorf("cannot update wsh: ssh client is not connected")
     }
+    if remoteInfo.ClientOs == "" || remoteInfo.ClientArch == "" {
+        return fmt.Errorf("invalid remote info: missing ClientOs or ClientArch")
+    }
     err := remote.CpWshToRemote(ctx, client, remoteInfo.ClientOs, remoteInfo.ClientArch)
     if err != nil {
         return fmt.Errorf("error installing wsh to remote: %w", err)
     }
🧹 Nitpick comments (5)
pkg/wshrpc/wshserver/wshserver.go (2)

719-720: Implement user input validation

The TODO comment indicates that user input validation needs to be added. This is essential to ensure secure and reliable operation.

Would you like me to implement the user input validation code, or open a new GitHub issue to track this task?


737-738: Implement configuration modification code

The TODO comment suggests that code for modifying configurations is needed. Implementing this will ensure that configurations are properly updated after the WSH update.

Would you like me to help implement the configuration modification code, or open a new GitHub issue to track this task?

pkg/remote/conncontroller/conncontroller.go (3)

Line range hint 231-242: Refactor IsWshVersionUpToDate to accept version strings directly

The function IsWshVersionUpToDate currently expects a version line in the format "wsh v0.10.4", which may not be flexible. Consider refactoring the function to accept version strings directly, improving reusability.

Apply this diff to modify the function:

 func IsWshVersionUpToDate(clientVersion string) (bool, string, error) {
-    wshVersionLine = strings.TrimSpace(wshVersionLine)
-    if wshVersionLine == "not-installed" {
+    clientVersion = strings.TrimSpace(clientVersion)
+    if clientVersion == "not-installed" || clientVersion == "" {
         return false, "", nil
     }
-    parts := strings.Fields(wshVersionLine)
-    if len(parts) != 2 {
-        return false, "", fmt.Errorf("unexpected version format: %s", wshVersionLine)
-    }
-    clientVersion := parts[1]
     expectedVersion := fmt.Sprintf("v%s", wavebase.WaveVersion)
     if semver.Compare(clientVersion, expectedVersion) < 0 {
         return false, clientVersion, nil

Then, adjust the calls to this function accordingly.


Line range hint 293-299: Adjust call to IsWshVersionUpToDate

After refactoring IsWshVersionUpToDate, update the call in StartConnServer to pass the client version directly.

Apply this diff:

     conn.Infof(ctx, "got connserver version: %s\n", strings.TrimSpace(versionLine))
-    isUpToDate, clientVersion, err := IsWshVersionUpToDate(versionLine)
+    parts := strings.Fields(versionLine)
+    if len(parts) != 2 {
+        return false, "", fmt.Errorf("unexpected version format: %s", versionLine)
+    }
+    clientVersion := parts[1]
+    isUpToDate, clientVersion, err := IsWshVersionUpToDate(clientVersion)
     if err != nil {
         sshSession.Close()
         return false, "", fmt.Errorf("error checking wsh version: %w", err)

293-294: Handle potential nil clientVersion after parsing

After extracting clientVersion, ensure it is not empty before proceeding with the version comparison to prevent potential panics.

Apply this diff:

     clientVersion := parts[1]
+    if clientVersion == "" {
+        return false, "", fmt.Errorf("client version is empty")
+    }
     isUpToDate, clientVersion, err := IsWshVersionUpToDate(clientVersion)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7a7905 and c9461ba.

📒 Files selected for processing (3)
  • frontend/types/gotypes.d.ts (1 hunks)
  • pkg/remote/conncontroller/conncontroller.go (3 hunks)
  • pkg/wshrpc/wshserver/wshserver.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/types/gotypes.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build for TestDriver.ai

Comment on lines +709 to +712
upToDate, _, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
if err != nil {
return false, fmt.Errorf("unable to compare wsh version: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect usage of IsWshVersionUpToDate function

The IsWshVersionUpToDate function expects a version line in the format "wsh v0.10.4" or "not-installed", but remoteInfo.ClientVersion likely contains only the version string (e.g., "v0.10.4"). Passing remoteInfo.ClientVersion directly may cause incorrect parsing and version comparison.

Apply this diff to adjust the version string before calling IsWshVersionUpToDate:

     log.Printf("checking wsh version for connection %s (current: %s)", connName, remoteInfo.ClientVersion)
-    upToDate, _, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
+    versionLine := fmt.Sprintf("wsh %s", remoteInfo.ClientVersion)
+    upToDate, _, err := conncontroller.IsWshVersionUpToDate(versionLine)
     if err != nil {
         return false, fmt.Errorf("unable to compare wsh version: %w", err)
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
upToDate, _, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
if err != nil {
return false, fmt.Errorf("unable to compare wsh version: %w", err)
}
versionLine := fmt.Sprintf("wsh %s", remoteInfo.ClientVersion)
upToDate, _, err := conncontroller.IsWshVersionUpToDate(versionLine)
if err != nil {
return false, fmt.Errorf("unable to compare wsh version: %w", err)
}

@oneirocosm oneirocosm merged commit 5a7771b into main Jan 11, 2025
5 checks passed
@oneirocosm oneirocosm deleted the sylvie/update-cmd branch January 11, 2025 05:29
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
This adds an RPC command for updating wsh on a remote machine without
starting a new session. It is not being used yet, but will be used for
connections using a single server in the future.
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.

1 participant