package seatdef import ( "encoding/json" "errors" "fmt" "slices" "strings" "testing" ) // TestADefinitionIsReadStrictlyNamingWhatIsWrong is the format's own table (design 26: a valid definition parses; // each missing required field is refused naming it; one over 256 KiB is refused), with the parts and fixtures beside. func TestADefinitionIsReadStrictlyNamingWhatIsWrong(t *testing.T) { const listGrain = `{"format":1,"seat":"node-hostname","scope":"node","grain":"seat-list","domain":"Core","decision":"ADR 1", "verbs":[{"name":"add","input":{"type":"object"}}]}` const whole = `{"format":1,"seat":"mesh-broker","scope":"mesh","grain":"whole","domain":"Core","decision":"ADR 1", "verbs":[{"name":"list","input":{"type":"object"},"answer":{"type":"object"}}], "events":[{"name":"created","body":{"type":"object"}}],"family":{"name":"broker.events","max-age-days":7}}` cases := []struct { name, raw string refused string // a text the refusal names, empty when it parses }{ {"the seat list's grain parses", listGrain, ""}, {"a whole definition parses", whole, ""}, {"no format", `{"seat":"a-b","scope":"mesh","grain":"seat-list","domain":"Core","decision":"x"}`, "format: missing"}, {"a later format", `{"format":2,"seat":"a-b","scope":"mesh","grain":"seat-list","domain":"Core","decision":"x"}`, "format 2"}, {"no seat", `{"format":1,"scope":"mesh","grain":"seat-list","domain":"Core","decision":"x"}`, "seat: missing"}, {"no scope", `{"format":1,"seat":"a-b","grain":"seat-list","domain":"Core","decision":"x"}`, "scope: missing"}, {"another scope", `{"format":1,"seat":"a-b","scope":"room","grain":"seat-list","domain":"Core","decision":"x"}`, "scope"}, {"no grain", `{"format":1,"seat":"a-b","scope":"mesh","domain":"Core","decision":"x"}`, "grain: missing"}, {"no decision", `{"format":1,"seat":"a-b","scope":"mesh","grain":"seat-list"}`, "decision: missing"}, {"no domain", `{"format":1,"seat":"a-b","scope":"mesh","grain":"seat-list","decision":"x"}`, "domain: missing"}, {"a domain the glossary lacks", `{"format":1,"seat":"a-b","scope":"mesh","grain":"seat-list","domain":"Weather","decision":"x"}`, "domain"}, {"the Placement domain is gone (ADR 0641 section 5)", `{"format":1,"seat":"a-b","scope":"mesh","grain":"seat-list","domain":"Placement","decision":"x"}`, "domain"}, {"an unknown field", `{"format":1,"seat":"a-b","scope":"mesh","grain":"seat-list","domain":"Core","decision":"x","sevres":[]}`, "sevres: a field the format does not know"}, {"a whole verb with no answer", strings.Replace(whole, `,"answer":{"type":"object"}`, "", 1), "verbs[0].answer: missing"}, {"a whole verb with no input", strings.Replace(whole, `"input":{"type":"object"},`, "", 1), "verbs[0].input: missing"}, {"a whole event with no body", strings.Replace(whole, `"name":"created","body":{"type":"object"}`, `"name":"created"`, 1), "events[0].body: missing"}, {"whole events kept nowhere", strings.Replace(whole, `,"family":{"name":"broker.events","max-age-days":7}`, "", 1), "family: missing"}, {"a family kept longer than the shared events stream", strings.Replace(whole, `"max-age-days":7`, `"max-age-days":30`, 1), "family.max-age-days: missing, or not 7"}, {"a family with a cap of its own", strings.Replace(whole, `"max-age-days":7`, `"max-age-days":7,"max-mib":256`, 1), "max-mib: a field the format does not know"}, {"a holder's event on its own stream", strings.Replace(whole, `"family":`, `"holder-events":[{"name":"verdict",`+ `"subject":"mesh.stream..event.verdict","family":"checker.asks"}],"family":`, 1), ""}, {"a holder's event on its own stream with no family", strings.Replace(whole, `"family":`, `"holder-events":[{"name":"verdict",`+ `"subject":"mesh.stream..event.verdict"}],"family":`, 1), "no family names that stream"}, {"a holder's event kept in its own stream under its module's subjects", strings.Replace(whole, `"family":`, `"holder-events":[{"name":"verdict",`+ `"subject":"mesh.mod..event.verdict","family":"checker.asks"}],"family":`, 1), "a family names the holder's own stream"}, {"a holder's event on a subject of no module", strings.Replace(whole, `"family":`, `"holder-events":[{"name":"verdict",`+ `"subject":"mesh.event.verdict"}],"family":`, 1), "holder-events[0].subject: not mesh.mod..event.verdict"}, {"an event with dotted words", strings.Replace(whole, `"name":"created"`, `"name":"pull.updated"`, 1), ""}, {"an event whose subject carries parts", strings.Replace(whole, `"name":"created"`, `"name":"milestone.asked","subject":"milestone..asked"`, 1), ""}, {"a subject whose words are not the name", strings.Replace(whole, `"name":"created"`, `"name":"owed","subject":"owing."`, 1), `its words are "owing", not the event's name "owed"`}, {"a subject with no part", strings.Replace(whole, `"name":"created"`, `"name":"owed","subject":"owed"`, 1), "events[0].subject: no part"}, {"a subject's part twice", strings.Replace(whole, `"name":"created"`, `"name":"running","subject":"running.."`, 1), "part twice"}, {"a subject on an event named by its caller", strings.Replace(whole, `"name":"created"`, `"name":"owed","by-caller":true,"subject":"owed."`, 1), "carries no subject of its own"}, {"an event kept last per subject", strings.Replace(whole, `"name":"created"`, `"name":"running","subject":"running..","keep":{"last-per-subject":true,"max-age-days":0}`, 1), ""}, {"an event kept in the old form", strings.Replace(whole, `"name":"created"`, `"name":"running","subject":"running.","keep":"last-per-subject"`, 1), `events[0].keep: "last-per-subject" is the old form`}, {"an event kept in a stream of its own, bounded", strings.Replace(whole, `"name":"created"`, `"name":"owed","subject":"owed..","keep":{"max-age-days":7,"max-mib":64}`, 1), ""}, {"an event kept with a dot in its name", strings.Replace(whole, `"name":"created"`, `"name":"pull.updated","keep":{}`, 1), "events[0].name: an event with a keep has no dot"}, {"an event kept by its family may have a dot", strings.Replace(whole, `"name":"created"`, `"name":"pull.updated"`, 1), ""}, {"a bound beside no keep", strings.Replace(whole, `"name":"created"`, `"name":"owed","max-mib":64`, 1), "max-mib: a field the format does not know"}, {"an event of one subject kept last per subject", strings.Replace(whole, `"name":"created"`, `"name":"running","keep":{"last-per-subject":true}`, 1), "give it a subject with parts"}, {"an accept with dotted words", strings.Replace(whole, `"events":`, `"accepts":[{"name":"run.now","body":{}}],"events":`, 1), "accepts[0].name"}, {"a verb twice", strings.Replace(listGrain, `]}`, `,{"name":"add"}]}`, 1), `"add" twice`}, {"states at the seat list's grain", strings.Replace(listGrain, `"domain":"Core","decision":"ADR 1",`, `"domain":"Core","decision":"ADR 1","states":[{"name":"asks"}],`, 1), "grain: seat-list holds"}, {"the old records field is gone", strings.Replace(whole, `"domain":"Core","decision":"ADR 1",`, `"domain":"Core","decision":"ADR 1","records":[{"name":"asks"}],`, 1), "records: a field the format does not know"}, {"a state with a key form and a value", withState(whole, `{"name":"asks","template":"state","writer":"caller", "history":3,"key-forms":[{"key":".","value":{"type":"object"}}]}`), ""}, {"a state offered as a view (design 47 G 699)", withState(whole, `{"name":"asks","template":"state","view":true, "key-forms":[{"key":"","value":{"type":"object"}}]}`), ""}, {"a verb answered by the holder's process by caller (design 47 G 656)", strings.Replace(whole, `"name":"list",`, `"name":"list","by-caller":true,`, 1), ""}, {"a verb sending its answer's file in chunks (design 47 G 681)", strings.Replace(whole, `"name":"list",`, `"name":"list","by-caller":true,"chunks":true,`, 1), ""}, {"a stream state with an age", withState(whole, `{"name":"placement","template":"events","max-age-days":7, "key-forms":[{"key":"changed.","value":{"type":"object"}}]}`), ""}, {"a state of an unknown template", withState(whole, `{"name":"asks","template":"bucket", "key-forms":[{"key":"","value":{"type":"object"}}]}`), `states[0].template: "bucket" is none of state, events`}, {"a key form with no value", withState(whole, `{"name":"asks","template":"state","key-forms":[{"key":""}]}`), `states[0].key-forms[0].value: missing: key form ""`}, {"a state with no key form", withState(whole, `{"name":"asks","template":"state"}`), "states[0].key-forms: missing"}, {"a key part that is no name", withState(whole, `{"name":"asks","template":"state", "key-forms":[{"key":".","value":{}}]}`), "part is not a lower-case name"}, {"a state written by neither", withState(whole, `{"name":"asks","template":"state","writer":"anyone", "key-forms":[{"key":"","value":{}}]}`), "states[0].writer"}, {"history of a stream", withState(whole, `{"name":"asks","template":"log","history":2, "key-forms":[{"key":"","value":{}}]}`), "states[0].history"}, {"a state twice", withState(withState(whole, `{"name":"asks","template":"state","key-forms":[{"key":"","value":{}}]}`), `{"name":"asks","template":"log","key-forms":[{"key":"","value":{}}]}`), `"asks" twice`}, // W1.1: a seat's acting rules (design 47 *What ADR 0656 leaves to this design*), at either grain. {"acting rules", strings.Replace(whole, `"family":`, `"acts":[{"step":"take-in"},{"step":"validate","on":"every"},`+ `{"step":"build","on":"go","bound":"60m"}],"family":`, 1), ""}, {"an acting rule at the seat list's grain", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"compose","bound":"30m"}],"verbs":`, 1), ""}, {"an acting rule with no step", strings.Replace(listGrain, `"verbs":`, `"acts":[{"on":"go"}],"verbs":`, 1), "acts[0].step: missing"}, {"an acting rule of an unknown step", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"deploy"}],"verbs":`, 1), `acts[0].step: "deploy" is not a step (take-in, validate, check, build, compose, grant, place, pipeline)`}, {"an acting rule on no language", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"build","on":"Go Lang"}],"verbs":`, 1), "acts[0].on"}, {"an acting rule's bound that is no duration", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"build","bound":"an hour"}],"verbs":`, 1), `acts[0].bound: "an hour" is not a duration`}, {"an acting rule's field the format does not know", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"build","when":"now"}],"verbs":`, 1), "when: a field the format does not know"}, {"one step on one language twice", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"grant"},{"step":"grant","on":"every"}],"verbs":`, 1), "acts[1]: the step grant on every twice"}, // The reader release (design 47 G §340, §409): the forms G writes beside the ones on main. {"callers as text", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":"a person",`, 1), ""}, {"callers as a list", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["operator","seat:mesh-grants","invokers"],"class":"read",`, 1), ""}, {"callers as neither", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":7,`, 1), "callers is a text or a list"}, {"a list with an empty entry", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["operator",""],`, 1), "verbs[0].callers[1]"}, {"a bare name among callers", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["mesh-grants"],`, 1), `"mesh-grants" is none of operator`}, {"a class of the old branches", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["holder","invokes","reviewers"],`, 1), `"holder" is none of operator`}, {"every form among callers", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["operator","healers","persons","sessions","invokers","seat:mesh-grants","module:mesh-grants","holder:node-backup@same-node"],`, 1), ""}, {"a holder not on the same node", strings.Replace(whole, `"name":"list",`, `"name":"list","callers":["holder:node-backup"],`, 1), "none of operator"}, {"a class that is none", strings.Replace(whole, `"name":"list",`, `"name":"list","class":"free",`, 1), `verbs[0].class: "free" is not a class (read, act, warrant)`}, {"an accepted kind's callers", strings.Replace(whole, `"events":`, `"accepts":[{"name":"step","body":{},"callers":["seat:mesh-pipeline-runner"]}],"events":`, 1), ""}, {"an event's callers", strings.Replace(whole, `"name":"created"`, `"name":"created","callers":["operator"]`, 1), "only an accepted kind carries callers"}, {"keep as an object", strings.Replace(whole, `"name":"created"`, `"name":"owed","keep":{"max-age-days":7,"max-mib":64}`, 1), ""}, {"keep as an object with no age limit", strings.Replace(whole, `"name":"created"`, `"name":"owed","keep":{"max-age-days":0,"last-per-subject":true},"subject":"owed."`, 1), ""}, {"keep as an object, last per subject, one subject", strings.Replace(whole, `"name":"created"`, `"name":"owed","keep":{"last-per-subject":true}`, 1), "give it a subject with parts"}, {"keep as an object with a field it does not know", strings.Replace(whole, `"name":"created"`, `"name":"owed","keep":{"days":7}`, 1), "keep is a string or an object"}, {"keep as an object with a negative age", strings.Replace(whole, `"name":"created"`, `"name":"owed","keep":{"max-age-days":-1}`, 1), "events[0].keep.max-age-days: is negative"}, {"the step pipeline and an image rule", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"pipeline"},{"step":"build","on":"kind:image"},{"step":"check"}],"verbs":`, 1), ""}, {"an acting rule on another kind", strings.Replace(listGrain, `"verbs":`, `"acts":[{"step":"build","on":"kind:Image"}],"verbs":`, 1), "acts[0].on"}, {"a verb marked for approval", strings.Replace(whole, `"name":"list",`, `"name":"list","needs-approval":true,`, 1), ""}, {"a verb marked with a word that is no boolean", strings.Replace(whole, `"name":"list",`, `"name":"list","needs-approval":"yes",`, 1), "not a seat definition's JSON"}, {"a bodies section", strings.Replace(whole, `"family":`, `"bodies":{"Finding":{"type":"object"}},"family":`, 1), ""}, {"one kind on two streams", strings.Replace(whole, `"events":`, `"accepts":[{"name":"step","body":{},"stream":"check"},{"name":"step","body":{},"stream":"delivery"}],"events":`, 1), ""}, {"one kind twice on a stream", strings.Replace(whole, `"events":`, `"accepts":[{"name":"step","body":{},"stream":"check"},{"name":"step","body":{},"stream":"check"}],"events":`, 1), `"step" twice`}, {"a stream that is none", strings.Replace(whole, `"events":`, `"accepts":[{"name":"step","body":{},"stream":"mail"}],"events":`, 1), `accepts[0].stream: "mail" is not check or delivery`}, {"an event on a stream", strings.Replace(whole, `"name":"created"`, `"name":"created","stream":"check"`, 1), "only an accepted kind rides a stream"}, {"over 256 KiB", listGrain[:len(listGrain)-1] + `,"description":"` + strings.Repeat("x", MaxSize) + `"}`, ErrTooLarge.Error()}, } for _, c := range cases { _, err := Parse([]byte(c.raw)) switch { case c.refused == "" && err != nil: t.Errorf("%s: refused: %v", c.name, err) case c.refused != "" && err == nil: t.Errorf("%s: parsed, want refused naming %q", c.name, c.refused) case c.refused != "" && !strings.Contains(err.Error(), c.refused): t.Errorf("%s: refused with %q, want it to name %q", c.name, err, c.refused) } } if _, err := Parse([]byte(listGrain[:len(listGrain)-1] + `,"description":"` + strings.Repeat("x", MaxSize) + `"}`)); !errors.Is(err, ErrTooLarge) { t.Errorf("over 256 KiB is ErrTooLarge, got %v", err) } // A part is taken in whole, its verbs before the definition's own; a part not given, or a type defined twice, // is refused. part, err := ParsePart([]byte(`{"format":1,"part":"registry","verbs":[{"name":"publish","input":{"type":"object"}, "answer":{"type":"object"}}],"events":[{"name":"published","body":{"type":"object"}}], "defs":{"Ref":{"type":"string"}}}`)) if err != nil { t.Fatal(err) } d, err := Parse([]byte(strings.Replace(whole, `"domain":"Core","decision":"ADR 1",`, `"domain":"Core","decision":"ADR 1","includes":["registry"],`, 1))) if err != nil { t.Fatal(err) } got, err := Resolve(d, map[string]Part{"registry": part}) if err != nil { t.Fatal(err) } if v := VerbNames(got.Verbs); strings.Join(v, ",") != "publish,list" { t.Errorf("resolved verbs %v, want the part's first", v) } if m := MessageNames(got.Events); strings.Join(m, ",") != "published,created" || got.Defs["Ref"] == nil { t.Errorf("resolved events %v, defs %v", m, got.Defs) } if _, err := Resolve(d, nil); err == nil || !strings.Contains(err.Error(), `part "registry" is not given`) { t.Errorf("a part not given: %v", err) } d.Defs = map[string]map[string]any{"Ref": {"type": "string"}} if _, err := Resolve(d, map[string]Part{"registry": part}); err == nil || !strings.Contains(err.Error(), "defs.Ref") { t.Errorf("a type defined twice: %v", err) } // A-264 (design 47 G §677, §697): a definition with a marked verb is read with that verb by-caller, the event // gated-ended and the verb approvals, through a part or not; its files stay as written, and one with none is as written. marked, err := Parse([]byte(strings.Replace(whole, `"name":"list",`, `"name":"list","needs-approval":true,`, 1))) if err != nil { t.Fatal(err) } if VerbNames(marked.Verbs)[0] != "list" || len(marked.Verbs) != 1 || marked.Verbs[0].ByCaller { t.Fatalf("parsed %+v", marked.Verbs) } for _, includes := range [][]string{nil, {"registry"}} { marked.Includes = includes got, err := Resolve(marked, map[string]Part{"registry": part}) if err != nil { t.Fatalf("includes %v: %v", includes, err) } var list, approvals *Verb for i := range got.Verbs { switch got.Verbs[i].Name { case "list": list = &got.Verbs[i] case ApprovalsVerb: approvals = &got.Verbs[i] } } var ended *Message for i := range got.Events { if got.Events[i].Name == GatedEndedEvent { ended = &got.Events[i] } } if list == nil || !list.ByCaller || approvals == nil || approvals.Class != ClassRead || !approvals.ByCaller || ended == nil || ended.SubjectPattern() != "gated-ended.." || !ended.KeptLastPerSubject() || ended.KeptAgeDays() != 1 { t.Errorf("includes %v: verbs %+v, events %+v", includes, got.Verbs, got.Events) } if ps := append(checkVerbs(got.Verbs, true), checkMessages("events", got.Events, true)...); len(ps) > 0 { t.Errorf("includes %v: what is added is refused: %v", includes, ps) } if again, _ := Resolve(got, nil); len(again.Verbs) != len(got.Verbs) || len(again.Events) != len(got.Events) { t.Errorf("resolved twice: %d verbs, %d events", len(again.Verbs), len(again.Events)) } raw, _ := json.Marshal(got) if back, err := Parse(raw); err != nil || len(back.Events) != len(got.Events) { t.Errorf("includes %v: the resolved definition does not read back: %v", includes, err) } } if plain, _ := Resolve(d, map[string]Part{"registry": part}); slices.Contains(VerbNames(plain.Verbs), ApprovalsVerb) { t.Errorf("a definition with no marked verb gains %v", VerbNames(plain.Verbs)) } // Fixtures name what they are an instance of. if _, err := ParseFixtures([]byte(`[{"name":"a","of":"verb:list.input","given":{}},{"name":"b","of":"event:created", "subject":"mesh.seat.mesh-broker.event.created","given":{}}]`)); err != nil { t.Errorf("fixtures: %v", err) } if _, err := ParseFixtures([]byte(`[{"name":"a","of":"state:asks/.","given":{}}]`)); err != nil { t.Errorf("a state's fixture: %v", err) } if _, err := ParseFixtures([]byte(`[{"name":"a","of":"state:asks","given":{}}]`)); err == nil { t.Error("a fixture of a state with no key form parsed") } if _, err := ParseFixtures([]byte(`[{"name":"a","of":"verb:list","given":{}}]`)); err == nil || !strings.Contains(err.Error(), "fixtures[0].of") { t.Errorf("a fixture of nothing known: %v", err) } if _, err := ParseIndex([]byte(`{"format":1,"seats":["a-b","a-b"]}`)); err == nil { t.Error("an index naming a seat twice parsed") } } // withState adds one state to a whole definition's JSON. func withState(def, state string) string { if strings.Contains(def, `"states":[`) { return strings.Replace(def, `"states":[`, `"states":[`+state+`,`, 1) } return strings.Replace(def, `"domain":"Core","decision":"ADR 1",`, `"domain":"Core","decision":"ADR 1","states":[`+state+`],`, 1) } // TestAnEventsSubjectNamesItsParts holds the three readings of an event's subject: its pattern, its parts in order and // the local name a manifest's emits and consumes give it. func TestAnEventsSubjectNamesItsParts(t *testing.T) { for _, c := range []struct { m Message pattern, parts, local string }{ {Message{Name: "created"}, "created", "", "created"}, {Message{Name: "pull.updated"}, "pull.updated", "", "pull.updated"}, {Message{Name: "running", Subject: "running.."}, "running..", "node,module", "running.*.*"}, {Message{Name: "milestone.asked", Subject: "milestone..asked"}, "milestone..asked", "milestone", "milestone.*.asked"}, } { if got := c.m.SubjectPattern(); got != c.pattern { t.Errorf("%s: pattern %q, want %q", c.m.Name, got, c.pattern) } if got := strings.Join(c.m.Parts(), ","); got != c.parts { t.Errorf("%s: parts %q, want %q", c.m.Name, got, c.parts) } if got := c.m.Local(); got != c.local { t.Errorf("%s: local %q, want %q", c.m.Name, got, c.local) } } } // W1.1: what an acting rule reads as where it says less (design 47 *An acting part's new version acts first*). func TestAnActingRuleReadsItsStepsDefaults(t *testing.T) { for _, c := range []struct { rule ActingRule language string acts bool wait string }{ {ActingRule{Step: StepBuild, On: "go"}, "go", true, "1h0m0s"}, {ActingRule{Step: StepBuild, On: "go"}, "typescript", false, "1h0m0s"}, {ActingRule{Step: StepCompose}, "anything", true, "30m0s"}, {ActingRule{Step: StepCheck, On: OnEvery}, "", true, "20m0s"}, {ActingRule{Step: StepGrant, Bound: "5m"}, "go", true, "5m0s"}, {ActingRule{Step: StepPlace}, "go", true, "10m0s"}, {ActingRule{Step: StepTakeIn}, "go", true, "0s"}, {ActingRule{Step: StepPipeline}, "go", true, "30m0s"}, } { if got := c.rule.ActsOn(c.language); got != c.acts { t.Errorf("%+v acts on %q: %v, want %v", c.rule, c.language, got, c.acts) } if got := c.rule.Wait().String(); got != c.wait { t.Errorf("%+v waits %s, want %s", c.rule, got, c.wait) } } } // Design 47 G §260, §396: a kept event's stream is SEAT__. func TestAKeptEventsStreamIsNamedFromTheSeatAndTheEvent(t *testing.T) { if got := KeptStream("mesh-delivery", Message{Name: "owed"}); got != "SEAT_mesh-delivery_owed" { t.Errorf("the stream is %s", got) } } // Design 47 G §391, §610: a verb that names no callers takes its class's default, a verb that names them keeps them. func subAVerbWithoutCallersTakesItsClassDefault(t *testing.T) { for _, c := range []struct { verb Verb want string }{ {Verb{}, "invokers persons sessions"}, {Verb{Class: ClassRead}, "invokers persons sessions"}, {Verb{Class: ClassAct}, "operator sessions invokers"}, {Verb{Class: ClassWarrant}, "operator sessions invokers"}, {Verb{Class: ClassAct, Callers: &Callers{List: []string{"seat:mesh-broker"}}}, "seat:mesh-broker"}, {Verb{Class: ClassWarrant, Callers: &Callers{Text: "a person"}}, "operator sessions invokers"}, {Verb{Class: "accept"}, "operator sessions invokers"}, } { if got := strings.Join(c.verb.EffectiveCallers(), " "); got != c.want { t.Errorf("%+v is open to %q, want %q", c.verb, got, c.want) } } } // Design 47 G §260, §396, §331: a kept event's stream is named from the seat and the event, 90 days and 16 MiB unless // the keep says otherwise, and 0 is no age limit. func subAKeptEventsStreamIsNamedAndBoundedByItsKeep(t *testing.T) { d, err := Parse([]byte(`{"format":1,"seat":"mesh-delivery","scope":"mesh","grain":"seat-list","domain":"Delivery","decision":"x", "events":[{"name":"owed","keep":{"max-age-days":7,"max-mib":64}},{"name":"toolchain-agreed","keep":{}}, {"name":"versions-filled","keep":{"max-age-days":0,"max-mib":1}}]}`)) if err != nil { t.Fatal(err) } for i, want := range []string{"SEAT_mesh-delivery_owed 7 64", "SEAT_mesh-delivery_toolchain-agreed 90 16", "SEAT_mesh-delivery_versions-filled 0 1"} { m := d.Events[i] if got := fmt.Sprint(KeptStream(d.Seat, m), " ", m.KeptAgeDays(), " ", m.KeptMiB()); got != want { t.Errorf("%s: %s, want %s", m.Name, got, want) } } }