I10: the indexer's integration tests drive the one model
The whole test starts the indexer against an embedded bus with the gate's source-moved on its kept stream and a durable per watched branch: a first revision with start true and no movers; one revision per take-in carrying its movers, pinned pipeline.<branch>.<source> and said as take-in.taken; the same source-moved given again said from the kept movers with no second revision; pipeline-started pinning, a restart keeping a running pipeline's revision; a take-in on a full store held, said once as take-in.pending and in the state held, taken again on the indexer's own room once pipeline-ended frees a pin; another branch's held take-in leaving main going on, skipped by hand with why in the hand-act log; a branch watched later bound on registration-changed. The packages test takes a mesh-sdk commit in and names mesh-sdk and the module requiring it, not the one requiring nothing of it. The toolchain test drives take-ins; the tests of the forge messages, the verdicts, the pins events of the gate and the view moving between take-ins (H-A-49, H-A-103) go. 7 integration tests (was 13). Builds: design 47 H §743, §744, §749, §768; H-A-12, H-A-30, H-A-49, H-A-50, H-A-90, H-A-92, H-A-97, H-A-102, H-A-103 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+94
-437
@@ -5,45 +5,69 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscompose"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdeliverychecker"
|
||||
|
||||
"mesh-delivery-indexer/internal/fingerprint"
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// TestAMeshSDKMergeMovesOnlyTheModulesImportingAChangedPackage (ADR 0593 §2-§4; D11): the indexer whole against the
|
||||
// bus. Two Go modules of the catalogue whose go.sum names mesh-sdk; their builds end reporting their imports (importer:
|
||||
// buildstep; plain: announce); then mesh-sdk merges a change of buildstep alone, which moves mesh-sdk's version. Within
|
||||
// 20 s the packages key of mesh-sdk/go names the merge with a digest per package, importer gets a new fingerprint, and
|
||||
// plain keeps the one it had, though the version line would have moved it. The forge's tools answer on the bus as the
|
||||
// gitea module's do. A merge of go/ alone before it writes no value of mesh-sdk, whose tree is its named paths'.
|
||||
func TestAMeshSDKMergeMovesOnlyTheModulesImportingAChangedPackage(t *testing.T) {
|
||||
// untilModule follows the catalog revisions until the trunk's view holds name with cond true: read again at each revision kept.
|
||||
func untilModule(t *testing.T, ctx context.Context, js jetstream.JetStream, name string, cond func(meshcatalog.ModulesByModuleValue) bool) meshcatalog.ModulesByModuleValue {
|
||||
t.Helper()
|
||||
obs, err := js.ObjectStore(ctx, newBusObjects(nil, testAccount, index.CatalogRevisionsObjects).bucket())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wctx, cancel := context.WithTimeout(ctx, waitBound)
|
||||
defer cancel()
|
||||
w, err := obs.Watch(wctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = w.Stop() }()
|
||||
var m meshcatalog.ModulesByModuleValue
|
||||
read := func() bool {
|
||||
e, err := revisionView{js: js}.Get(ctx, name)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
m, err = meshcatalogclient.DecodeModule(e.Value())
|
||||
return err == nil && cond(m)
|
||||
}
|
||||
if read() {
|
||||
return m
|
||||
}
|
||||
for range w.Updates() {
|
||||
if read() {
|
||||
return m
|
||||
}
|
||||
}
|
||||
t.Fatalf("modules.%s = %+v after %s", name, m, waitBound)
|
||||
return m
|
||||
}
|
||||
|
||||
// TestASourceRevisionMovingMeshSDKNamesItAndItsImporters (design 47 H §743; A-476a; ADR 0593 §2 to §4): the indexer whole against
|
||||
// the bus. Two Go modules of the catalogue, importer, whose go.sum requires mesh-sdk's Go module, and plain, which requires
|
||||
// nothing of it, are taken in with mesh-sdk as main's first source revision. A source revision moving mesh-sdk to a commit
|
||||
// changing its buildstep package is taken in as one revision whose movers are mesh-sdk and importer, of another repository,
|
||||
// and not plain; the packages key of mesh-sdk/go names that commit with a digest per package.
|
||||
func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) {
|
||||
const (
|
||||
sdkGo = "git.novox.be/novox/mesh-sdk/go"
|
||||
m1, m2 = "1111111111111111111111111111111111111111", "2222222222222222222222222222222222222222"
|
||||
catalogMerge = "3333333333333333333333333333333333333333"
|
||||
goSumContent = "git.novox.be/novox/mesh-sdk/go v0.1.14 h1:x=\ngit.novox.be/novox/mesh-sdk/go v0.1.14/go.mod h1:y=\n"
|
||||
goSumHash = "3b5028f0c1e9bde04dd766abd63eb5931bc516bae695cf46f00abcd8510b0381"
|
||||
sdkRoot1, sdk2 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
)
|
||||
avahi, err := os.ReadFile("../../internal/index/testdata/catalogue-a67f0196-avahi.module.json")
|
||||
@@ -54,20 +78,27 @@ func TestAMeshSDKMergeMovesOnlyTheModulesImportingAChangedPackage(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// mesh-sdk publishes its Go module as a package artifact beside its TypeScript one, as its manifest names it today.
|
||||
sdkManifest = []byte(strings.Replace(string(sdkManifest), `"artifacts": [`, `"artifacts": [{"name": "go", "kind": "package", "language": "go", "paths": ["go"]}, `, 1))
|
||||
named := func(module string) string {
|
||||
return strings.Replace(string(avahi), `"module": "avahi"`, `"module": "`+module+`"`, 1)
|
||||
}
|
||||
// mesh-sdk's go directory at each merge: m2 changes buildstep alone.
|
||||
listing := map[string]map[string]string{
|
||||
m1: {"go.mod": "f1", "go.sum": "f2", "stdio.go": "f3", "announce/announce.go": "f4", "buildstep/step.go": "f5"},
|
||||
m2: {"go.mod": "f1", "go.sum": "f2", "stdio.go": "f3", "announce/announce.go": "f4", "buildstep/step.go": "f6"},
|
||||
// mesh-sdk at each commit: m2 changes buildstep alone, and the objects of its named paths.
|
||||
sdkAt := func(root, step, src string) repoAt {
|
||||
return repoAt{trees: map[string]string{"": root}, files: map[string]string{"module.json": string(sdkManifest), "go/go.mod": "module " + sdkGo + "\n\ngo 1.26\n", "package.json": `{"name": "@novox/mesh-sdk"}`},
|
||||
listing: map[string]map[string]string{"go": {"go.mod": "f1", "go.sum": "f2", "stdio.go": "f3", "announce/announce.go": "f4", "buildstep/step.go": step}},
|
||||
paths: map[string]map[string]string{"": {"go": "9" + src[1:], "src": src, "test": "2222222222222222222222222222222222222222",
|
||||
"package.json": "3333333333333333333333333333333333333333", "package-lock.json": "4444444444444444444444444444444444444444",
|
||||
"tsconfig.json": "5555555555555555555555555555555555555555"}}}
|
||||
}
|
||||
var packages, seatDefs, findings, takeIns jetstream.KeyValue
|
||||
js, ctx, _, modules := startIndexer(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
|
||||
var packages jetstream.KeyValue
|
||||
var heard *takeIns
|
||||
js, ctx, _, _ := startIndexer(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
|
||||
var err error
|
||||
if packages, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.PackagesState), History: index.PackagesHistory}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The state taken, which names each repository's taken commit the packages are published at (ADR 0593 §2).
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.TakenState), History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -83,427 +114,53 @@ func TestAMeshSDKMergeMovesOnlyTheModulesImportingAChangedPackage(t *testing.T)
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
serveForge(t, js.Conn(), listing, goSumContent)
|
||||
// The seat definitions' state (DLV-I17), as the grants part makes it from the manifest.
|
||||
if seatDefs, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.SeatDefinitionsState), History: 5}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// DLV-I19, I20: the indexer's findings and takeins states, and the checker's stream asks with the indexer's durable
|
||||
// consumer, which carries the checker's verdict event.
|
||||
if findings, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: findingsBucket, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if takeIns, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.TakeInsState), History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
forge := serveCommits(t, js.Conn())
|
||||
forge.put(m1, sdkAt(sdkRoot1, "f5", "6666666666666666666666666666666666666666"))
|
||||
forge.put(m2, sdkAt(sdk2, "f6", "7777777777777777777777777777777777777777"))
|
||||
forge.put(catalogMerge, repoAt{trees: map[string]string{"modules/importer": "t1", "modules/plain": "t2"},
|
||||
files: map[string]string{"modules/importer/module.json": named("importer"), "modules/plain/module.json": named("plain"),
|
||||
"modules/importer/go.sum": goSumContent, "modules/plain/go.sum": "golang.org/x/sys v0.1.0 h1:x=\n"}})
|
||||
regs := registerAvahi(t, ctx, js, "main")
|
||||
for _, r := range []meshcatalog.Registration{{V: 1, Module: "importer", Origin: "novox/mesh-catalog", Path: "modules/importer", Branches: []string{"main"}},
|
||||
{V: 1, Module: "plain", Origin: "novox/mesh-catalog", Path: "modules/plain", Branches: []string{"main"}},
|
||||
{V: 1, Module: "mesh-sdk", Origin: "novox/mesh-sdk", Path: ".", Branches: []string{"main"}}} {
|
||||
raw, _ := json.Marshal(r)
|
||||
if _, err := regs.Put(ctx, index.RegistrationKey(r.Module), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
seedBuildModules(t, ctx, js, nil)
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: checkerAsksStream, Subjects: []string{meshdeliverychecker.HolderSubjectVerdict(index.CheckerModule)}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, checkerAsksStream, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-indexer", AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
heard = hearTakeIns(t, js.Conn())
|
||||
})
|
||||
merged := func(repo string, number int, merge string, f forgemsg.Forge) {
|
||||
say := func(source int64, start bool, heads ...meshdelivery.SourceMovedEventHeadsItem) {
|
||||
t.Helper()
|
||||
f.Kind, f.Repository, f.Branch, f.Number, f.Head, f.Merge = forgemsg.ForgeMerged, repo, "feat/x", number, "0123456789abcdef0123456789abcdef01234567", merge
|
||||
data, err := forgemsg.EncodeForge(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.Publish(ctx, "mesh.stream.mesh-delivery-forge-bridge.event.forge."+strings.ReplaceAll(repo, "/", ".")+".merged", data); err != nil {
|
||||
raw, _ := json.Marshal(meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: source, Call: "0123456789abcdef", Start: start, Heads: heads})
|
||||
if _, err := js.Publish(ctx, meshdelivery.SubjectSourceMoved("main", strconv.FormatInt(source, 10)), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
module := func(name string, ok func(meshcatalog.ModulesByModuleValue) bool) meshcatalog.ModulesByModuleValue {
|
||||
t.Helper()
|
||||
var m meshcatalog.ModulesByModuleValue
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if e, err := modules.Get(ctx, name); err == nil {
|
||||
if m, err = meshcatalogclient.DecodeModule(e.Value()); err == nil && ok(m) {
|
||||
return m
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Fatalf("modules.%s = %+v within 20 s", name, m)
|
||||
return m
|
||||
}
|
||||
sdkObjects := func(src string) map[string]map[string]string {
|
||||
return map[string]map[string]string{"": {"src": src, "test": "2222222222222222222222222222222222222222",
|
||||
"package.json": "3333333333333333333333333333333333333333", "package-lock.json": "4444444444444444444444444444444444444444",
|
||||
"tsconfig.json": "5555555555555555555555555555555555555555"}}
|
||||
}
|
||||
// mesh-sdk at m1, then the catalogue's two modules: their go.sum names mesh-sdk, read by the indexer itself.
|
||||
merged("novox/mesh-sdk", 70, m1, forgemsg.Forge{Root: sdkRoot1, Trees: map[string]string{"": sdkRoot1},
|
||||
Manifests: map[string]string{"": string(sdkManifest)}, Paths: sdkObjects("6666666666666666666666666666666666666666")})
|
||||
module("mesh-sdk", func(m meshcatalog.ModulesByModuleValue) bool { return m.Commit == m1 })
|
||||
merged("novox/mesh-catalog", 301, catalogMerge, forgemsg.Forge{Root: "r0",
|
||||
Trees: map[string]string{"modules/importer": "t1", "modules/plain": "t2"},
|
||||
Manifests: map[string]string{"modules/importer": named("importer"), "modules/plain": named("plain")},
|
||||
Locks: map[string]map[string]string{"modules/importer": {"go.sum": goSumHash}, "modules/plain": {"go.sum": goSumHash}}})
|
||||
// The toolchain is reported, and each module gets its fingerprint of the version line.
|
||||
for _, l := range []string{"go", "node"} {
|
||||
if _, err := js.Publish(ctx, "mesh.stream.mesh-build-"+l+".event.toolchain.reported", []byte(`{"node":"n1","language":"`+l+`"}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
hasFP := func(m meshcatalog.ModulesByModuleValue) bool { return m.Fp2 != "" && m.Packages[sdkGo] == m1 }
|
||||
importer, plain := module("importer", hasFP), module("plain", hasFP)
|
||||
|
||||
// Each build ends reporting its imports: kept, no fingerprint moving.
|
||||
for _, b := range []struct {
|
||||
m meshcatalog.ModulesByModuleValue
|
||||
name string
|
||||
imports []string
|
||||
}{{importer, "importer", []string{sdkGo, sdkGo + "/buildstep"}}, {plain, "plain", []string{sdkGo, sdkGo + "/announce"}}} {
|
||||
raw, err := builds.EncodeBuildLogEntry(builds.BuildLogEntry{Event: builds.BuildEndedEvent, Module: b.name, FP: b.m.Fp2,
|
||||
Repository: "novox/mesh-catalog", Directory: "modules/" + b.name, Commit: catalogMerge, Ref: "main", Node: "n1",
|
||||
At: time.Now().UTC(), Outcome: builds.BuildDone, Imports: b.imports})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.Publish(ctx, buscompose.LogSubject(builds.BuilderModule, builds.BuilderLog)+"."+b.name, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fp := b.m.Fp2
|
||||
module(b.name, func(m meshcatalog.ModulesByModuleValue) bool {
|
||||
return m.Inputs2 != nil && m.Inputs2.ImportForm != "" && m.Fp2 == fp
|
||||
})
|
||||
say(10, true, meshdelivery.SourceMovedEventHeadsItem{Repository: "novox/mesh-sdk", Commit: m1}, meshdelivery.SourceMovedEventHeadsItem{Repository: "novox/mesh-catalog", Commit: catalogMerge})
|
||||
heard.next(t, "main", 10)
|
||||
heard.acked(t, "main")
|
||||
untilModule(t, ctx, js, "importer", func(m meshcatalog.ModulesByModuleValue) bool { return m.Fp2 != "" && m.Packages[sdkGo] == m1 })
|
||||
plain := untilModule(t, ctx, js, "plain", func(m meshcatalog.ModulesByModuleValue) bool { return m.Fp2 != "" })
|
||||
if _, ok := plain.Packages[sdkGo]; ok {
|
||||
t.Fatalf("plain requires %s: %+v", sdkGo, plain.Packages)
|
||||
}
|
||||
|
||||
// mesh-sdk merges a change of go/ alone that leaves its own named paths' objects: its value, a TypeScript package's
|
||||
// over its named tree, is not written (issue 1758, ADR 0499 clause 6; the operator, 2026-10-25: a module's value moves
|
||||
// only with the module).
|
||||
const goOnly = "4444444444444444444444444444444444444444"
|
||||
merged("novox/mesh-sdk", 72, goOnly, forgemsg.Forge{Root: "cccccccccccccccccccccccccccccccccccccccc",
|
||||
Trees: map[string]string{"": "cccccccccccccccccccccccccccccccccccccccc"}, Manifests: map[string]string{"": string(sdkManifest)},
|
||||
Paths: sdkObjects("6666666666666666666666666666666666666666")})
|
||||
// mesh-sdk merges a change of buildstep alone (its version moves: src changed too).
|
||||
merged("novox/mesh-sdk", 71, m2, forgemsg.Forge{Root: sdk2, Trees: map[string]string{"": sdk2},
|
||||
Manifests: map[string]string{"": string(sdkManifest)}, Paths: sdkObjects("7777777777777777777777777777777777777777")})
|
||||
sdkAt2 := module("mesh-sdk", func(m meshcatalog.ModulesByModuleValue) bool { return m.Commit == m2 })
|
||||
if sdkAt2.Inputs2 == nil || !strings.HasPrefix(sdkAt2.Inputs2.Tree, fingerprint.NamedTreePrefix) {
|
||||
t.Errorf("mesh-sdk's kept inputs %+v, want a named tree", sdkAt2.Inputs2)
|
||||
say(11, false, meshdelivery.SourceMovedEventHeadsItem{Repository: "novox/mesh-sdk", Commit: m2})
|
||||
taken := heard.next(t, "main", 11)
|
||||
var movers []string
|
||||
for _, e := range taken.Entries {
|
||||
movers = append(movers, e.Module)
|
||||
}
|
||||
history, err := modules.History(ctx, "mesh-sdk")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range history {
|
||||
if m, err := meshcatalogclient.DecodeModule(e.Value()); err == nil && m.Commit == goOnly {
|
||||
t.Errorf("the go/-only merge wrote mesh-sdk's value: %+v", m)
|
||||
}
|
||||
slices.Sort(movers)
|
||||
if !slices.Equal(movers, []string{"importer", "mesh-sdk"}) {
|
||||
t.Errorf("the take-in of mesh-sdk at %s names the movers %v, want mesh-sdk and its importer, not plain", m2, movers)
|
||||
}
|
||||
key, _ := index.PackagesKey(sdkGo)
|
||||
var pub meshcatalog.PackagesByModuleValue
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if e, err := packages.Get(ctx, key); err == nil {
|
||||
if pub, err = index.DecodePublishedPackages(e.Value()); err == nil && pub.Commit == m2 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if pub.Commit != m2 || len(pub.Packages) != 3 {
|
||||
t.Fatalf("packages.%s = %+v within 20 s, want the merge %s with a digest of go, announce and buildstep", key, pub, m2)
|
||||
}
|
||||
// A-476a: mesh-sdk's merge moves importer, of another repository, which imports a package it moved.
|
||||
moved := module("importer", func(m meshcatalog.ModulesByModuleValue) bool { return m.Fp2 != importer.Fp2 })
|
||||
if moved.Packages[sdkGo] != m2 {
|
||||
t.Errorf("importer moved to %+v, want it built against %s", moved.Packages, m2)
|
||||
}
|
||||
// plain imports nothing that changed: its value keeps its fingerprint (one recompute has run: importer moved in it).
|
||||
if now := module("plain", func(meshcatalog.ModulesByModuleValue) bool { return true }); now.Fp2 != plain.Fp2 {
|
||||
t.Errorf("plain moved from %s to %s, though it imports nothing the merge changed", plain.Fp2, now.Fp2)
|
||||
}
|
||||
|
||||
// DLV-I17, I18 (research 081 test 21, design 26): mesh-contracts merges a valid definition, said once; a pull
|
||||
// request's head whose definition does not parse is kept as its entry naming why while the trunk's stays; it closes
|
||||
// and its entry goes.
|
||||
const contractsMerge, badHead = "5555555555555555555555555555555555555555", "6666666666666666666666666666666666666666"
|
||||
git := `{"format":1,"seat":"git","scope":"mesh","grain":"seat-list","decision":"novox/hq ADR 0111","domain":"Core","delivers":"git"}`
|
||||
// No index names the seats: the indexer lists the module's `seats/` directory (ADR 0635 §6, D-I5).
|
||||
seatFiles[contractsMerge] = map[string]string{"seats/git/seat.json": git}
|
||||
seatFiles[badHead] = map[string]string{"seats/git/seat.json": `{"format":1,"seat":"git"}`}
|
||||
// The indexer starts with the two build seats and the seat mesh-module-assigner the fixture keeps (seedBuildModules, its claimant
|
||||
// for A-302) and no other definition: the verb seat-definitions answers them at once (ADR 0636 §4, §8).
|
||||
if got, err := index.SeatDefinitionsOf(jsSource{ctx, seatDefs}, nil, ""); err != nil || func() string {
|
||||
list, _ := got.(index.SeatDefinitionList)
|
||||
var names []string
|
||||
for _, d := range list.Seats {
|
||||
names = append(names, d.Seat)
|
||||
}
|
||||
return strings.Join(names, ",")
|
||||
}() != "mesh-module-assigner,node-build-go,node-build-node" {
|
||||
t.Errorf("seat-definitions of an indexer that kept the build seats and the assigner's alone = %+v, %v", got, err)
|
||||
}
|
||||
contracts := `{"module":"mesh-contracts","version":"1.0","build":{"artifacts":[{"name":"go","kind":"package","language":"go","paths":["go"],"series":"0.1","generated-from":"."}]}}`
|
||||
merged("novox/mesh-contracts", 80, contractsMerge, forgemsg.Forge{Root: "dddddddddddddddddddddddddddddddddddddddd",
|
||||
Trees: map[string]string{"": "dddddddddddddddddddddddddddddddddddddddd"}, Manifests: map[string]string{"": contracts}})
|
||||
entry := func(key string, ok func(index.SeatDefinitionEntry) bool) index.SeatDefinitionEntry {
|
||||
t.Helper()
|
||||
var e index.SeatDefinitionEntry
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if v, err := seatDefs.Get(ctx, key); err == nil && json.Unmarshal(v.Value(), &e) == nil && ok(e) {
|
||||
return e
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s.%s = %+v within 20 s", index.SeatDefinitionsState, key, e)
|
||||
return e
|
||||
}
|
||||
trunk := entry("git.trunk", func(e index.SeatDefinitionEntry) bool { return e.Commit == contractsMerge && e.Digest != "" })
|
||||
pull := func(action string) {
|
||||
t.Helper()
|
||||
data, _ := forgemsg.EncodeForge(forgemsg.Forge{Kind: forgemsg.ForgePull, Action: action, Repository: "novox/mesh-contracts", Branch: "feat/y",
|
||||
Number: 81, Head: badHead, Dirs: []string{""}, DirsKnown: true, Manifests: map[string]string{"": contracts}})
|
||||
if _, err := js.Publish(ctx, "mesh.stream.mesh-delivery-forge-bridge.event.forge.novox.mesh-contracts.pull", data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
pull(forgemsg.PullUpdated)
|
||||
pk := index.SeatDefinitionKey("git", index.SourcePull, "novox/mesh-contracts", 81)
|
||||
if bad := entry(pk, func(e index.SeatDefinitionEntry) bool { return e.Unparsed != "" }); !strings.Contains(bad.Unparsed, "scope") || bad.Definition != nil {
|
||||
t.Errorf("the pull request's entry %+v, want why it does not parse and no definition", bad)
|
||||
}
|
||||
if now := entry("git.trunk", func(index.SeatDefinitionEntry) bool { return true }); now.Digest != trunk.Digest {
|
||||
t.Errorf("the trunk's entry moved to %+v on a pull request's head", now)
|
||||
}
|
||||
pull(forgemsg.PullClosed)
|
||||
for deadline := time.Now().Add(20 * time.Second); ; time.Sleep(50 * time.Millisecond) {
|
||||
if _, err := seatDefs.Get(ctx, pk); errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("%s is kept 20 s after its pull request closed", pk)
|
||||
}
|
||||
}
|
||||
// The seat's events are on the shared events stream like every seat's.
|
||||
info, err := js.Stream(ctx, "EVENTS")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
full, err := info.Info(ctx, jetstream.WithSubjectFilter("mesh.seat."+index.CatalogSeat+".event.seat-definition-changed"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Said on the seat's subject: the trunk's git alone; a pull request's head (unparsed, then closed) says nothing (ADR 0636 §4).
|
||||
if n := full.State.Subjects["mesh.seat."+index.CatalogSeat+".event.seat-definition-changed"]; n != 1 {
|
||||
t.Errorf("seat-definition-changed said %d times, want 1", n)
|
||||
}
|
||||
if m, err := info.GetLastMsgForSubject(ctx, "mesh.seat.mesh-catalog.event.seat-definition-changed"); err != nil ||
|
||||
!strings.Contains(string(m.Data), `"seat":"git"`) || !strings.Contains(string(m.Data), `"source":"trunk"`) || !strings.Contains(string(m.Data), `"digest":"`+trunk.Digest+`"`) {
|
||||
t.Errorf("seat-definition-changed = %v, %v; want {seat, source, digest} of the trunk's git", m, err)
|
||||
}
|
||||
|
||||
// DLV-I20 [i]: a pull request's check verdict naming out-of-step files keeps them; a trunk build end of the builder's log
|
||||
// naming them raises generated-types-out-of-step, and only a clean build end of the same module clears it. DLV-I19 [i]:
|
||||
// indexer_out_of_step answers both, from the states the indexer wrote.
|
||||
verdict, _ := json.Marshal(meshdeliverychecker.VerdictHolderEvent{Repository: "novox/mesh-contracts", Pull: 82, Head: badHead, Verdict: "fail", OutOfStep: []string{"go/seats/git/types.go"}})
|
||||
if _, err := js.Publish(ctx, meshdeliverychecker.HolderSubjectVerdict(index.CheckerModule), verdict); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logEnd := func(outcome string, files ...string) {
|
||||
t.Helper()
|
||||
raw, err := builds.EncodeBuildLogEntry(builds.BuildLogEntry{Event: builds.BuildEndedEvent, Module: "mesh-contracts", FP: "src2:mesh-contracts",
|
||||
Repository: "novox/mesh-contracts", Directory: meshcatalogclient.RootPath, Commit: contractsMerge, Node: "n1", At: time.Now().UTC(), Outcome: outcome})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var e map[string]any
|
||||
_ = json.Unmarshal(raw, &e)
|
||||
if len(files) > 0 {
|
||||
e["out-of-step"] = files // BuildLogEntry.OutOfStep, the builder's field (J3), written by its name here
|
||||
}
|
||||
raw, _ = json.Marshal(e)
|
||||
if _, err := js.Publish(ctx, buscompose.LogSubject(builds.BuilderModule, builds.BuilderLog)+".mesh-contracts", raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
logEnd(builds.BuildFailed, "go/seats/git/types.go")
|
||||
outOfStep := func(want int) []index.OutOfStepRow {
|
||||
t.Helper()
|
||||
var rows []index.OutOfStepRow
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if rows, err = index.OutOfStepOf(testIndexer, jsSource{ctx, seatDefs}, jsSource{ctx, findings}); err == nil && len(rows) == want {
|
||||
return rows
|
||||
}
|
||||
}
|
||||
t.Fatalf("indexer_out_of_step = %+v (%v) within 20 s, want %d rows", rows, err, want)
|
||||
return nil
|
||||
}
|
||||
if rows := outOfStep(2); rows[0].Module != "mesh-contracts" || !strings.Contains(rows[0].Summary, "types.go") || rows[1].Pull != "novox/mesh-contracts#82" {
|
||||
t.Errorf("indexer_out_of_step = %+v, want the trunk's finding and the pull request's files", rows)
|
||||
}
|
||||
// The finding was said by the indexer's finding writer on its own stream (design 47 G §689, A-30): finding-written.
|
||||
findingWritten := func() bool {
|
||||
st, err := js.Stream(ctx, findingsStream)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
info, err := st.Info(ctx)
|
||||
return err == nil && info.State.Msgs > 0
|
||||
}
|
||||
for deadline := time.Now().Add(20 * time.Second); !findingWritten() && time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
}
|
||||
if !findingWritten() {
|
||||
t.Error("the out-of-step finding was written into the findings state but its finding-written was not said on the indexer's findings stream")
|
||||
}
|
||||
logEnd(builds.BuildDone)
|
||||
if rows := outOfStep(1); rows[0].Source != index.SourcePull {
|
||||
t.Errorf("after a clean build end indexer_out_of_step = %+v, want the pull request's files alone", rows)
|
||||
}
|
||||
|
||||
// DLV-I19 [i]: indexer_seat_definitions_again for a pull request, asked through the takeins state as the tool asks it,
|
||||
// reads the head with its own manifest; indexer_seat_definition then answers the pull request's entry beside the trunk's.
|
||||
const goodHead = "7777777777777777777777777777777777777777"
|
||||
seatFiles[goodHead] = map[string]string{"module.json": contracts,
|
||||
"seats/git/seat.json": strings.Replace(git, "ADR 0111", "ADR 0200", 1)}
|
||||
key, value, err := index.NewSeatDefinitionsAgain("mesh-contracts", 83, goodHead, "the forge did not answer", "person.op", time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := takeIns.Put(ctx, key, value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p83 := index.SeatDefinitionKey("git", index.SourcePull, "novox/mesh-contracts", 83)
|
||||
entry(p83, func(e index.SeatDefinitionEntry) bool { return e.Commit == goodHead && e.Digest != "" })
|
||||
if a, err := index.SeatDefinitionOf(jsSource{ctx, seatDefs}, nil, "git", "novox/mesh-contracts", 83); err != nil || a.Answered != "novox/mesh-contracts#83" ||
|
||||
a.Entry.Commit != goodHead || a.Trunk == nil || a.Trunk.Digest != trunk.Digest {
|
||||
t.Errorf("indexer_seat_definition of the pull request = %+v, %v", a, err)
|
||||
}
|
||||
|
||||
// ADR 0636 §5, D-I3, D-I5: a seat of the mesh's own contracts is taken only from its domain's contracts module, and a move
|
||||
// there is a handover in either merge order of the two trunks. `wants` (Provisioning) and `vault` (Identity and access) are
|
||||
// held by mesh-contracts as an older indexer kept them.
|
||||
seat := func(name, domain string) string {
|
||||
return `{"format":1,"seat":"` + name + `","scope":"mesh","grain":"seat-list","decision":"d","domain":"` + domain + `"}`
|
||||
}
|
||||
for name, domain := range map[string]string{"wants": "Provisioning", "vault": "Identity and access"} {
|
||||
var d seatdef.Definition
|
||||
if err := json.Unmarshal([]byte(seat(name, domain)), &d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := json.Marshal(d)
|
||||
held, _ := json.Marshal(index.SeatDefinitionEntry{Seat: name, Source: index.SourceTrunk, Repository: "novox/mesh-contracts", Module: "mesh-contracts",
|
||||
Directory: ".", Commit: "old", Digest: "old-" + name, Definition: raw})
|
||||
if _, err := seatDefs.Put(ctx, name+".trunk", held); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
const dropped, provisioningDef, identity = "8888888888888888888888888888888888888888", "9999999999999999999999999999999999999999", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
seatFiles[dropped] = map[string]string{"seats/git/seat.json": git} // mesh-contracts without wants and vault
|
||||
seatFiles[provisioningDef] = map[string]string{"seats/wants/seat.json": seat("wants", "Provisioning")}
|
||||
seatFiles[identity] = map[string]string{"seats/vault/seat.json": seat("vault", "Identity and access")}
|
||||
domainModule := func(name string) string {
|
||||
return strings.Replace(contracts, `"mesh-contracts"`, `"`+name+`"`, 1)
|
||||
}
|
||||
// Order 1: the domain's module merges first (its own repository) and takes wants over.
|
||||
merged("novox/mesh-provisioning", 90, provisioningDef, forgemsg.Forge{Root: "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
|
||||
Trees: map[string]string{"": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}, Manifests: map[string]string{"": domainModule("mesh-provisioning-contracts")}})
|
||||
entry("wants.trunk", func(e index.SeatDefinitionEntry) bool {
|
||||
return e.Module == "mesh-provisioning-contracts" && e.Commit == provisioningDef
|
||||
untilKey(t, ctx, packages, key, func(v []byte) bool {
|
||||
pub, err := index.DecodePublishedPackages(v)
|
||||
return v != nil && err == nil && pub.Commit == m2 && len(pub.Packages) == 3
|
||||
})
|
||||
// mesh-contracts then drops both: wants stays the domain module's; vault, whose module has not merged yet, is kept.
|
||||
merged("novox/mesh-contracts", 91, dropped, forgemsg.Forge{Root: "dddddddddddddddddddddddddddddddddddddddd",
|
||||
Trees: map[string]string{"": "dddddddddddddddddddddddddddddddddddddddd"}, Manifests: map[string]string{"": contracts}})
|
||||
entry("git.trunk", func(e index.SeatDefinitionEntry) bool { return e.Commit == contractsMerge })
|
||||
for _, k := range []string{"wants.trunk", "vault.trunk"} {
|
||||
if _, err := seatDefs.Get(ctx, k); err != nil {
|
||||
t.Fatalf("%s is gone after mesh-contracts dropped it: %v", k, err)
|
||||
}
|
||||
}
|
||||
// Order 2 completed: the identity module merges afterwards and takes vault over.
|
||||
merged("novox/mesh-identity", 92, identity, forgemsg.Forge{Root: "ffffffffffffffffffffffffffffffffffffffff",
|
||||
Trees: map[string]string{"": "ffffffffffffffffffffffffffffffffffffffff"}, Manifests: map[string]string{"": domainModule("mesh-identity-and-access-contracts")}})
|
||||
entry("vault.trunk", func(e index.SeatDefinitionEntry) bool {
|
||||
return e.Module == "mesh-identity-and-access-contracts" && e.Commit == identity
|
||||
})
|
||||
// The seat list the verb answers: every trunk seat with its digest, the handed-over ones included, never a pull request's.
|
||||
list, err := index.SeatDefinitionsOf(jsSource{ctx, seatDefs}, nil, "")
|
||||
raw, _ := json.Marshal(list)
|
||||
for _, want := range []string{`"seat":"git"`, `"seat":"vault"`, `"seat":"wants"`} {
|
||||
if err != nil || !strings.Contains(string(raw), want) || strings.Contains(string(raw), `"source":"pull"`) {
|
||||
t.Errorf("seat-definitions = %s, %v; want %s", raw, err, want)
|
||||
}
|
||||
}
|
||||
// D-29: the indexer reads its own seat list as every part does, so the judge judges against the seats it said: the
|
||||
// handed-over ones are known to catalogue (the test's seat list holds neither).
|
||||
for deadline := time.Now().Add(10 * time.Second); ; time.Sleep(20 * time.Millisecond) {
|
||||
_, wants := catalogue.SeatNamed("wants")
|
||||
_, vault := catalogue.SeatNamed("vault")
|
||||
if wants && vault {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("the indexer's judge does not know the seats it said: wants %v, vault %v", wants, vault)
|
||||
}
|
||||
}
|
||||
// Said: git, wants and vault changed once each beyond the first count; no removal for the handed-over seats.
|
||||
if m, err := info.GetLastMsgForSubject(ctx, "mesh.seat.mesh-catalog.event.seat-definition-removed"); err == nil {
|
||||
t.Errorf("a handover said seat-definition-removed: %s", m.Data)
|
||||
}
|
||||
}
|
||||
|
||||
// seatFiles are mesh-contracts' files by commit, as the seat git's file answers them.
|
||||
var seatFiles = map[string]map[string]string{}
|
||||
|
||||
// serveForge answers the seat git's verbs on the bus as its holder, the forge module, does (milestone 47/G W4.15): trees
|
||||
// (the trees of a commit, or with files the blobs under each directory of mesh-sdk's listing at that commit), file (every
|
||||
// go.sum holds goSum; a seat definition the commit does not hold is absent) and contains.
|
||||
func serveForge(t *testing.T, nc *nats.Conn, listing map[string]map[string]string, goSum string) {
|
||||
t.Helper()
|
||||
reply := func(m *nats.Msg, result any) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": result, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
trees, err := nc.Subscribe("mesh.seat.git.tool.trees", func(m *nats.Msg) {
|
||||
var a git.TreesInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
out := git.TreesAnswer{Root: "r0", Trees: map[string]string{}, Commit: a.Commit}
|
||||
if len(a.Files) > 0 {
|
||||
out.Files = map[string]map[string]string{}
|
||||
for _, d := range a.Files {
|
||||
if a.Repository == "novox/mesh-sdk" && d == "go" && listing[a.Commit] != nil {
|
||||
out.Files[d] = listing[a.Commit]
|
||||
}
|
||||
if fs, ok := seatFiles[a.Commit]; ok && strings.HasPrefix(d, "seats") { // a contracts module's seats/ directory (D-I5)
|
||||
out.Files[d] = map[string]string{}
|
||||
for p := range fs {
|
||||
if rel, ok := strings.CutPrefix(p, d+"/"); ok {
|
||||
out.Files[d][rel] = "blob"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reply(m, out)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
file, err := nc.Subscribe("mesh.seat.git.tool.file", func(m *nats.Msg) {
|
||||
var a git.FileInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
if _, held := seatFiles[a.Ref]; held { // the seat definitions (DLV-I17): a path the commit does not hold is absent
|
||||
if v, ok := seatFiles[a.Ref][a.Path]; ok {
|
||||
reply(m, git.FileAnswer{Path: a.Path, Ref: a.Ref, Content: v})
|
||||
} else {
|
||||
reply(m, git.FileAnswer{Path: a.Path, Ref: a.Ref, Absent: true})
|
||||
}
|
||||
return
|
||||
}
|
||||
reply(m, git.FileAnswer{Path: a.Path, Ref: a.Ref, Content: goSum})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Each merge here is newer than the one before: a commit is in another only when it is that commit.
|
||||
contains, err := nc.Subscribe("mesh.seat.git.tool.contains", func(m *nats.Msg) {
|
||||
var a git.ContainsInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
reply(m, git.ContainsAnswer{Commit: a.Commit, In: a.In, Contains: a.Commit == a.In})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = trees.Unsubscribe(); _ = file.Unsubscribe(); _ = contains.Unsubscribe() })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,559 @@
|
||||
//go:build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// waitBound is how long a bed waits for what the indexer says or writes; a wait is on the bus (an event, a watch), never a sleep.
|
||||
const waitBound = 20 * time.Second
|
||||
|
||||
// watchBranch makes the indexer's durable of one watched branch on the gate's source-moved, as the grants part makes it (design
|
||||
// 47 H §743, H-A-30, H-A-90): <node>_<indexer>_<escaped branch>, one message at a time, its wait for an acknowledgement longer
|
||||
// than any hold (§744).
|
||||
func watchBranch(t *testing.T, ctx context.Context, js jetstream.JetStream, branch string) {
|
||||
t.Helper()
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, meshdelivery.StreamSourceMoved, jetstream.ConsumerConfig{
|
||||
Durable: "n1_mesh-delivery-indexer_" + keys.EscapeName(branch), AckPolicy: jetstream.AckExplicitPolicy, MaxAckPending: 1, AckWait: time.Hour,
|
||||
FilterSubjects: []string{meshdelivery.SubjectSourceMoved(keys.EscapeName(branch), "*")}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// repoAt is one repository at one commit as the seat git answers it: each module directory's tree, and its files by path.
|
||||
type repoAt struct {
|
||||
trees map[string]string
|
||||
files map[string]string
|
||||
listing map[string]map[string]string // by directory, the blobs under it (the trees' files)
|
||||
paths map[string]map[string]string // by directory, the objects of its named paths
|
||||
}
|
||||
|
||||
// forgeCommits answers the seat git's trees and file for the commits it holds, as the forge module does (A-190); a commit it
|
||||
// does not hold is refused, a read the take-in cannot make.
|
||||
type forgeCommits struct {
|
||||
mu sync.Mutex
|
||||
at map[string]repoAt
|
||||
}
|
||||
|
||||
func (f *forgeCommits) put(commit string, r repoAt) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.at[commit] = r
|
||||
}
|
||||
|
||||
func (f *forgeCommits) get(commit string) (repoAt, bool) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
r, ok := f.at[commit]
|
||||
return r, ok
|
||||
}
|
||||
|
||||
// serveCommits serves the seat git's trees and file on the bus from what put holds.
|
||||
func serveCommits(t *testing.T, nc *nats.Conn) *forgeCommits {
|
||||
t.Helper()
|
||||
f := &forgeCommits{at: map[string]repoAt{}}
|
||||
reply := func(m *nats.Msg, result any) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": result, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
refuse := func(m *nats.Msg, commit string) {
|
||||
raw, _ := json.Marshal(map[string]any{"error": "the forge holds no commit " + commit})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
trees, err := nc.Subscribe("mesh.seat.git.tool.trees", func(m *nats.Msg) {
|
||||
var a git.TreesInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
r, ok := f.get(a.Commit)
|
||||
if !ok {
|
||||
refuse(m, a.Commit)
|
||||
return
|
||||
}
|
||||
out := git.TreesAnswer{Root: "r-" + a.Commit[:8], Commit: a.Commit, Trees: r.trees}
|
||||
for _, d := range a.Files {
|
||||
if l, ok := r.listing[d]; ok {
|
||||
if out.Files == nil {
|
||||
out.Files = map[string]map[string]string{}
|
||||
}
|
||||
out.Files[d] = l
|
||||
}
|
||||
}
|
||||
for d := range a.Paths {
|
||||
if p, ok := r.paths[d]; ok {
|
||||
if out.Paths == nil {
|
||||
out.Paths = map[string]map[string]string{}
|
||||
}
|
||||
out.Paths[d] = p
|
||||
}
|
||||
}
|
||||
reply(m, out)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
file, err := nc.Subscribe("mesh.seat.git.tool.file", func(m *nats.Msg) {
|
||||
var a git.FileInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
r, ok := f.get(a.Ref)
|
||||
if !ok {
|
||||
refuse(m, a.Ref)
|
||||
return
|
||||
}
|
||||
if c, held := r.files[a.Path]; held {
|
||||
reply(m, git.FileAnswer{Path: a.Path, Ref: a.Ref, Content: c})
|
||||
return
|
||||
}
|
||||
reply(m, git.FileAnswer{Path: a.Path, Ref: a.Ref, Absent: true})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Each commit here is newer than the one before: a commit is in another only when it is that commit.
|
||||
contains, err := nc.Subscribe("mesh.seat.git.tool.contains", func(m *nats.Msg) {
|
||||
var a git.ContainsInput
|
||||
_ = json.Unmarshal(m.Data, &a)
|
||||
reply(m, git.ContainsAnswer{Commit: a.Commit, In: a.In, Contains: a.Commit == a.In})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = trees.Unsubscribe(); _ = file.Unsubscribe(); _ = contains.Unsubscribe() })
|
||||
return f
|
||||
}
|
||||
|
||||
// catalogueAt is the catalogue repository with avahi's real manifest in modules/avahi at the tree given.
|
||||
func catalogueAt(t *testing.T, tree string) repoAt {
|
||||
t.Helper()
|
||||
manifest, err := os.ReadFile("../../internal/index/testdata/catalogue-a67f0196-avahi.module.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return repoAt{trees: map[string]string{"modules/avahi": tree},
|
||||
files: map[string]string{"modules/avahi/module.json": string(manifest), "modules/avahi/go.sum": "golang.org/x/sys v0.1.0 h1:x=\n"}}
|
||||
}
|
||||
|
||||
// registerAvahi keeps avahi's registration from the catalogue, watching branches, as the registrations part writes it.
|
||||
func registerAvahi(t *testing.T, ctx context.Context, js jetstream.JetStream, branches ...string) jetstream.KeyValue {
|
||||
t.Helper()
|
||||
regs, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.RegistrationsState), History: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg, _ := json.Marshal(meshcatalog.Registration{V: 1, Module: "avahi", Origin: "novox/mesh-catalog", Path: "modules/avahi", Branches: branches})
|
||||
if _, err := regs.Put(ctx, index.RegistrationKey("avahi"), reg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return regs
|
||||
}
|
||||
|
||||
// sayMoved says the gate's source-moved of one source revision of a branch, moving the catalogue to commit.
|
||||
func sayMoved(t *testing.T, ctx context.Context, js jetstream.JetStream, branch string, source int64, commit string, start bool) {
|
||||
t.Helper()
|
||||
e := meshdelivery.SourceMovedEvent{V: 1, Branch: branch, Source: source, Call: "0123456789abcdef", Start: start,
|
||||
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: "novox/mesh-catalog", Commit: commit}}}
|
||||
if start {
|
||||
e.Call = "seed.lead.20261120"
|
||||
}
|
||||
raw, _ := json.Marshal(e)
|
||||
if _, err := js.Publish(ctx, meshdelivery.SubjectSourceMoved(keys.EscapeName(branch), strconv.FormatInt(source, 10)), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// takeIns hears what the indexer says of its take-ins: every take-in.taken and take-in.pending, in the order said.
|
||||
type takeIns struct {
|
||||
taken chan meshcatalog.TakeInTaken
|
||||
pending chan meshcatalog.TakeInPending
|
||||
acks chan string // the escaped branch whose source-moved the indexer acknowledged
|
||||
}
|
||||
|
||||
func hearTakeIns(t *testing.T, nc *nats.Conn) *takeIns {
|
||||
t.Helper()
|
||||
h := &takeIns{taken: make(chan meshcatalog.TakeInTaken, 64), pending: make(chan meshcatalog.TakeInPending, 64), acks: make(chan string, 64)}
|
||||
prefix := "$JS.ACK." + meshdelivery.StreamSourceMoved + "."
|
||||
acks, err := nc.Subscribe(prefix+"*.>", func(m *nats.Msg) {
|
||||
consumer, _, _ := strings.Cut(strings.TrimPrefix(m.Subject, prefix), ".")
|
||||
if branch, ok := strings.CutPrefix(consumer, "n1_mesh-delivery-indexer_"); ok && (string(m.Data) == "+ACK" || len(m.Data) == 0) {
|
||||
h.acks <- branch
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = acks.Unsubscribe() })
|
||||
sub, err := nc.Subscribe("mesh.mod."+testIndexer+".event.take-in.*", func(m *nats.Msg) {
|
||||
switch m.Subject {
|
||||
case "mesh.mod." + testIndexer + ".event.take-in.taken":
|
||||
var e meshcatalog.TakeInTaken
|
||||
if json.Unmarshal(m.Data, &e) == nil {
|
||||
h.taken <- e
|
||||
}
|
||||
case "mesh.mod." + testIndexer + ".event.take-in.pending":
|
||||
var e meshcatalog.TakeInPending
|
||||
if json.Unmarshal(m.Data, &e) == nil {
|
||||
h.pending <- e
|
||||
}
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
return h
|
||||
}
|
||||
|
||||
// next is the next take-in.taken said, which must be of that branch and source.
|
||||
func (h *takeIns) next(t *testing.T, branch string, source int64) meshcatalog.TakeInTaken {
|
||||
t.Helper()
|
||||
select {
|
||||
case e := <-h.taken:
|
||||
if e.Branch != branch || e.Source != source {
|
||||
t.Fatalf("take-in.taken of %s %d said, want %s %d first: %+v", e.Branch, e.Source, branch, source, e)
|
||||
}
|
||||
return e
|
||||
case <-time.After(waitBound):
|
||||
t.Fatalf("no take-in.taken of %s %d within %s", branch, source, waitBound)
|
||||
}
|
||||
return meshcatalog.TakeInTaken{}
|
||||
}
|
||||
|
||||
// acked waits for the indexer's acknowledgement of a source-moved of branch: the next one heard must be of that branch.
|
||||
func (h *takeIns) acked(t *testing.T, branch string) {
|
||||
t.Helper()
|
||||
select {
|
||||
case b := <-h.acks:
|
||||
if b != keys.EscapeName(branch) {
|
||||
t.Fatalf("a source-moved of %s acknowledged, want %s", b, branch)
|
||||
}
|
||||
case <-time.After(waitBound):
|
||||
t.Fatalf("no source-moved of %s acknowledged within %s", branch, waitBound)
|
||||
}
|
||||
}
|
||||
|
||||
// nextPending is the next take-in.pending said, which must be of that branch and source.
|
||||
func (h *takeIns) nextPending(t *testing.T, branch string, source int64) meshcatalog.TakeInPending {
|
||||
t.Helper()
|
||||
select {
|
||||
case e := <-h.pending:
|
||||
if e.Branch != branch || e.Source != source || e.Why == "" {
|
||||
t.Fatalf("take-in.pending %+v said, want %s %d with why", e, branch, source)
|
||||
}
|
||||
return e
|
||||
case <-time.After(waitBound):
|
||||
t.Fatalf("no take-in.pending of %s %d within %s", branch, source, waitBound)
|
||||
}
|
||||
return meshcatalog.TakeInPending{}
|
||||
}
|
||||
|
||||
// untilKey watches one key until cond holds of its value (nil when absent or deleted).
|
||||
func untilKey(t *testing.T, ctx context.Context, kv jetstream.KeyValue, key string, cond func([]byte) bool) {
|
||||
t.Helper()
|
||||
wctx, cancel := context.WithTimeout(ctx, waitBound)
|
||||
defer cancel()
|
||||
w, err := kv.Watch(wctx, key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = w.Stop() }()
|
||||
var last []byte
|
||||
for e := range w.Updates() {
|
||||
switch {
|
||||
case e == nil: // the initial values are read
|
||||
case e.Operation() == jetstream.KeyValuePut:
|
||||
last = e.Value()
|
||||
default:
|
||||
last = nil
|
||||
}
|
||||
if cond(last) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s.%s is %s after %s, not what the bed waits for", kv.Bucket(), key, last, waitBound)
|
||||
}
|
||||
|
||||
// untilRevisionGone watches the catalog revisions until the object name is no longer kept.
|
||||
func untilRevisionGone(t *testing.T, ctx context.Context, js jetstream.JetStream, name string) {
|
||||
t.Helper()
|
||||
obs, err := js.ObjectStore(ctx, newBusObjects(nil, testAccount, index.CatalogRevisionsObjects).bucket())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wctx, cancel := context.WithTimeout(ctx, waitBound)
|
||||
defer cancel()
|
||||
w, err := obs.Watch(wctx, jetstream.IgnoreDeletes())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = w.Stop() }()
|
||||
if _, err := obs.GetInfo(ctx, name); errors.Is(err, jetstream.ErrObjectNotFound) {
|
||||
return
|
||||
}
|
||||
for range w.Updates() {
|
||||
if _, err := obs.GetInfo(ctx, name); errors.Is(err, jetstream.ErrObjectNotFound) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("the catalog revision %s is still kept after %s", name, waitBound)
|
||||
}
|
||||
|
||||
// setCap sets the cap of the catalog revisions' object store, as its definition's keep would.
|
||||
func setCap(t *testing.T, ctx context.Context, js jetstream.JetStream, capacity int64) {
|
||||
t.Helper()
|
||||
if _, err := js.UpdateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: newBusObjects(nil, testAccount, index.CatalogRevisionsObjects).bucket(), MaxBytes: capacity}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// sayPipeline says the runner's pipeline-started or pipeline-ended of a take-in's pipeline <branch>.<source> on its revision.
|
||||
func sayPipeline(t *testing.T, ctx context.Context, js jetstream.JetStream, ended bool, branch string, source int64) {
|
||||
t.Helper()
|
||||
b, s := keys.EscapeName(branch), strconv.FormatInt(source, 10)
|
||||
pipeline := b + "." + s
|
||||
if !ended {
|
||||
raw, _ := json.Marshal(meshpipelinerunner.PipelineStarted{V: 1, Pipeline: pipeline, Branch: branch, Source: source, Revision: source,
|
||||
Movers: []meshpipelinerunner.Mover{{Module: "avahi", Tier: 1}}})
|
||||
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineStarted(b, s), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
raw, _ := json.Marshal(meshpipelinerunner.PipelineEnded{V: 1, Pipeline: pipeline, Branch: branch, Source: source, Revision: source,
|
||||
Outcome: meshpipelinerunner.PipelineEndedOutcomePassed, Movers: []meshpipelinerunner.MoverEnded{{Module: "avahi", Steps: []meshpipelinerunner.StepResult{}, Tier: 1}}})
|
||||
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineEnded(b, s), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// pinned is whether a pins value names the record.
|
||||
func pinned(record string) func([]byte) bool {
|
||||
return func(v []byte) bool {
|
||||
var p index.PinValue
|
||||
return v != nil && json.Unmarshal(v, &p) == nil && len(p.Records) == 1 && p.Records[0] == record
|
||||
}
|
||||
}
|
||||
|
||||
func absent(v []byte) bool { return v == nil }
|
||||
|
||||
// TestIndexerWhole starts the indexer whole (its entry, run, with MESH_BROKER_FILE) against an embedded bus, with avahi registered
|
||||
// from the catalogue watching main and beta, the go toolchain reported, the seat git served and the streams and durables the
|
||||
// grants part makes (design 47 H §743, §744, §749, §768; H-A-12, H-A-30, H-A-50, H-A-90, H-A-92, H-A-97):
|
||||
//
|
||||
// - main's first source revision (start true) is taken in with no mover and pins nothing; the next, moving avahi's tree, is one
|
||||
// revision main.11 carrying avahi as its one mover, pinned pipeline.main.11, said once as take-in.taken; the same source-moved
|
||||
// given again says the same from the kept movers and keeps no second revision;
|
||||
// - pipeline-started of main.12 pins it, a restart keeps main.11 while its pipeline runs and removes main.10;
|
||||
// - with the store full, main.13 is held, said once as take-in.pending and written in the state held; nothing takes it in on a
|
||||
// timer: main.11's pipeline-ended frees its pin, the revision goes, the indexer says its room and takes main.13 in on it;
|
||||
// - beta's take-in whose commit the forge cannot read is held while main's next goes on; the hand skip, with why, is recorded in
|
||||
// the hand-act log before it is asked, and take-in.taken says it skipped;
|
||||
// - a branch watched later is bound on registration-changed and its first revision taken in.
|
||||
func TestIndexerWhole(t *testing.T) {
|
||||
const (
|
||||
c10, c11, c12, c13 = "1010101010101010101010101010101010101010", "1111111111111111111111111111111111111111", "1212121212121212121212121212121212121212", "1313131313131313131313131313131313131313"
|
||||
unread = "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"
|
||||
)
|
||||
var forge *forgeCommits
|
||||
var heard *takeIns
|
||||
var pins, held, takeinsKV, regs jetstream.KeyValue
|
||||
js, ctx, _, _, restart := startIndexerRun(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
|
||||
heard = hearTakeIns(t, js.Conn())
|
||||
forge = serveCommits(t, js.Conn())
|
||||
for commit, tree := range map[string]string{c10: "t10", c11: "t11", c12: "t12", c13: "t13"} {
|
||||
forge.put(commit, catalogueAt(t, tree))
|
||||
}
|
||||
var err error
|
||||
for _, b := range []struct {
|
||||
state string
|
||||
kv *jetstream.KeyValue
|
||||
}{{index.HeldState, &held}, {index.TakeInsState, &takeinsKV}} {
|
||||
if *b.kv, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, b.state), History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
regs = registerAvahi(t, ctx, js, "main", "beta")
|
||||
tc, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.ToolchainsBucket("mesh-build-go"), History: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key, _ := index.ToolchainKey("n1", "go")
|
||||
value, _ := index.EncodeToolchain(nodebuildgo.Toolchain{Language: "go", Version: "go1.27.1", Recipe: "1", At: ptr(time.Now())})
|
||||
if _, err := tc.Put(ctx, key, value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seedBuildModules(t, ctx, js, nil)
|
||||
})
|
||||
var err error
|
||||
if pins, err = js.KeyValue(ctx, index.Bucket(testIndexer, index.PinsState)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
objects := newBusObjects(js, testAccount, index.CatalogRevisionsObjects)
|
||||
|
||||
// The first revision: no mover, no pin; its entries are the base.
|
||||
sayMoved(t, ctx, js, "main", 10, c10, true)
|
||||
if first := heard.next(t, "main", 10); len(first.Entries) != 0 || first.Revision != 10 {
|
||||
t.Fatalf("the first revision said %+v, want revision 10 with no entries", first)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 10), absent)
|
||||
|
||||
// One take-in, one revision carrying its movers, pinned for its pipeline; said again from the kept movers.
|
||||
sayMoved(t, ctx, js, "main", 11, c11, false)
|
||||
taken := heard.next(t, "main", 11)
|
||||
if len(taken.Entries) != 1 || taken.Entries[0].Module != "avahi" || taken.Entries[0].Commit != c11 || taken.Entries[0].Fingerprint == "" ||
|
||||
taken.Entries[0].Repository != "novox/mesh-catalog" || taken.Revision != 11 || taken.Call == "" {
|
||||
t.Fatalf("take-in.taken of main 11 = %+v, want avahi at %s as its one mover", taken, c11)
|
||||
}
|
||||
rev, _, err := index.ReadRevision(ctx, objects, "main.11")
|
||||
if err != nil || len(rev.Movers) != 1 || rev.Movers[0] != taken.Entries[0] {
|
||||
t.Fatalf("main.11 = %+v (%v), want it kept carrying the movers said", rev, err)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), pinned("pipeline.main.11"))
|
||||
info, err := objects.open(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := info.GetInfo(ctx, "main.11")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayMoved(t, ctx, js, "main", 11, c11, false)
|
||||
if again := heard.next(t, "main", 11); len(again.Entries) != 1 || again.Entries[0] != taken.Entries[0] || again.Revision != 11 {
|
||||
t.Errorf("the source-moved given again said %+v, want the kept movers %+v", again, taken.Entries)
|
||||
}
|
||||
if after, err := info.GetInfo(ctx, "main.11"); err != nil || after.NUID != before.NUID {
|
||||
t.Errorf("main.11 was written again (%v): a source-moved given again keeps no second revision", err)
|
||||
}
|
||||
|
||||
// pipeline-started pins its revision; a restart while main.11's pipeline runs keeps it, and the judge at the start removes
|
||||
// main.10, which nothing pins and which is no longer current.
|
||||
sayMoved(t, ctx, js, "main", 12, c12, false)
|
||||
heard.next(t, "main", 12)
|
||||
if err := pins.Delete(ctx, index.PinKey("main", 12)); err != nil { // the take-in's own pin, so pipeline-started alone writes it below
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayPipeline(t, ctx, js, false, "main", 12)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 12), pinned("pipeline.main.12"))
|
||||
restart()
|
||||
untilRevisionGone(t, ctx, js, "main.10")
|
||||
if _, _, err := index.ReadRevision(ctx, objects, "main.11"); err != nil {
|
||||
t.Fatalf("main.11 is not kept across a restart while its pipeline runs: %v", err)
|
||||
}
|
||||
|
||||
// The store full: held, said once, in the state held; taken in on the indexer's own room once a freed pin makes it.
|
||||
used, _, err := objects.Fill(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
setCap(t, ctx, js, used+1)
|
||||
sayMoved(t, ctx, js, "main", 13, c13, false)
|
||||
if p := heard.nextPending(t, "main", 13); p.Why == "" {
|
||||
t.Fatalf("take-in.pending %+v names no why", p)
|
||||
}
|
||||
untilKey(t, ctx, held, keys.EscapeName("main"), func(v []byte) bool {
|
||||
var h index.HeldTakeIn
|
||||
return v != nil && json.Unmarshal(v, &h) == nil && h.Source == 13 && h.Why != "" && !h.Since.IsZero()
|
||||
})
|
||||
setCap(t, ctx, js, 1<<30) // a larger cap alone wakes nothing: no timer takes a held take-in in
|
||||
sayPipeline(t, ctx, js, true, "main", 11)
|
||||
if got := heard.next(t, "main", 13); len(got.Entries) != 1 || got.Entries[0].Commit != c13 {
|
||||
t.Errorf("main 13 taken in on room said %+v, want avahi at %s", got, c13)
|
||||
}
|
||||
untilKey(t, ctx, held, keys.EscapeName("main"), absent)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), absent)
|
||||
if n := len(heard.pending); n != 0 {
|
||||
t.Errorf("take-in.pending said %d more times for one held source revision, want once", n)
|
||||
}
|
||||
|
||||
// Another branch's hold leaves main going on; the hand skip ends it with why in the hand-act log.
|
||||
sayMoved(t, ctx, js, "beta", 1, unread, true)
|
||||
heard.nextPending(t, "beta", 1)
|
||||
sayMoved(t, ctx, js, "main", 14, c13, false)
|
||||
if next := heard.next(t, "main", 14); len(next.Entries) != 0 {
|
||||
t.Errorf("main 14 at main 13's head said %+v, want no mover", next)
|
||||
}
|
||||
var log []string
|
||||
tools := index.HeldTools(kvStore{held}, askVia(t, ctx, takeinsKV), time.Now, func(what, why string) error {
|
||||
log = append(log, what+": "+why)
|
||||
return nil
|
||||
})
|
||||
pending, err := toolNamed(t, tools, index.PendingTool).Run(map[string]any{})
|
||||
if a, ok := pending.(index.PendingAnswer); err != nil || !ok || len(a.Held) != 1 || a.Held[0].Branch != "beta" || a.Held[0].Source != 1 {
|
||||
t.Fatalf("indexer_pending = %+v (%v), want beta's source revision 1 held", pending, err)
|
||||
}
|
||||
if _, err := toolNamed(t, tools, index.TakeInSkipTool).Run(map[string]any{"branch": "beta", "source": float64(1), "why": "the forge lost the commit"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if skipped := heard.next(t, "beta", 1); !skipped.Skipped || skipped.Why != "the forge lost the commit" || len(skipped.Entries) != 0 {
|
||||
t.Errorf("the skip said %+v, want skipped with its why and no entries", skipped)
|
||||
}
|
||||
if len(log) != 1 {
|
||||
t.Errorf("the hand-act log holds %v, want the one skip", log)
|
||||
}
|
||||
untilKey(t, ctx, held, keys.EscapeName("beta"), absent)
|
||||
|
||||
// A branch watched later: its durable bound on the indexer's own registration-changed.
|
||||
watchBranch(t, ctx, js, "gamma")
|
||||
reg, _ := json.Marshal(meshcatalog.Registration{V: 1, Module: "avahi", Origin: "novox/mesh-catalog", Path: "modules/avahi", Branches: []string{"main", "beta", "gamma"}})
|
||||
if _, err := regs.Put(ctx, index.RegistrationKey("avahi"), reg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.Publish(ctx, meshcatalog.SubjectRegistrationChanged, []byte(`{"module":"avahi"}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayMoved(t, ctx, js, "gamma", 1, c10, true)
|
||||
heard.next(t, "gamma", 1)
|
||||
if _, _, err := index.ReadRevision(ctx, objects, "gamma.1"); err != nil {
|
||||
t.Errorf("gamma.1 is not kept: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// toolNamed is the tool of that name.
|
||||
func toolNamed(t *testing.T, tools []stdio.Tool, name string) stdio.Tool {
|
||||
t.Helper()
|
||||
for _, tl := range tools {
|
||||
if tl.Name == name {
|
||||
return tl
|
||||
}
|
||||
}
|
||||
t.Fatalf("no tool %s", name)
|
||||
return stdio.Tool{}
|
||||
}
|
||||
|
||||
// askVia asks one hand act through the state takeins as the tools do (askTakeIn) and answers once the indexer wrote its answer.
|
||||
func askVia(t *testing.T, ctx context.Context, kv jetstream.KeyValue) func(string, []byte) (index.TakeInAsk, error) {
|
||||
return func(key string, value []byte) (index.TakeInAsk, error) {
|
||||
if _, err := kv.Put(ctx, key, value); err != nil {
|
||||
return index.TakeInAsk{}, err
|
||||
}
|
||||
var a index.TakeInAsk
|
||||
untilKey(t, ctx, kv, key, func(v []byte) bool {
|
||||
got, err := index.DecodeTakeIn(v)
|
||||
if err == nil && got.Done() {
|
||||
a = got
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return a, nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user