Centralize output schema and module key validation catalogs
This commit is contained in:
@@ -2,13 +2,15 @@ package validators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/modulecatalog"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/validators/protected_terms"
|
||||
)
|
||||
|
||||
var builtInChains = map[string][]string{
|
||||
"glossary": {
|
||||
modulecatalog.KeyGlossary: {
|
||||
KeyProposalShape,
|
||||
KeyNoEffect,
|
||||
KeyOriginalTextPresence,
|
||||
@@ -18,7 +20,7 @@ var builtInChains = map[string][]string{
|
||||
KeySpokenFormPlausibility,
|
||||
KeyMeaningReversalReview,
|
||||
},
|
||||
"homophones": {
|
||||
modulecatalog.KeyHomophones: {
|
||||
KeyProposalShape,
|
||||
KeyNoEffect,
|
||||
KeyOriginalTextPresence,
|
||||
@@ -28,7 +30,7 @@ var builtInChains = map[string][]string{
|
||||
KeySpokenFormPlausibility,
|
||||
KeyMeaningReversalReview,
|
||||
},
|
||||
"spoken_word": {
|
||||
modulecatalog.KeySpokenWord: {
|
||||
KeyProposalShape,
|
||||
KeyNoEffect,
|
||||
KeyOriginalTextPresence,
|
||||
@@ -38,7 +40,7 @@ var builtInChains = map[string][]string{
|
||||
KeyEditorialReview,
|
||||
KeyMeaningReversalReview,
|
||||
},
|
||||
"grammar": {
|
||||
modulecatalog.KeyGrammar: {
|
||||
KeyProposalShape,
|
||||
KeyNoEffect,
|
||||
KeyOriginalTextPresence,
|
||||
@@ -51,9 +53,10 @@ var builtInChains = map[string][]string{
|
||||
}
|
||||
|
||||
func BuiltInChainKeys(moduleKey string) ([]string, error) {
|
||||
keys, ok := builtInChains[moduleKey]
|
||||
key := strings.TrimSpace(moduleKey)
|
||||
keys, ok := builtInChains[key]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no built-in validator chain for module %q", moduleKey)
|
||||
return nil, fmt.Errorf("no built-in validator chain for module %q", key)
|
||||
}
|
||||
out := make([]string, len(keys))
|
||||
copy(out, keys)
|
||||
@@ -61,6 +64,7 @@ func BuiltInChainKeys(moduleKey string) ([]string, error) {
|
||||
}
|
||||
|
||||
func ResolveBuiltInChain(moduleKey string, registry *Registry) ([]contracts.Validator, error) {
|
||||
moduleKey = strings.TrimSpace(moduleKey)
|
||||
keys, err := BuiltInChainKeys(moduleKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -71,7 +75,7 @@ func ResolveBuiltInChain(moduleKey string, registry *Registry) ([]contracts.Vali
|
||||
|
||||
out := make([]contracts.Validator, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
if moduleKey == "glossary" && key == KeyProtectedTerms {
|
||||
if moduleKey == modulecatalog.KeyGlossary && key == KeyProtectedTerms {
|
||||
// Glossary stages preserve current stricter protection semantics while
|
||||
// reporting the stable protected_terms key.
|
||||
v, buildErr := protected_terms.NewGlossaryStage()
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/modulecatalog"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/proposals"
|
||||
@@ -200,7 +201,7 @@ func TestBuiltInRegistryUnknownKeyFails(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuiltInChainKeysResolveForProductionModules(t *testing.T) {
|
||||
for _, moduleKey := range []string{"glossary", "homophones", "spoken_word", "grammar"} {
|
||||
for _, moduleKey := range modulecatalog.SupportedKeys() {
|
||||
keys, err := BuiltInChainKeys(moduleKey)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve keys for %q: %v", moduleKey, err)
|
||||
@@ -213,7 +214,7 @@ func TestBuiltInChainKeysResolveForProductionModules(t *testing.T) {
|
||||
|
||||
func TestResolveBuiltInChainUsesRegisteredKeys(t *testing.T) {
|
||||
r := NewBuiltInRegistry()
|
||||
for _, moduleKey := range []string{"glossary", "homophones", "spoken_word", "grammar"} {
|
||||
for _, moduleKey := range modulecatalog.SupportedKeys() {
|
||||
chain, err := ResolveBuiltInChain(moduleKey, r)
|
||||
if err != nil {
|
||||
t.Fatalf("resolve chain for %q: %v", moduleKey, err)
|
||||
|
||||
Reference in New Issue
Block a user