Skip to content

Commit dd853b9

Browse files
authored
Correctly handle agents prerelease versions for SDK version check (#729)
1 parent fede4ec commit dd853b9

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/agentfs/sdk_version_check.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,31 @@ func isVersionSatisfied(version, minVersion string) (bool, error) {
657657
return false, fmt.Errorf("invalid minimum version format: %s", minVersion)
658658
}
659659

660-
return !v.LessThan(min), nil
660+
// Check if version satisfies minimum using semver comparison
661+
if !v.LessThan(min) {
662+
return true, nil
663+
}
664+
665+
// Special handling for prerelease versions: if the base version matches,
666+
// consider prerelease versions as satisfying the requirement
667+
// (e.g., 1.3.0-rc1 should satisfy >=1.3.0)
668+
vBase := v.String()
669+
minBase := min.String()
670+
671+
// Remove prerelease suffix for base version comparison
672+
if strings.Contains(vBase, "-") {
673+
vBase = strings.Split(vBase, "-")[0]
674+
}
675+
if strings.Contains(minBase, "-") {
676+
minBase = strings.Split(minBase, "-")[0]
677+
}
678+
679+
if vBase == minBase && v.LessThan(min) {
680+
// Same base version, prerelease should satisfy
681+
return true, nil
682+
}
683+
684+
return false, nil
661685
}
662686

663687
// normalizeVersion normalizes version strings for semver parsing
@@ -674,6 +698,21 @@ func normalizeVersion(version string) string {
674698
version = version[1:]
675699
}
676700

701+
// Handle prerelease versions: convert various formats to semver
702+
// 1.3.0rc1 -> 1.3.0-rc1, 1.3rc -> 1.3.0-rc, etc.
703+
prereleasePattern := regexp.MustCompile(`^(\d+(?:\.\d+)*)([a-zA-Z][a-zA-Z0-9]*.*)$`)
704+
if matches := prereleasePattern.FindStringSubmatch(version); matches != nil {
705+
baseVersion := matches[1]
706+
prerelease := matches[2]
707+
708+
// Ensure we have at least MAJOR.MINOR.PATCH
709+
parts := strings.Split(baseVersion, ".")
710+
for len(parts) < 3 {
711+
parts = append(parts, "0")
712+
}
713+
version = strings.Join(parts, ".") + "-" + prerelease
714+
}
715+
677716
return version
678717
}
679718

pkg/agentfs/sdk_version_check_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ version = "1.5.0"`,
142142
},
143143
expectError: false,
144144
},
145+
{
146+
name: "Python requirements.txt with prerelease version",
147+
projectType: ProjectTypePythonPip,
148+
setupFiles: map[string]string{
149+
"requirements.txt": "livekit-agents~=1.3rc",
150+
},
151+
expectError: false,
152+
},
145153
{
146154
name: "No package found",
147155
projectType: ProjectTypePythonPip,
@@ -209,6 +217,9 @@ func TestIsVersionSatisfied(t *testing.T) {
209217
{"~1.5.0", "1.0.0", true, false},
210218
{">=1.5.0", "1.0.0", true, false},
211219
{"==1.5.0", "1.0.0", true, false},
220+
{"1.3.0rc1", "1.3.0", true, false}, // prerelease should satisfy same base version
221+
{"1.3rc", "1.3.0", true, false}, // short prerelease should satisfy same base version
222+
{"1.3.0rc1", "1.4.0", false, false}, // prerelease should not satisfy higher version
212223
{"invalid", "1.0.0", false, true},
213224
{"1.5.0", "invalid", false, true},
214225
}
@@ -248,6 +259,12 @@ func TestNormalizeVersion(t *testing.T) {
248259
{`'1.5.0'`, "1.5.0"},
249260
{"*", "*"},
250261
{"latest", "latest"},
262+
{"1.3.0rc1", "1.3.0-rc1"},
263+
{"1.3.0beta2", "1.3.0-beta2"},
264+
{"1.3.0alpha1", "1.3.0-alpha1"},
265+
{"1.3rc", "1.3.0-rc"},
266+
{"1.3rc1", "1.3.0-rc1"},
267+
{"~=1.3rc", "1.3.0-rc"},
251268
}
252269

253270
for _, tt := range tests {

0 commit comments

Comments
 (0)