Drop what a send carried from the node row (migration 0109) and read an image list from the compositions (release 6, issue 1945 B8)

This commit is contained in:
2026-10-24 17:29:03 +02:00
parent b4a62e9e6e
commit 8f90d3ecd6
18 changed files with 148 additions and 125 deletions
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
sdkdelivery "git.novox.be/novox/mesh-sdk/go/delivery"
"net/http"
"net/http/httptest"
"slices"
@@ -229,3 +230,35 @@ func TestImagesAreEveryContainerImageOfTheDeclarationAndOfWhatWasSent(t *testing
t.Errorf("with nothing sent yet: %+v %v", none, err)
}
}
// **`images` reads what a node applies from its compositions** (ADR 0539 §2, issue 1945 B8): the containers among the
// resources of the values kept in its bucket, whatever module and fingerprint; none kept is not known.
func TestImagesAreReadFromTheCompositionsAMachineKeeps(t *testing.T) {
file := json.RawMessage(`{"id":"web.config","type":"file","module":"web","path":"/etc/web","content":"x"}`)
box := json.RawMessage(`{"id":"web.server","type":"container","name":"web","module":"web","image":"registry/web@sha256:` + strings.Repeat("a", 64) + `"}`)
other := json.RawMessage(`{"id":"db.server","type":"container","name":"db","module":"db","image":"registry/db@sha256:` + strings.Repeat("b", 64) + `"}`)
encode := func(module string, fp string, resources ...json.RawMessage) []byte {
v, err := sdkdelivery.EncodeComposed(sdkdelivery.Composed{Node: "anchor", Module: module, FP: fp, Resources: resources})
if err != nil {
t.Fatal(err)
}
return v
}
web := encode("web", sdkdelivery.SourcePrefix2+strings.Repeat("1", 64), file, box)
db := encode("db", sdkdelivery.SourcePrefix2+strings.Repeat("2", 64), other)
got, kept, err := imagesOfCompositions([][]byte{web, db})
if err != nil || !kept || len(got) != 2 {
t.Fatalf("images %+v kept %v: %v", got, kept, err)
}
answer, err := imagesOf("anchor", nil, got, kept)
if err != nil || len(answer.Images) != 2 || !answer.SentKnown {
t.Fatalf("the answer %+v: %v", answer, err)
}
if none, kept, err := imagesOfCompositions(nil); err != nil || kept || len(none) != 0 {
t.Fatalf("no composition kept: %+v %v %v", none, kept, err)
}
if _, _, err := imagesOfCompositions([][]byte{[]byte("nope")}); err == nil {
t.Fatal("an unreadable composition was read as holding no image")
}
}