diff --git a/modules/mesh-delivery-indexer/judge/busstate.go b/modules/mesh-delivery-indexer/judge/busstate.go index 28a0900c5..c90d97693 100644 --- a/modules/mesh-delivery-indexer/judge/busstate.go +++ b/modules/mesh-delivery-indexer/judge/busstate.go @@ -119,7 +119,8 @@ var bareStream = map[string]optionRule{ // ledgerConfiguration is what a ledger's own configuration may give: how long its history is kept (design 25 § 12.1). var ledgerConfiguration = map[string]optionRule{ - catalogue.OptionAgeDays: {kind: optionInt, least: 1, most: 3650}, + catalogue.OptionAgeDays: {kind: optionInt, least: 1, most: 3650}, + catalogue.ConfigEndedDays: {kind: optionInt, least: 1, most: 3650}, } // noAge is how a bare stream says it keeps its messages for good. @@ -433,6 +434,7 @@ func ledgerTypeProblems(at string, e catalogue.BusStateEntry) []string { problems = append(problems, fmt.Sprintf("%s: a ledger names at least one type (novox/hq ADR 0597 §1)", at)) } seen := map[string]bool{} + endsWith := false for _, t := range e.Types { where := fmt.Sprintf("%s: type %q", at, t.Name) switch { @@ -473,6 +475,12 @@ func ledgerTypeProblems(at string, e catalogue.BusStateEntry) []string { } } } + if t.EndsWith != "" { + endsWith = true + if _, ok := t.Schema[t.EndsWith]; !ok { + problems = append(problems, fmt.Sprintf("%s: ends-with names the field %q, which the type's schema does not hold (design 47 H2 H-A-634 (3))", where, t.EndsWith)) + } + } for _, name := range slices.Sorted(maps.Keys(t.Schema)) { of := t.Schema[name].DigestOf if of == "" { @@ -483,6 +491,14 @@ func ledgerTypeProblems(at string, e catalogue.BusStateEntry) []string { } } } + // A ledger gives ended instances a lifetime (ended-days) exactly when a type says what ends an instance (ends-with). + _, endedDays := e.Configuration[catalogue.ConfigEndedDays] + if endedDays && !endsWith { + problems = append(problems, fmt.Sprintf("%s: the configuration gives %s and no type names ends-with, so no instance ends (design 47 H2 H-A-634 (3))", at, catalogue.ConfigEndedDays)) + } + if endsWith && !endedDays { + problems = append(problems, fmt.Sprintf("%s: a type names ends-with and the configuration gives no %s (design 47 H2 H-A-634 (3))", at, catalogue.ConfigEndedDays)) + } return problems } diff --git a/modules/mesh-delivery-indexer/judge/busstate_test.go b/modules/mesh-delivery-indexer/judge/busstate_test.go index 973dee8c9..b59538c17 100644 --- a/modules/mesh-delivery-indexer/judge/busstate_test.go +++ b/modules/mesh-delivery-indexer/judge/busstate_test.go @@ -16,6 +16,15 @@ import ( func TestBusStateIsJudgedOnce(t *testing.T) { const ledger = `{"name":"records","storage":"ledger","template":"ledger","options":{"max-mib":512},"types":[` + `{"name":"decision","schema":{"title":{"type":"text"}},"operations":[{"name":"propose","effect":"set-fields","fields":["title"]}]}]}` + ended := func(ledger, days, endsWith string) string { + if days != "" { + ledger = strings.Replace(ledger, `"options"`, `"configuration":{"ended-days":`+days+`},"options"`, 1) + } + if endsWith != "" { + ledger = strings.Replace(ledger, `"name":"decision",`, `"name":"decision","ends-with":"`+endsWith+`",`, 1) + } + return ledger + } manifest := func(entries string) string { return `{"module":"a","version":"1.0","requires":[` + entries + `]}` } @@ -84,6 +93,13 @@ func TestBusStateIsJudgedOnce(t *testing.T) { {"a bare stream with a wrong when full", manifest(`{"name":"x","storage":"stream","configuration":{"when-full":"crash","max-mib":10,"max-age-days":9}}`), []string{"\"x\"", "\"when-full\"", "\"refuse\" or \"drop-oldest\""}}, {"a ledger effect outside the four", manifest(strings.Replace(ledger, `"set-fields"`, `"upsert"`, 1)), []string{"\"records\"", "effect \"upsert\"", "outside the four"}}, {"a ledger whose history expires", manifest(strings.Replace(ledger, `"options"`, `"configuration":{"max-age-days":30},"options"`, 1)), nil}, + // Design 47 H2 H-A-634 (3), H-A-690: ended-days is 1 to 3650 and goes with a type naming the field that ends an instance. + {"a ledger whose ended instances live 30 days", manifest(ended(ledger, "30", "title")), nil}, + {"ended-days 0", manifest(ended(ledger, "0", "title")), []string{"\"ended-days\""}}, + {"ended-days 3651", manifest(ended(ledger, "3651", "title")), []string{"\"ended-days\""}}, + {"an ends-with naming no field of the schema", manifest(ended(ledger, "30", "nothing")), []string{"ends-with", "\"nothing\""}}, + {"ended-days with no type naming ends-with", manifest(ended(ledger, "30", "")), []string{"ended-days", "no type names ends-with"}}, + {"ends-with with no ended-days", manifest(ended(ledger, "", "title")), []string{"ends-with", "no ended-days"}}, // DLV-I12 (ADR 0595 §8, ADR 0597 §2, §4): each refusal names the module, the entry, the type, the operation or index, and the field. {"a set-entry naming no into", manifest(strings.Replace(ledger, `"effect":"set-fields","fields":["title"]`, `"effect":"set-entry","key":"title"`, 1)), []string{"\"records\"", "type \"decision\"", "operation \"propose\"", "no into"}},