From d1256ec9410854c99aa7a9c5b286d4e2dc68b7d1 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 12:32:00 +0100 Subject: [PATCH] B4: the released record keeps the origin's branch with its source revision Source revisions are numbered per watched branch today, so a release found by its source revision alone could meet another branch's equal number and fill an importer with the wrong version. The record keeps the branch the reservation came from, and an importer's fill matches both. Builds: design 47 H2 H-A-558 (2), H-A-551 --- .../internal/versions/reserve.go | 19 ++++++++++--------- .../internal/versions/reserve_test.go | 4 ++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/mesh-delivery-builder/internal/versions/reserve.go b/modules/mesh-delivery-builder/internal/versions/reserve.go index 7dc9f58a3..c62df7d04 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve.go @@ -419,10 +419,11 @@ type ReleasedBuild struct { // Withdrawn are the fingerprints whose numbers the released version took over, by the number withdrawn (H-A-226), so a // takeover still answers once the release deleted the series key (H-A-508); absent for a release that took none over. Withdrawn map[string]string `json:"withdrawn,omitempty"` - // Source is the source revision of the catalog revision the released build came from, as its reservation kept it (design 47 - // H2 H-A-551): an importer's build of that source revision is filled from it once the reservation is gone; 0 for a release - // kept before. - Source int64 `json:"source,omitempty"` + // Branch and Source are the source revision of the catalog revision the released build came from, as the key's origin names + // it (its watched branch with it), as its reservation kept them (design 47 H2 H-A-551, H-A-558 (2)): an importer's build of + // that origin is filled from it once the reservation is gone; empty for a release kept before. + Branch string `json:"branch,omitempty"` + Source int64 `json:"source,omitempty"` } // ReleasedFor says whether the builder saw a version released for the build of fingerprint among the module's last releases. @@ -494,7 +495,7 @@ func (r *Reserver) PublishedOf(ctx context.Context, module, artifact, fingerprin // VersionAt answers the version artifact of module is published at from the source revision of branch (design 47 H2 H-A-547 // (3), H-A-551): the standing reservation of that branch and source revision whose artifact a registry seat said published, its -// number not withdrawn, first; else the module's release recorded at that source revision, the newest such. A reservation of +// number not withdrawn, first; else the module's release recorded at that branch and source revision (H-A-558 (2)), the newest such. A reservation of // that origin not yet published answers none, so the importer's build waits for the publish (H-A-521). func (r *Reserver) VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error) { if module == "" || artifact == "" || source <= 0 { @@ -525,7 +526,7 @@ func (r *Reserver) VersionAt(ctx context.Context, module, artifact, branch strin var rec ReleasedRecord if found && json.Unmarshal(raw, &rec) == nil { for i := len(rec.Kept) - 1; i >= 0; i-- { - if rec.Kept[i].Source == source { + if rec.Kept[i].Branch == branch && rec.Kept[i].Source == source { return rec.Kept[i].Version, true, nil } } @@ -534,7 +535,7 @@ func (r *Reserver) VersionAt(ctx context.Context, module, artifact, branch strin } // keepRelease adds a release to the module's record, dropping the oldest past ReleasedKept. -func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests, withdrawn map[string]string, source int64) error { +func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests, withdrawn map[string]string, branch string, source int64) error { n := r.ReleasedKept if n < 1 { n = DefaultReleasedKept @@ -554,7 +555,7 @@ func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version kept = append(kept, k) } } - kept = append(kept, ReleasedBuild{Fingerprint: fingerprint, Version: version, Digests: digests, Withdrawn: maps.Clone(withdrawn), Source: source}) + kept = append(kept, ReleasedBuild{Fingerprint: fingerprint, Version: version, Digests: digests, Withdrawn: maps.Clone(withdrawn), Branch: branch, Source: source}) if len(kept) > n { kept = kept[len(kept)-n:] } @@ -604,7 +605,7 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri continue } if cur.Version == version && cur.Fingerprint != "" && r.Releases != nil { - if err := r.keepRelease(ctx, module, cur.Fingerprint, version, cur.Artifacts, cur.Withdrawn, cur.Source); err != nil { + if err := r.keepRelease(ctx, module, cur.Fingerprint, version, cur.Artifacts, cur.Withdrawn, cur.Branch, cur.Source); err != nil { return gone, fmt.Errorf("the release of %s %s cannot be recorded: %w", module, version, err) } } diff --git a/modules/mesh-delivery-builder/internal/versions/reserve_test.go b/modules/mesh-delivery-builder/internal/versions/reserve_test.go index 174f8393b..d04dd022d 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve_test.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve_test.go @@ -240,6 +240,10 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) { if v := at("main", 41); v != w.Version { t.Errorf("once released, main.41 answers %q, want %s from the release's record", v, w.Version) } + // H-A-558 (2): the record keeps the origin's branch with its source revision, so another branch's equal number never meets it. + if v := at("feat", 41); v != "" { + t.Errorf("once released, feat.41 answers %q, want none", v) + } // One key per module holds the last releases, the oldest dropped (A-456b). for _, fp := range []string{"src2:b1", "src2:b2"} { n, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp})