Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go
T
jschoubben abdd70d918 I2b: one catalog revision per take-in, <branch>.<source>, carrying its movers
TakeInSource takes a gate's source-moved in: the trees of each repository it moves at the
named commit through the seat git, the fingerprints of the modules registered for it, the
movers against the branch's newest catalog revision, and one revision <escaped
branch>.<source> for every branch, the trunk included, numbered by the source and written
once by read before write. The revision carries its movers, and a redelivery whose revision
is kept says take-in.taken again from them, recomputing nothing (H-A-92). It is pinned for
the take-in's pipeline as pipeline.<branch>.<source> in the same write when it has a mover,
none for a take-in with no mover. take-in.taken carries branch, source, revision, call and
the movers' entries alone, under a duplicate id of its branch and source (H-A-31). A
source-moved with no call is refused as the old form (§765).

Only a take-in keeps a catalog revision (H-A-49): the recompute, the build ends' imports and
the start's reconcile keep none, and KeepView, keepEntries, keepTrunkRevision and
PinPipelines go. Another branch than the first is taken in on its newest revision's view.

Builds: design 47 H §743, §749 (the pin in the take-in's write), §765 (the old form); H-A-31, H-A-32, H-A-49, H-A-92

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:56:27 +01:00

113 lines
5.3 KiB
Go

package index
import (
"context"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
)
// Design 47 G A-85, §291, H §743, H-A-32: the indexer keeps a catalog revision per watched branch, <branch>.<source> (the
// branch escaped) for every branch, the first included, numbered by the source revision it was taken in from, and the verb revision answers the
// branch it is asked for; the event names the branch, escaped.
func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
ctx := context.Background()
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC) }}
var said []meshcatalog.CatalogRevisionEvent
ix.SayCatalogRevision = func(_ context.Context, e meshcatalog.CatalogRevisionEvent) error { said = append(said, e); return nil }
reader := meshcatalog.CatalogEntry{Module: "reader", Repository: "novox/r", Commit: "c1", Invokes: []string{RevisionInvoke}, Manifest: map[string]any{}}
tip := func(commit string) map[string]meshcatalog.CatalogEntry {
e := reader
e.Commit = commit
return map[string]meshcatalog.CatalogEntry{"reader": e}
}
if err := ix.KeepBranchEntries(ctx, "main", 5, tip("c1"), nil); err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, "feature/x.y", 7, tip("c2"), nil); err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, "feature/x.y", 8, tip("c3"), nil); err != nil {
t.Fatal(err)
}
names, _ := ix.Revisions.Names(ctx)
have := map[string]bool{}
for _, n := range names {
have[n] = true
}
for _, want := range []string{"main.5", "feature/x=2ey.7", "feature/x=2ey.8"} {
if !have[want] {
t.Errorf("the objects hold %v, want %s", names, want)
}
}
if len(said) != 3 || said[0].Branch != "main" || said[1].Branch != "feature/x=2ey" || said[2].Revision != 8 {
t.Errorf("said %+v, want main 5, then the escaped branch 7 and 8", said)
}
answer := func(branch string, revision int64) meshcatalog.RevisionAnswer {
a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Revision: revision})
if err != nil {
t.Fatalf("revision of %q: %v", branch, err)
}
return a
}
if a := answer("main", 0); a.Revision.Revision != 5 || a.Entries[0].Commit != "c1" {
t.Errorf("main answered %+v", a)
}
if a := answer("feature/x=2ey", 0); a.Revision.Revision != 8 || a.Revision.Branch != "feature/x.y" || a.Entries[0].Commit != "c3" {
t.Errorf("the branch's newest answered %+v, want its revision 8 at c3", a.Revision)
}
if a := answer("feature/x=2ey", 7); a.Revision.Revision != 7 || a.Entries[0].Commit != "c2" {
t.Errorf("the branch's revision 7 answered %+v", a.Revision)
}
if a := answer("beta", 0); !a.NoneYet {
t.Errorf("a branch with no revision answered %+v, want none-yet", a)
}
// A-205: `source` answers the branch's revision taken in from that source revision; a candidate's group alone answers its
// newest revision, whatever its heads.
bySource := func(branch string, source int64) (meshcatalog.RevisionAnswer, error) {
return Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Source: source})
}
if a, err := bySource("main", 5); err != nil || a.Revision.Revision != 5 || a.Entries[0].Commit != "c1" {
t.Errorf("main's source 5 answered %+v (%v)", a.Revision, err)
}
if a, err := bySource("feature/x=2ey", 7); err != nil || a.Revision.Revision != 7 || a.Entries[0].Commit != "c2" {
t.Errorf("the branch's source 7 answered %+v (%v), want its revision 7 at c2", a.Revision, err)
}
if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 8 {
t.Errorf("the branch's source 8 answered %+v (%v)", a.Revision, err)
}
if _, err := bySource("feature/x=2ey", 9); err == nil {
t.Error("a source no revision was taken in from was answered")
}
for i, heads := range []string{"h1", "h2"} {
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: int64(3 + i), Kind: "candidate", Group: "run-ab", Heads: heads}, tip("c9"))
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
}
if a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Group: "run-ab"}); err != nil || a.Revision.Revision != 4 || a.Revision.Heads != "h2" || a.Entries[0].Commit != "c9" {
t.Errorf("a group alone answered %+v (%v), want its newest revision 4", a.Revision, err)
}
if _, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Group: "run-none"}); err == nil {
t.Error("a candidate never kept was answered")
}
}
// H-A-66 (design 47 H §752): the verb revision answers every caller, even one the runtime proved none for and whose module
// declares no invokes.
func TestTheRevisionAnswersEveryCaller(t *testing.T) {
ctx := context.Background()
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)}
engine := meshcatalog.CatalogEntry{Module: "mesh-host", Repository: "novox/h", Commit: "c1", Manifest: map[string]any{}}
if err := ix.KeepBranchEntries(ctx, "main", 5, map[string]meshcatalog.CatalogEntry{"mesh-host": engine}, nil); err != nil {
t.Fatal(err)
}
if a, err := RevisionTool(ix.Revisions, nil).Run(map[string]any{"branch": "main"}); err != nil || a.(meshcatalog.RevisionAnswer).NoneYet {
t.Errorf("an unproven caller answered %+v, %v; want the revision", a, err)
}
}