agent: the parts check counts the templates archives a composition was rendered from as fetched (A-481, A-481a)

compose fills Composed.Templates from the resolved manifest's TemplatesDigest; partsDifference adds them to the digests fetched.

Builds: design 47 G A-481, A-481a
This commit is contained in:
2026-11-17 23:44:15 +01:00
parent 179a4a6402
commit 87cfae48b2
7 changed files with 45 additions and 11 deletions
+1 -1
View File
@@ -1631,7 +1631,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo
// A want with parts is applied only when they and the digests its composition fetches agree (design 47 G §524): the
// module keeps running what it has, and the have says which digest differs.
if words := partsDifference(w.Want.Parts, comp.C.Resources); words != "" {
if words := partsDifference(w.Want.Parts, comp.C.Resources, comp.C.Templates); words != "" {
a.mu.Lock()
prev, runs := a.running[module]
a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev}
+18 -7
View File
@@ -364,33 +364,44 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) {
}
// A container's digest is the one after its image's @.
container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","image-seat":"mesh-artifact-store","image-holder":"n1","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, nil); got != "" {
t.Fatalf("a container whose digest is in the parts differs: %q", got)
}
// A-454: an image the manifest pins from outside, by its digest, is no part of the want's parts, and a mesh-built one still is.
upstream := json.RawMessage(`{"id":"web.u","type":"container","name":"web-u","image":"registry@` + d2 + `","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}, nil); got != "" {
t.Fatalf("an upstream image pinned by its digest is a part: %q", got)
}
// And neither is the registry seat's copy of an upstream image, though it is routed through the seat.
mirrored := json.RawMessage(`{"id":"web.m","type":"container","name":"web-m","image":"store:5000/upstream/docker.io/library/registry@` + d1 + `","image-seat":"container-image-registry","image-holder":"n1","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}, nil); got != "" {
t.Fatalf("an upstream copy served through the registry seat is a part: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) {
t.Fatalf("with only an upstream image the mesh-built one is not missing, or the upstream one is named: %q", got)
}
// A-454a: a mesh-built image whose seat holder is not on record carries no image-seat; its digest is in the parts, so it is fetched.
noSeat := json.RawMessage(`{"id":"web.n","type":"container","name":"web-n","image":"store/web@` + d3 + `","module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}, nil); got != "" {
t.Fatalf("a mesh-built image with no image-seat, named by the parts, is not fetched: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}, nil); got != "" {
t.Fatalf("an upstream image beside it is a part: %q", got)
}
// A-481: a templates archive the composition was rendered from is fetched, one the want's parts do not name is a part
// the composition lacks, and the want's digest nothing read stays not fetched.
if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, []string{d1}); got != "" {
t.Fatalf("a templates archive named by the parts and rendered from is fetched: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d1) {
t.Fatalf("a templates archive nothing read stays not fetched: %q", got)
}
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, []string{d1}); !strings.Contains(got, "fetched and not in the want's parts: "+d1) {
t.Fatalf("a templates archive outside the parts differs: %q", got)
}
// A-432: a runtime of its own runs the tool runner's program, which the module's parts do not name.
ownRuntime := json.RawMessage(`{"id":"web.own-runtime","type":"process","name":"web-runtime","source":"store/node-tools","digest":"` + d1 + `","run":["./node-tools"],"module":"web"}`)
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}); got != "" {
if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}, nil); got != "" {
t.Fatalf("a runtime of its own differs from the module's parts: %q", got)
}
}
+6 -1
View File
@@ -60,7 +60,7 @@ func upstreamCopy(image string) bool {
// assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With
// `parts`, the want is applied only when the digest of every resource fetched is among the values of `parts` and every
// value of `parts` is the digest of a resource fetched; otherwise it returns the detail naming each digest.
func partsDifference(parts map[string]string, resources []json.RawMessage) string {
func partsDifference(parts map[string]string, resources []json.RawMessage, templates []string) string {
if len(parts) == 0 {
return ""
}
@@ -69,6 +69,11 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin
inParts[d] = true
}
fetched := map[string]bool{}
// A templates archive the composition was rendered from was read from the artifact store and checked by its digest:
// a part fetched (design 47 G A-481, A-481a).
for _, d := range templates {
fetched[d] = true
}
for _, raw := range resources {
r, err := declaration.ParseResource(raw)
if err != nil {