diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index a9e663a..170a0b3 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -268,6 +268,31 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) { b.mu.Unlock() t.Fatalf("handed %v, want %s and %s", got, lemursKey, nodeKey) } + // ADR 0601 ยง1: the module composed today at the build it runs, as the agent compares it with what runs. The same inputs give + // the digest handed; a changed input (here its manifest's service, as a changed setting would change a file) another; a + // build that cannot be composed (no done build or manifest of it: held) gives none. + c.mu.Lock() + handedDig := c.handed[lemursKey] + c.mu.Unlock() + if dig, ok := c.ComposedToday(ctx, "lemurs", fp); !ok || dig != handedDig { + t.Errorf("composed today at the build it runs: %s %v, want %s", dig, ok, handedDig) + } + if dig, ok := c.ComposedToday(ctx, "lemurs", delivery.SourcePrefix2+strings.Repeat("9", 64)); ok { + t.Errorf("a build that cannot be composed was composed today: %s", dig) + } + chgJSON := strings.Replace(lemurs, `"state":"running"`, `"state":"stopped"`, 1) + chgDigest := delivery.ManifestDigest([]byte(chgJSON)) + chgMan, _ := delivery.EncodeManifest(delivery.Manifest{Module: "lemurs", JSON: chgJSON}) + chgKey, _ := delivery.ManifestsKey(chgDigest) + b.mu.Lock() + b.kv[delivery.ManifestsBucket+"/"+chgKey] = chgMan + b.mu.Unlock() + chgMod, _ := delivery.EncodeModule(delivery.Module{FP2: fp, Manifest: chgDigest, Repository: "novox/x", Commit: "c"}) + c.takeModule(agent.Update{Key: "lemurs", Value: chgMod}) + if dig, ok := c.ComposedToday(ctx, "lemurs", fp); !ok || dig == handedDig { + t.Errorf("composed today with a changed input: %s %v, want another digest than %s", dig, ok, handedDig) + } + c.takeModule(agent.Update{Key: "lemurs", Value: mod}) // Issue 1126, the switch made safe: a bus not answering for a moment (a reload of its accounts) is tried again and // refuses nothing; a pass whose run ended refuses nothing either.