A step keeps the node whose holder said ask-taken; a superseded step's drop is asked of that node's holder, an untaken ask's of any holder, as kept calls; steps on mesh-builds and mesh-wants are only ended superseded. A pipeline a publish started says that publish (published), so a newer publish of the package supersedes it. Builds: design 47 G §31, §119, §350, A-182, A-202 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
125 lines
5.9 KiB
Go
125 lines
5.9 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
)
|
|
|
|
type created map[string][]byte
|
|
|
|
func (c created) Create(key string, value []byte) error {
|
|
if _, ok := c[key]; ok {
|
|
return ErrExists
|
|
}
|
|
c[key] = value
|
|
return nil
|
|
}
|
|
|
|
// The starts (design 47 G §54, §103, §334): a pipeline's key written by compare-and-set on its absence, so a second start
|
|
// of the same source revision and module writes nothing; a publish starts one pipeline per dependent outdated names
|
|
// behind by kind 1, keyed by the publishing branch and revision.
|
|
func TestStarts(t *testing.T) {
|
|
store := created{}
|
|
var said []string
|
|
var superseding []string
|
|
s := &Starter{Pipelines: store, Say: func(subject string, body any) error {
|
|
ev := body.(seat.PipelineStarted)
|
|
said = append(said, subject+" "+ev.Pipeline)
|
|
if ev.Published == nil || ev.Published.Artifact != "mesh-sdk:go" || ev.Published.Version != "0.1.16" {
|
|
t.Errorf("pipeline-started of %s says the publish %+v (A-202)", ev.Pipeline, ev.Published)
|
|
}
|
|
return nil
|
|
}, Supersede: func(newer seat.Pipeline) { superseding = append(superseding, newer.Pipeline) }}
|
|
view := func(branch string) (Half, bool) {
|
|
return Half{Revision: 9, Entries: map[string]catalog.CatalogEntry{
|
|
"app": {Module: "app", Commit: "c1", Fp: "src2:aa", Repository: "o/app"}}}, true
|
|
}
|
|
var asked catalog.OutdatedInput
|
|
outdated := func(in catalog.OutdatedInput) (catalog.OutdatedAnswer, error) {
|
|
asked = in
|
|
return catalog.OutdatedAnswer{Behind: []catalog.Outdated{
|
|
{Module: "app", Kind: 1}, {Module: "tool", Kind: 1}, {Module: "ordered", Kind: 4}}}, nil
|
|
}
|
|
n, err := s.Published(builds.PackagePublished{Artifact: "mesh-sdk:go", Branch: "main", Source: 41, Module: "mesh-sdk", Version: "0.1.16"}, outdated, view)
|
|
if err != nil || n != 2 {
|
|
t.Fatalf("a publish started %d (%v), want the two dependents behind by kind 1", n, err)
|
|
}
|
|
if asked.Dependency != "mesh-sdk:go" || asked.Branch != "main" {
|
|
t.Errorf("outdated asked %+v, want the package on its branch", asked)
|
|
}
|
|
var p seat.Pipeline
|
|
if err := json.Unmarshal(store["main.41.app"], &p); err != nil || p.Commit != "c1" || p.Fingerprint != "src2:aa" || p.Revision != 9 ||
|
|
p.Outcome != seat.PipelineOutcomeRunning || p.Source != 41 || p.Published == nil || p.Published.Version != "0.1.16" {
|
|
t.Errorf("the pipeline main.41.app = %+v (%v)", p, err)
|
|
}
|
|
// Each pipeline written supersedes the older ones it replaces (§31).
|
|
if len(superseding) != 2 {
|
|
t.Errorf("the publish's pipelines superseding: %v, want both", superseding)
|
|
}
|
|
if _, ok := store["main.41.ordered"]; ok {
|
|
t.Error("an ordering edge starts no pipeline")
|
|
}
|
|
// The take-in of the same source revision and module is the same pipeline: the second start writes nothing.
|
|
before := string(store["main.41.app"])
|
|
ok, err := s.Start(Begin{Branch: "main", Source: 41, Module: "app", Commit: "c2"})
|
|
if ok || err != nil || string(store["main.41.app"]) != before || len(said) != 2 {
|
|
t.Errorf("a second start wrote %v (%v); said %v", ok, err, said)
|
|
}
|
|
if !strings.HasPrefix(said[0], "mesh.seat.mesh-pipeline-runner.event.pipeline-started.app.main.c1 main.41.app") {
|
|
t.Errorf("pipeline-started said on %q", said[0])
|
|
}
|
|
s.Say = func(string, any) error { return nil }
|
|
// A branch holding a dot is escaped in the key, so the key reads back; a start naming no source revision is refused.
|
|
if _, err := s.Start(Begin{Branch: "release.1", Source: 3, Module: "app"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if b, r, m, ok := seat.ParsePipelinesByBranchRevisionModuleKey(Key("release.1", 3, "app")); !ok || r != "3" || m != "app" || b == "release" {
|
|
t.Errorf("the key of release.1 is %q", Key("release.1", 3, "app"))
|
|
}
|
|
if _, err := s.Start(Begin{Branch: "main", Module: "app"}); err == nil {
|
|
t.Error("a start with no source revision is refused")
|
|
}
|
|
s.Pipelines = failing{}
|
|
if _, err := s.Start(Begin{Branch: "main", Source: 5, Module: "app"}); err == nil {
|
|
t.Error("a write the bus refuses is an error")
|
|
}
|
|
}
|
|
|
|
type failing struct{}
|
|
|
|
func (failing) Create(string, []byte) error { return errors.New("bus away") }
|
|
|
|
// A take-in.taken starts one pipeline per entry of its source revision (design 47 G §44, §54, §476); a hand drop starts
|
|
// none, and a publish that started an entry first leaves the take-in's start of it writing nothing.
|
|
func TestTakenInStarts(t *testing.T) {
|
|
store := created{}
|
|
var said []string
|
|
s := &Starter{Pipelines: store, Say: func(subject string, body any) error { said = append(said, subject); return nil }}
|
|
view := func(string) (Half, bool) { return Half{Revision: 12}, true }
|
|
ev := catalog.TakeInTaken{Kind: "taken", Branch: "main", Source: 7, Group: "g1", Entries: []catalog.TakeInEntry{
|
|
{Module: "a", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/a"}, {Module: "b", Commit: "c2", Fingerprint: "src2:bb"}}}
|
|
if _, err := s.Start(Begin{Branch: "main", Source: 7, Module: "b", Commit: "c2"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
n, err := s.TakenIn(ev, view)
|
|
if err != nil || n != 1 || len(said) != 2 {
|
|
t.Fatalf("a take-in started %d (%v), said %v: want a only, b being started already", n, err, said)
|
|
}
|
|
var p seat.Pipeline
|
|
if err := json.Unmarshal(store["main.7.a"], &p); err != nil || p.Commit != "c1" || p.Group != "g1" || p.Revision != 12 || p.Fingerprint != "src2:aa" {
|
|
t.Errorf("the pipeline main.7.a = %+v (%v)", p, err)
|
|
}
|
|
if n, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Dropped: true, By: "op", Branch: "main", Source: 8, Entries: ev.Entries}, view); n != 0 || err != nil {
|
|
t.Errorf("a hand drop started %d (%v)", n, err)
|
|
}
|
|
if _, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Branch: "main"}, view); err == nil {
|
|
t.Error("a take-in naming no source revision is refused")
|
|
}
|
|
}
|