fix(lambda): list $LATEST first, then versions in numeric order (#5376)

Sort stored versions numerically so ListVersionsByFunction is stable and matches AWS.

* Fix #5121

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-10 09:41:44 -04:00
1 parent 6d76af0834
commit 47dae887f9
3 files changed
+54 -4

No files matched your search

@@ -10,6 +10,8 @@ import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
@@ -78,7 +80,7 @@ public class LambdaFunctionStore implements Resettable {
public void save(String region, LambdaFunction fn) {
// Remove old index entry if URL changed or was removed
get(region, fn.getFunctionName(), fn.getVersion()).ifPresent(this::deindexFunction);
backend.put(regionKey(region, fn.getFunctionName(), fn.getVersion()), fn);
indexFunction(fn);
}
@@ -140,7 +142,17 @@ public class LambdaFunctionStore implements Resettable {
public List<LambdaFunction> listVersions(String region, String functionName) {
String prefix = "lambda::" + region + "::" + functionName + "::";
return backend.scan(key -> key.startsWith(prefix));
List<LambdaFunction> versions = new ArrayList<>(backend.scan(key -> key.startsWith(prefix)));
versions.sort(Comparator.comparingLong(LambdaFunctionStore::versionRank));
return versions;
}
private static long versionRank(LambdaFunction fn) {
String version = fn.getVersion();
if (version == null || version.isEmpty() || !version.chars().allMatch(Character::isDigit)) {
return -1L;
}
return Long.parseLong(version);
}
/**