From 83e4470757402e1264ef5500103ec88d3e0e10e2 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 23:39:53 +0100 Subject: [PATCH] Design 47 H1 (1), review round 1: a source answers its take-in's revision The revision verb's source input, and the pipeline-wanted that frees pins by it, answer the lowest-numbered revision of a source (the take-in's), never a later re-pin's of the same source. TestIndexerWhole asks the exact first number: the bed seeds main.1 of source 0, so source 10's is 2 (no source is kept twice). Builds: design 47 H-A-213 (1), (4), H-A-211 --- .../mesh-delivery-indexer/takein_integration_test.go | 4 ++-- .../internal/index/catalog_branches_test.go | 7 +++++++ .../internal/index/revision_verb.go | 12 +++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/takein_integration_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/takein_integration_test.go index 0020713c..3055a5ac 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/takein_integration_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/takein_integration_test.go @@ -453,8 +453,8 @@ func TestIndexerWhole(t *testing.T) { first := heard.next(t, "main", 10) r := func(source int64) int64 { return first.Revision + source - 10 } rn := func(source int64) string { return fmt.Sprintf("main.%d", r(source)) } - if len(first.Entries) != 0 || first.Revision <= 0 || first.Source != 10 { - t.Fatalf("the first revision said %+v, want a revision of source 10 with no entries", first) + if len(first.Entries) != 0 || first.Revision != 2 || first.Source != 10 { + t.Fatalf("the first revision said %+v, want revision 2 (the bed's seed is main.1, of source 0) of source 10 with no entries", first) } untilKey(t, ctx, pins, index.PinKey("main", r(10)), absent) diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go index 574de13d..31fe824f 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go @@ -77,6 +77,13 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) { if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 2 { t.Errorf("the branch's source 8 answered %+v (%v)", a.Revision, err) } + // H-A-213: a re-pin's revision of source 8 answers below the take-in's: source 8 answers revision 2. + if _, err := ix.keepBranchEntries(ctx, "feature/x.y", 8, "release of mesh-sdk 0.1.27", tip("c4"), nil); err != nil { + t.Fatal(err) + } + if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 2 || a.Entries[0].Commit != "c3" { + t.Errorf("the branch's source 8 after a re-pin answered %+v (%v), want the take-in's revision 2", a.Revision, err) + } if _, err := bySource("feature/x=2ey", 9); err == nil { t.Error("a source no revision was taken in from was answered") } diff --git a/modules/mesh-delivery-indexer/internal/index/revision_verb.go b/modules/mesh-delivery-indexer/internal/index/revision_verb.go index 20402883..2667fbb4 100644 --- a/modules/mesh-delivery-indexer/internal/index/revision_verb.go +++ b/modules/mesh-delivery-indexer/internal/index/revision_verb.go @@ -167,18 +167,24 @@ func revisionOfSource(ctx context.Context, o Objects, branch string, source int6 } } slices.SortFunc(found, func(a, b int64) int { return int(b - a) }) + // A re-pin or a take-in again keeps a later revision of the same source (H-A-211, H-A-213): the source's own revision is + // the lowest numbered of it, the take-in's. + lowest := "" for _, r := range found { name := RevisionObject(meshcatalog.CatalogRevision{Branch: branch, Revision: r}) rev, _, err := ReadRevision(ctx, o, name) if err != nil { return "", err } - if rev.Source == source { - return name, nil - } if rev.Source < source { break } + if rev.Source == source { + lowest = name + } + } + if lowest != "" { + return lowest, nil } return "", fmt.Errorf("no revision of %q was taken in from the source revision %d", branch, source) }