The candidate (the pipeline's own revision) against the branch's newest through mesh-catalog's revision; serving parts by the holder of the runner's, catalog's, steps' and composer's seats; acting rules, credentials; grants through grants-for. A read that fails says could not run. Touches steps.go (Hearer.Widens field, say's pipeline-ended), main.go (hearer.Widens), module.json invokes. Builds: design 47 G §71, §275, §335, §441, A-207, A-215, A-220 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
109 lines
5.8 KiB
Go
109 lines
5.8 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants"
|
|
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"
|
|
)
|
|
|
|
func entry(module, fp string, acts []catalog.ActingRule, manifest map[string]any) catalog.CatalogEntry {
|
|
return catalog.CatalogEntry{Module: module, Fp: fp, Acts: acts, Manifest: manifest}
|
|
}
|
|
|
|
func halfOf(rev int64, es ...catalog.CatalogEntry) Half {
|
|
h := Half{Revision: rev, Entries: map[string]catalog.CatalogEntry{}}
|
|
for _, e := range es {
|
|
h.Entries[e.Module] = e
|
|
}
|
|
return h
|
|
}
|
|
|
|
// widens compares the pipeline's own revision with the branch's newest: the serving parts found by the holder of the seats
|
|
// (the runner, the catalog, each step's seat, the node-engine) by fingerprint, an acting rule gained, matching more or held longer, a
|
|
// credential named that was not, and the grants the grants part adds; each is said by name, a grants part that does not answer says
|
|
// `could not run` and nothing is refused (design 47 G §71, §275, §441, A-207, A-215, A-220).
|
|
func TestWidensIsTheCandidateAgainstTheNewest(t *testing.T) {
|
|
p := seat.Pipeline{Pipeline: "main.8.app", Module: "app", Branch: "main", Source: 31, Revision: 8,
|
|
Steps: []seat.StepResult{{Step: "unit", Seat: "node-build-go"}, {Step: "lint", Seat: "node-build-go"}, {Step: "approval"}}}
|
|
holders := map[string]string{seat.Seat: "runner", catalog.Seat: "indexer", "node-build-go": "build-go", "node-engine": "host"}
|
|
rule := func(on, bound string) []catalog.ActingRule {
|
|
return []catalog.ActingRule{{Seat: "node-build-go", Step: "check", On: on, Bound: bound}}
|
|
}
|
|
newest := halfOf(9,
|
|
entry("runner", "fp-1", nil, nil), entry("indexer", "fp-1", nil, nil), entry("build-go", "fp-1", nil, nil), entry("host", "fp-1", nil, nil),
|
|
entry("app", "fp-1", rule("go", "10m"), map[string]any{"secrets": map[string]any{"token": "/x"}, "provides": []any{"db"}}))
|
|
cases := []struct {
|
|
name string
|
|
cand Half
|
|
grants meshgrants.GrantsFor
|
|
grantsErr error
|
|
want []string
|
|
}{
|
|
{"nothing changes", newest, meshgrants.GrantsFor{}, nil, nil},
|
|
{"a serving part's fingerprint moves", halfOf(8, entry("build-go", "fp-2", nil, nil), entry("host", "fp-1", nil, nil), entry("indexer", "fp-1", nil, nil),
|
|
entry("runner", "fp-1", nil, nil), newest.Entries["app"]), meshgrants.GrantsFor{}, nil, []string{"serving part build-go"}},
|
|
{"an acting rule is gained", halfOf(8, entry("app", "fp-1", append(rule("go", "10m"), catalog.ActingRule{Seat: "x", Step: "grant"}), newest.Entries["app"].Manifest)),
|
|
meshgrants.GrantsFor{}, nil, []string{"acting rule app x.grant"}},
|
|
{"an acting rule matches more", halfOf(8, entry("app", "fp-1", rule("every", "10m"), newest.Entries["app"].Manifest)), meshgrants.GrantsFor{}, nil,
|
|
[]string{"acting rule app node-build-go.check"}},
|
|
{"an acting rule is held longer", halfOf(8, entry("app", "fp-1", rule("go", "1h"), newest.Entries["app"].Manifest)), meshgrants.GrantsFor{}, nil,
|
|
[]string{"acting rule app node-build-go.check"}},
|
|
{"an acting rule is held shorter", halfOf(8, entry("app", "fp-1", rule("go", "5m"), newest.Entries["app"].Manifest)), meshgrants.GrantsFor{}, nil, nil},
|
|
{"a secret and a credential provision are named", halfOf(8, entry("app", "fp-1", rule("go", "10m"), map[string]any{
|
|
"secrets": map[string]any{"token": "/x", "key": map[string]any{"path": "/k"}},
|
|
"provides": []any{"db", map[string]any{"name": "vault", "credential": map[string]any{"own": "key"}}}})),
|
|
meshgrants.GrantsFor{}, nil, []string{"credential app key", "credential app vault"}},
|
|
{"a grant is added", newest, meshgrants.GrantsFor{Modules: []meshgrants.GrantsForModulesItem{
|
|
{Module: "app", Added: []meshgrants.Grant{{Subject: "mesh.seat.x", Verb: "do"}}}, {Module: "other", Added: []meshgrants.Grant{{Subject: "s", Verb: "v"}}}}},
|
|
nil, []string{"grant app mesh.seat.x do"}},
|
|
{"the grants part does not answer", newest, meshgrants.GrantsFor{}, errors.New("no responders"), []string{"could not run mesh-grants"}},
|
|
{"the grants part cannot read the candidate", newest, meshgrants.GrantsFor{Error: "the catalog half is not held"}, nil, []string{"could not run mesh-grants"}},
|
|
}
|
|
for _, c := range cases {
|
|
w := &Widener{
|
|
Revision: func(_ string, rev int64) (Half, error) {
|
|
if rev == 0 {
|
|
return newest, nil
|
|
}
|
|
if rev != 8 {
|
|
t.Errorf("%s: the candidate asked as revision %d", c.name, rev)
|
|
}
|
|
return c.cand, nil
|
|
},
|
|
Holder: func(s string) (string, error) { return holders[s], nil },
|
|
GrantsFor: func(string, int64) (meshgrants.GrantsFor, error) { return c.grants, c.grantsErr },
|
|
}
|
|
var got []string
|
|
for _, x := range w.Widens(p) {
|
|
got = append(got, x.What+" "+x.Name)
|
|
}
|
|
if strings.Join(got, ";") != strings.Join(c.want, ";") {
|
|
t.Errorf("%s: widens %q, want %q", c.name, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// pipeline-ended carries the widens the runner computed, and says it whether or not anything widens (design 47 G §71, A-207).
|
|
func TestPipelineEndedCarriesWidens(t *testing.T) {
|
|
var body any
|
|
h := &Hearer{Say: func(_ string, b any) error { body = b; return nil },
|
|
Widens: func(p seat.Pipeline) []seat.Widening {
|
|
return []seat.Widening{{What: seat.WideningWhatGrant, Name: p.Module + " s v"}}
|
|
}}
|
|
if err := h.say(seat.EventPipelineEnded, seat.Pipeline{Module: "app", Outcome: seat.PipelineOutcomePassed}, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if e, ok := body.(seat.PipelineEnded); !ok || len(e.Widens) != 1 || e.Widens[0].Name != "app s v" {
|
|
t.Errorf("pipeline-ended says %+v", body)
|
|
}
|
|
h.Widens = nil
|
|
_ = h.say(seat.EventPipelineEnded, seat.Pipeline{Module: "app"}, nil)
|
|
if e := body.(seat.PipelineEnded); len(e.Widens) != 0 {
|
|
t.Errorf("a runner with no widener said %v", e.Widens)
|
|
}
|
|
}
|