Fail virtual ansible merges on a short member versions list
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-18 04:02:08 +11:00
parent d6acf7a7e9
commit c1a5feb64e
2 changed files with 16 additions and 1 deletions
+4 -1
View File
@@ -160,9 +160,12 @@ func (e *Engine) ansibleMember(ctx context.Context, member, ns, name string) (*A
}
m.Found = true
m.Refs = append(m.Refs, doc.Data...)
if remote.RepoType == models.RepoTypeLocal || len(doc.Data) == 0 || len(m.Refs) >= doc.Meta.Count {
if remote.RepoType == models.RepoTypeLocal || len(m.Refs) >= doc.Meta.Count {
return m, nil
}
if len(doc.Data) == 0 {
return nil, fmt.Errorf("%s/%s: empty page after %d of %d versions", member, path, len(m.Refs), doc.Meta.Count)
}
}
return nil, fmt.Errorf("%s: more than %d pages of %s.%s versions", member, maxAnsibleMemberPages, ns, name)
}
+12
View File
@@ -139,6 +139,18 @@ func TestAnsibleVersionsFailsClosed(t *testing.T) {
}
}
func TestAnsibleVersionsShortRemote(t *testing.T) {
e := ansibleEngine(func(_ models.Remote, path string) ([]byte, error) {
if strings.Contains(path, "offset=") {
return json.Marshal(map[string]any{"meta": map[string]int{"count": 3}, "data": []any{}})
}
return galaxyPages([]string{"3.0.0", "2.0.0", "1.0.0"}, path)
})
if _, err := e.AnsibleVersions(context.Background(), ansibleVirt("galaxy"), "a", "b"); err == nil || errors.Is(err, ErrNotFound) {
t.Fatalf("empty page before count: want a non-404 error, got %v", err)
}
}
func TestAnsibleVersionRoutesViaVirtual(t *testing.T) {
detail := func(dl string) []byte {
b, _ := json.Marshal(map[string]any{"version": "1.0.0", "download_url": dl, "artifact": map[string]string{"sha256": "ab"}})