R4e (mesh-controller): deliver from the builder's keys, ask build-agent only for its own modules, follow the forge's protection for checks, announce the controller's states #441

Merged
mesh-tools merged 39 commits from feat/r4e into main 2026-10-22 22:12:59 +00:00
2 changed files with 37 additions and 6 deletions
Showing only changes of commit dfc2f2aa98 - Show all commits
+7 -6
View File
@@ -160,13 +160,13 @@ func settleKeys(ctx context.Context, inv keyRecords, keys planKeyReads, p *inven
keyTakes.Unlock()
registered := taken
if !registered {
if registered, err = registeredFrom(ctx, inv, m, b); err != nil {
if registered, err = registeredAt(ctx, inv, m, trunk.Commit); err != nil {
return changed, err
}
}
if registered {
at := b.At
s.State, s.BuiltAt, s.Commit, s.Build = "built", &at, b.Commit, id
s.State, s.BuiltAt, s.Commit, s.Build = "built", &at, trunk.Commit, id
s.Made = fmt.Sprintf("taken from the builder's key %s (revision %d), no build asked", short(trunk.FP2), k.Revision)
s.Why = ""
fmt.Printf("%s: %s taken from the builder's key %s\n", p.ID, m, short(trunk.FP2))
@@ -192,9 +192,10 @@ func settleKeys(ctx context.Context, inv keyRecords, keys planKeyReads, p *inven
return changed, nil
}
// registeredFrom says the module's registration stands on the build: the catalogue holds the module at the build's
// commit, or the build was registered as one with an unchanged source (no move).
func registeredFrom(ctx context.Context, inv keyRecords, module string, b inventory.Build) (bool, error) {
// registeredAt says the catalogue holds the module registered at the commit the walk takes it at: its key's take-in
// registered it there, whether with the key's artifacts or, unchanged, with the build it stands on (no move). A key
// recorded at an earlier commit (the same fingerprint at an older merge) is taken in again, to register it here.
func registeredAt(ctx context.Context, inv keyRecords, module, commit string) (bool, error) {
src, err := inv.SourceOf(ctx, module)
if errors.Is(err, inventory.ErrNoSuchModule) {
return false, nil
@@ -202,7 +203,7 @@ func registeredFrom(ctx context.Context, inv keyRecords, module string, b invent
if err != nil {
return false, err
}
return sameCommitID(src.BuiltFrom, b.Commit), nil
return sameCommitID(src.BuiltFrom, commit), nil
}
func sameCommitID(a, b string) bool {
+30
View File
@@ -188,3 +188,33 @@ func TestARefusedTakeInFailsTheWalk(t *testing.T) {
t.Fatalf("a refused take-in did not fail the walk: %s %q", p.State, p.Note)
}
}
// A6: a walk's module whose fingerprint did not change since an earlier merge has its key recorded at that merge's
// commit: the walk takes it in again, so the module is registered at the commit the walk carries, before it is built.
func TestAKeyRecordedAtAnEarlierCommitIsTakenInAgain(t *testing.T) {
t.Cleanup(func() {
keyTakes.Lock()
keyTakes.running, keyTakes.waits, keyTakes.taken = map[string]bool{}, map[string]string{}, map[string]bool{}
keyTakes.Unlock()
})
p, byName := aWalkOfOne("sudo")
askModule(t.Context(), p, "sudo", byName)
fp := "src2:" + strings.Repeat("e", 64)
k := builderkeys.Key{Module: "sudo", Fingerprint: fp, Found: true, Revision: 1, Build: sdkdelivery.BuilderBuild{
State: sdkdelivery.BuildDone, Manifest: strings.Repeat("b", 64), Artifacts: []sdkdelivery.BuiltArtifact{{Name: "a",
Digest: "sha256:1", Reference: "artifact-store://sudo/a/blobs/sha256:1"}}}}
keys := planKeysOf{values: map[string]sdkdelivery.Module{"sudo@c0ffee0123456789": {FP2: fp, Commit: "c0ffee0123456789"}},
keys: map[string]builderkeys.Key{"sudo": k}}
id := keyBuildID(k)
records := recordsOf{builds: map[string]inventory.Build{id: {ID: id, Module: "sudo", Commit: "0ld0ld0ld0ld"}},
sources: map[string]inventory.Source{"sudo": {BuiltFrom: "0ld0ld0ld0ld"}}}
var taken []string
if _, err := settleKeys(t.Context(), records, keys, p, p.Tiers[0], func(m string, _ sdkdelivery.Module, _ string) {
taken = append(taken, m)
}); err != nil {
t.Fatal(err)
}
if s := p.Modules["sudo"]; s.State != "asked" || len(taken) != 1 {
t.Fatalf("a key recorded at an earlier commit settled the walk at that commit: %+v, taken %v", s, taken)
}
}