Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go
T
jschoubben 13550328a6 indexer: a catalog revision per watched branch, branch.<branch>.<n> beside trunk.<n>, and revision answering per branch
The first watched branch's revisions stay trunk.<n>; catalog-revision names its branch, escaped. Nothing yet takes a
non-first branch's source revision in (KeepBranchEntries has no caller).

Builds: design 47 G §291, §614, A-85
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-11 23:22:34 +01:00

67 lines
2.7 KiB
Go

package index
import (
"context"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
)
// Design 47 G A-85, §291: the indexer keeps a catalog revision per watched branch, trunk.<n> for the first and
// branch.<branch>.<n> (the branch escaped) for another, each numbered by its own branch, 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{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")); err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, "feature/x.y", 7, tip("c2")); err != nil {
t.Fatal(err)
}
if err := ix.KeepBranchEntries(ctx, "feature/x.y", 8, tip("c3")); 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{"trunk.1", "branch.feature/x=2ey.1", "branch.feature/x=2ey.2"} {
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 != 2 {
t.Errorf("said %+v, want main 1, then the escaped branch 1 and 2", said)
}
answer := func(branch string, revision int64) meshcatalog.RevisionAnswer {
a, err := Revision(ctx, ix.Revisions, "indexer", "reader", 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 != 1 || a.Entries[0].Commit != "c1" {
t.Errorf("main answered %+v", a)
}
if a := answer("feature/x=2ey", 0); a.Revision.Revision != 2 || a.Revision.Branch != "feature/x.y" || a.Entries[0].Commit != "c3" {
t.Errorf("the branch's newest answered %+v, want its revision 2 at c3", a.Revision)
}
if a := answer("feature/x=2ey", 1); a.Revision.Revision != 1 || a.Entries[0].Commit != "c2" {
t.Errorf("the branch's revision 1 answered %+v", a.Revision)
}
if a := answer("beta", 0); !a.NoneYet {
t.Errorf("a branch with no revision answered %+v, want none-yet", a)
}
}