Repository: lima-vm/lima (Go)

Issue:
[Windows] Test coverage missing for part of User home dir setup login on Windows
### Description

Identified by this comment https://github.com/lima-vm/lima/pull/3304#discussion_r2002648601

There is non-trivial piece of code for deriving user home in guest VM using cygpath/wslpath. Both a similar, but have behavior differences and could have configuration differences. 

For testing purposes this could would need to be refactored and mocks created for the tools themselves.

The thing to think about is. May be this code can be removed at all, because it is followed up by https://github.com/lima-vm/lima/blob/786c1f5f3c6e8ff276c0c5d6789cdd9243d70f49/pkg/osutil/user.go#L167 which is re-implementation of basics of the cygpath processing Windows paths into Unix (default msys2 configuration, no FS customizations). May be this is really sufficient for the case, especially because the path from the tools has to be updated with some sort of prefix and is not used directly (to prevent collision with mounts).


Discussion:

Patch:
diff --git a/pkg/osutil/user.go b/pkg/osutil/user.go
index 8a47ffee58d..8b09091f069 100644
--- a/pkg/osutil/user.go
+++ b/pkg/osutil/user.go
@@ -7,15 +7,12 @@ import (
 	"fmt"
 	"os/exec"
 	"os/user"
-	"path"
-	"path/filepath"
 	"regexp"
 	"runtime"
 	"strconv"
 	"strings"
 	"sync"
 
-	"github.com/lima-vm/lima/pkg/ioutilx"
 	. "github.com/lima-vm/lima/pkg/must"
 	"github.com/lima-vm/lima/pkg/version/versionutil"
 	"github.com/sirupsen/logrus"
@@ -45,9 +42,6 @@ var (
 // names to the fallback user as well, so the regex does not allow them.
 var regexUsername = regexp.MustCompile("^[a-z_][a-z0-9_-]*$")
 
-// regexPath detects valid Linux path.
-var regexPath = regexp.MustCompile("^[/a-zA-Z0-9_-]+$")
-
 func LookupUser(name string) (User, error) {
 	if users == nil {
 		users = make(map[string]User)
@@ -115,9 +109,8 @@ func LimaUser(limaVersion string, warn bool) *user.User {
 			warnings = append(warnings, warning)
 			limaUser.Username = fallbackUser
 		}
-		if runtime.GOOS != "windows" {
-			limaUser.HomeDir = "/home/{{.User}}.linux"
-		} else {
+		limaUser.HomeDir = "/home/{{.User}}.linux"
+		if runtime.GOOS == "windows" {
 			idu, err := call([]string{"id", "-u"})
 			if err != nil {
 				logrus.Debug(err)
@@ -146,38 +139,6 @@ func LimaUser(limaVersion string, warn bool) *user.User {
 				warnings = append(warnings, warning)
 				limaUser.Gid = formatUidGid(gid)
 			}
-			home, err := ioutilx.WindowsSubsystemPath(limaUser.HomeDir)
-			if err != nil {
-				logrus.Debug(err)
-			} else {
-				// Trim mount prefix within Subsystem
-				// cygwin/msys2 cygpath could have prefix for drive mounts configured via /etc/fstab
-				// wsl wslpath could have prefix for drive mounts configured via [automount] section in wsl.conf
-				drivePath, err := ioutilx.WindowsSubsystemPath(filepath.VolumeName(limaUser.HomeDir) + "/")
-				if err != nil {
-					logrus.Debug(err)
-				} else {
-					prefix := path.Dir(strings.TrimSuffix(drivePath, "/"))
-					if prefix != "/" {
-						home = strings.TrimPrefix(home, prefix)
-					}
-					home += ".linux"
-				}
-			}
-			if home == "" {
-				drive := filepath.VolumeName(limaUser.HomeDir)
-				home = filepath.ToSlash(limaUser.HomeDir)
-				// replace C: with /c
-				prefix := strings.ToLower(fmt.Sprintf("/%c", drive[0]))
-				home = strings.Replace(home, drive, prefix, 1)
-				home += ".linux"
-			}
-			if !regexPath.MatchString(limaUser.HomeDir) {
-				warning := fmt.Sprintf("local home %q is not a valid Linux path (must match %q); using %q home instead",
-					limaUser.HomeDir, regexPath.String(), home)
-				warnings = append(warnings, warning)
-				limaUser.HomeDir = home
-			}
 		}
 	})
 	if warn {


Test patch:
diff --git a/pkg/limayaml/defaults_test.go b/pkg/limayaml/defaults_test.go
index 52d1435baa9..b8f203838dd 100644
--- a/pkg/limayaml/defaults_test.go
+++ b/pkg/limayaml/defaults_test.go
@@ -62,10 +62,7 @@ func TestFillDefault(t *testing.T) {
 	limaHome, err := dirnames.LimaDir()
 	assert.NilError(t, err)
 	user := osutil.LimaUser("0.0.0", false)
-	if runtime.GOOS != "windows" {
-		// manual template expansion for "/home/{{.User}}.linux" (done by FillDefault)
-		user.HomeDir = fmt.Sprintf("/home/%s.linux", user.Username)
-	}
+	user.HomeDir = fmt.Sprintf("/home/%s.linux", user.Username)
 	uid, err := strconv.ParseUint(user.Uid, 10, 32)
 	assert.NilError(t, err)