Skip to content

Commit 6696d47

Browse files
nek023Stratus3D
andauthored
fix: correct version resolution order to restore legacy file fallback behavior (#1956)
Co-authored-by: Trevor Brown <[email protected]>
1 parent 38bea71 commit 6696d47

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

internal/resolve/resolve.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ func Version(conf config.Config, plugin plugins.Plugin, directory string) (versi
5656
}
5757

5858
func findVersionsInDir(conf config.Config, plugin plugins.Plugin, directory string) (versions ToolVersions, found bool, err error) {
59+
filepath := path.Join(directory, conf.DefaultToolVersionsFilename)
60+
61+
if _, err = os.Stat(filepath); err == nil {
62+
versions, found, err := toolversions.FindToolVersions(filepath, plugin.Name)
63+
if found || err != nil {
64+
return ToolVersions{Versions: versions, Source: conf.DefaultToolVersionsFilename, Directory: directory}, found, err
65+
}
66+
}
67+
5968
legacyFiles, err := conf.LegacyVersionFile()
6069
if err != nil {
6170
return versions, found, err
@@ -69,15 +78,6 @@ func findVersionsInDir(conf config.Config, plugin plugins.Plugin, directory stri
6978
}
7079
}
7180

72-
filepath := path.Join(directory, conf.DefaultToolVersionsFilename)
73-
74-
if _, err = os.Stat(filepath); err == nil {
75-
versions, found, err := toolversions.FindToolVersions(filepath, plugin.Name)
76-
if found || err != nil {
77-
return ToolVersions{Versions: versions, Source: conf.DefaultToolVersionsFilename, Directory: directory}, found, err
78-
}
79-
}
80-
8181
return versions, found, nil
8282
}
8383

internal/resolve/resolve_test.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,34 @@ func TestFindVersionsInDir(t *testing.T) {
129129
assert.Nil(t, err)
130130
})
131131

132-
t.Run("when legacy file support is on looks up version in legacy file", func(t *testing.T) {
132+
t.Run("when .tool-version exists and legacy file support is on looks up version in .tool-versions", func(t *testing.T) {
133133
currentDir := t.TempDir()
134134

135-
data := []byte("1.2.3 2.3.4")
135+
data := []byte(fmt.Sprintf("%s 1.2.3", testPluginName))
136+
err = os.WriteFile(filepath.Join(currentDir, ".tool-versions"), data, 0o666)
137+
assert.NoError(t, err)
138+
139+
data = []byte("2.3.4 3.4.5")
136140
err = os.WriteFile(filepath.Join(currentDir, ".dummy-version"), data, 0o666)
141+
assert.NoError(t, err)
137142

138143
toolVersion, found, err := findVersionsInDir(conf, plugin, currentDir)
144+
assert.Equal(t, toolVersion.Versions, []string{"1.2.3"})
145+
assert.True(t, found)
146+
assert.NoError(t, err)
147+
})
139148

149+
t.Run("when .tool-version does not exist and legacy file support is on looks up version in legacy file", func(t *testing.T) {
150+
currentDir := t.TempDir()
151+
152+
data := []byte("1.2.3 2.3.4")
153+
err = os.WriteFile(filepath.Join(currentDir, ".dummy-version"), data, 0o666)
154+
assert.NoError(t, err)
155+
156+
toolVersion, found, err := findVersionsInDir(conf, plugin, currentDir)
140157
assert.Equal(t, toolVersion.Versions, []string{"1.2.3", "2.3.4"})
141158
assert.True(t, found)
142-
assert.Nil(t, err)
159+
assert.NoError(t, err)
143160
})
144161
}
145162

0 commit comments

Comments
 (0)