Migrate NPC registry durable contract
This commit is contained in:
@@ -22,7 +22,7 @@ const (
|
||||
type Options struct{}
|
||||
type Validator struct{}
|
||||
|
||||
var _ contracts.TypedValidator[dnd.NPCList] = (*Validator)(nil)
|
||||
var _ contracts.TypedValidator[dnd.NPCRegistry] = (*Validator)(nil)
|
||||
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
|
||||
|
||||
func New(Options) *Validator { return &Validator{} }
|
||||
@@ -36,7 +36,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCList]) (contracts.ValidationResult, error) {
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCRegistry]) (contracts.ValidationResult, error) {
|
||||
if err := npcshape.Validate(req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func Spec() pipeline.ValidatorSpec {
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCList], error) {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCRegistry], error) {
|
||||
options, err := DecodeOptions(request.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -43,13 +43,13 @@ func TestValidatorContractAndRegistration(t *testing.T) {
|
||||
|
||||
func TestValidatorDefersShapeAndRejectsIdentityIssues(t *testing.T) {
|
||||
validator := New(Options{})
|
||||
shapeInvalid := dnd.NPCList{NPCs: []dnd.NPC{{Name: "missing evidence"}}}
|
||||
shapeInvalid := dnd.NPCRegistry{NPCs: []dnd.NPC{{Name: "missing evidence"}}}
|
||||
result, err := validator.Validate(context.Background(), validationRequest(shapeInvalid))
|
||||
if err != nil || !result.Approved {
|
||||
t.Fatalf("shape-invalid result = %#v, error = %v, want deferred approval", result, err)
|
||||
}
|
||||
|
||||
value := validNPCList(2)
|
||||
value := validNPCRegistry(2)
|
||||
value.NPCs[0].ID = "not-an-id"
|
||||
value.NPCs[1].Name = value.NPCs[0].Name
|
||||
value.NPCs[1].ID = value.NPCs[0].ID
|
||||
@@ -65,7 +65,7 @@ func TestValidatorDefersShapeAndRejectsIdentityIssues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorBoundsUnicodeDiagnostics(t *testing.T) {
|
||||
value := validNPCList(30)
|
||||
value := validNPCRegistry(30)
|
||||
for index := range value.NPCs {
|
||||
value.NPCs[index].ID = fmt.Sprintf("bad-%d", index)
|
||||
value.NPCs[index].Name = strings.Repeat("火", 140) + fmt.Sprintf("-%d", index)
|
||||
@@ -82,12 +82,12 @@ func TestValidatorBoundsUnicodeDiagnostics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func validationRequest(value dnd.NPCList) contracts.TypedValidationRequest[dnd.NPCList] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCList]{Value: value}
|
||||
func validationRequest(value dnd.NPCRegistry) contracts.TypedValidationRequest[dnd.NPCRegistry] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCRegistry]{Value: value}
|
||||
}
|
||||
|
||||
func validNPCList(count int) dnd.NPCList {
|
||||
value := dnd.NPCList{NPCs: make([]dnd.NPC, count)}
|
||||
func validNPCRegistry(count int) dnd.NPCRegistry {
|
||||
value := dnd.NPCRegistry{NPCs: make([]dnd.NPC, count)}
|
||||
for index := range value.NPCs {
|
||||
name := fmt.Sprintf("NPC %d", index)
|
||||
value.NPCs[index] = dnd.NPC{ID: "npc:sha256:0000000000000000000000000000000000000000000000000000000000000000", Name: name, SourceRefs: []source.SourceRef{sourceRefForTest()}}
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
type Options struct{}
|
||||
type Validator struct{}
|
||||
|
||||
var _ contracts.TypedValidator[dnd.NPCList] = (*Validator)(nil)
|
||||
var _ contracts.TypedValidator[dnd.NPCRegistry] = (*Validator)(nil)
|
||||
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
|
||||
|
||||
func New(Options) *Validator { return &Validator{} }
|
||||
@@ -32,7 +32,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCList]) (contracts.ValidationResult, error) {
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCRegistry]) (contracts.ValidationResult, error) {
|
||||
issues := issuesFor(req.Value)
|
||||
if len(issues) > 0 {
|
||||
return rejection(diagnostics.Aggregate("invalid NPC shape", issues)), nil
|
||||
@@ -40,7 +40,7 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
|
||||
func Validate(value dnd.NPCList) error {
|
||||
func Validate(value dnd.NPCRegistry) error {
|
||||
issues := issuesFor(value)
|
||||
if len(issues) == 0 {
|
||||
return nil
|
||||
@@ -48,7 +48,7 @@ func Validate(value dnd.NPCList) error {
|
||||
return fmt.Errorf("%s", diagnostics.Aggregate("invalid NPC shape", issues))
|
||||
}
|
||||
|
||||
func issuesFor(value dnd.NPCList) []string {
|
||||
func issuesFor(value dnd.NPCRegistry) []string {
|
||||
issues := make([]string, 0)
|
||||
if value.NPCs == nil {
|
||||
return []string{"npcs must be present"}
|
||||
@@ -73,7 +73,7 @@ func Spec() pipeline.ValidatorSpec {
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCList], error) {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCRegistry], error) {
|
||||
options, err := DecodeOptions(request.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -13,21 +13,21 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatorApprovesWellFormedNPCPayload(t *testing.T) {
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validNPCList()))
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validNPCRegistry()))
|
||||
if err != nil || !result.Approved {
|
||||
t.Fatalf("Validate() = %#v, %v; want approval", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorRejectsRequiredShapeValues(t *testing.T) {
|
||||
value := validNPCList()
|
||||
value := validNPCRegistry()
|
||||
value.NPCs[0].Name = ""
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(value))
|
||||
if err != nil || result.Approved || result.ReasonCode != ReasonCode || !strings.Contains(result.Message, "name must not be empty") {
|
||||
t.Fatalf("Validate() = %#v, %v; want bounded shape rejection", result, err)
|
||||
}
|
||||
|
||||
missing := dnd.NPCList{}
|
||||
missing := dnd.NPCRegistry{}
|
||||
result, err = New(Options{}).Validate(context.Background(), requestWithValue(missing))
|
||||
if err != nil || result.Approved || result.ReasonCode != ReasonCode {
|
||||
t.Fatalf("missing Validate() = %#v, %v; want shape rejection", result, err)
|
||||
@@ -35,7 +35,7 @@ func TestValidatorRejectsRequiredShapeValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorBoundsDiagnosticsAndQuotesUnicode(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: make([]dnd.NPC, 24)}
|
||||
value := dnd.NPCRegistry{NPCs: make([]dnd.NPC, 24)}
|
||||
long := strings.Repeat("火", 220) + "\n\t"
|
||||
for index := range value.NPCs {
|
||||
value.NPCs[index] = dnd.NPC{ID: "", Name: long, SourceRefs: []source.SourceRef{}}
|
||||
@@ -66,7 +66,7 @@ func TestValidatorSpecCheckpointAndRegistration(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorDoesNotMutateValue(t *testing.T) {
|
||||
value := validNPCList()
|
||||
value := validNPCRegistry()
|
||||
before := value
|
||||
_, err := New(Options{}).Validate(context.Background(), requestWithValue(value))
|
||||
if err != nil || value.NPCs[0].Name != before.NPCs[0].Name {
|
||||
@@ -74,12 +74,12 @@ func TestValidatorDoesNotMutateValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func requestWithValue(value dnd.NPCList) contracts.TypedValidationRequest[dnd.NPCList] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCList]{Value: value}
|
||||
func requestWithValue(value dnd.NPCRegistry) contracts.TypedValidationRequest[dnd.NPCRegistry] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCRegistry]{Value: value}
|
||||
}
|
||||
|
||||
func validNPCList() dnd.NPCList {
|
||||
return dnd.NPCList{NPCs: []dnd.NPC{{
|
||||
func validNPCRegistry() dnd.NPCRegistry {
|
||||
return dnd.NPCRegistry{NPCs: []dnd.NPC{{
|
||||
ID: "candidate", Name: "Mira Thorn",
|
||||
SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}},
|
||||
}}}
|
||||
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
type Options struct{}
|
||||
type Validator struct{}
|
||||
|
||||
var _ contracts.TypedValidator[dnd.NPCList] = (*Validator)(nil)
|
||||
var _ contracts.TypedValidator[dnd.NPCRegistry] = (*Validator)(nil)
|
||||
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
|
||||
|
||||
func New(Options) *Validator { return &Validator{} }
|
||||
@@ -33,7 +33,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCList]) (contracts.ValidationResult, error) {
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCRegistry]) (contracts.ValidationResult, error) {
|
||||
if err := npcshape.Validate(req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func Spec() pipeline.ValidatorSpec {
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCList], error) {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCRegistry], error) {
|
||||
options, err := DecodeOptions(request.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,14 +14,14 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatorApprovesValidSourceReferences(t *testing.T) {
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validDocument(), validNPCList()))
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validDocument(), validNPCRegistry()))
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 0 {
|
||||
t.Fatalf("Validate() = %#v, %v; want approval", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorRejectsInvalidSourceReferences(t *testing.T) {
|
||||
value := validNPCList()
|
||||
value := validNPCRegistry()
|
||||
value.NPCs[0].SourceRefs = []source.SourceRef{
|
||||
{SourceID: "foreign", StartUnitID: 1, EndUnitID: 1},
|
||||
{SourceID: "session", StartUnitID: 2, EndUnitID: 1},
|
||||
@@ -34,7 +34,7 @@ func TestValidatorRejectsInvalidSourceReferences(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorDefersMalformedShape(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: []dnd.NPC{{Name: "Mira Thorn"}}}
|
||||
value := dnd.NPCRegistry{NPCs: []dnd.NPC{{Name: "Mira Thorn"}}}
|
||||
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validDocument(), value))
|
||||
if err != nil || !result.Approved || result.ReasonCode != "" || result.Message != "" {
|
||||
t.Fatalf("Validate() = %#v, %v; want shape deferral", result, err)
|
||||
@@ -42,7 +42,7 @@ func TestValidatorDefersMalformedShape(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorBoundsDiagnosticsAndHandlesMissingDocument(t *testing.T) {
|
||||
value := validNPCList()
|
||||
value := validNPCRegistry()
|
||||
value.NPCs[0].SourceRefs = make([]source.SourceRef, 24)
|
||||
for index := range value.NPCs[0].SourceRefs {
|
||||
value.NPCs[0].SourceRefs[index] = source.SourceRef{SourceID: strings.Repeat("火", 220) + "\n\t", StartUnitID: index + 1, EndUnitID: index + 1}
|
||||
@@ -72,8 +72,8 @@ func TestValidatorSpecCheckpointAndRegistration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func requestWithValue(doc *source.SourceDocument, value dnd.NPCList) contracts.TypedValidationRequest[dnd.NPCList] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCList]{Source: doc, Value: value}
|
||||
func requestWithValue(doc *source.SourceDocument, value dnd.NPCRegistry) contracts.TypedValidationRequest[dnd.NPCRegistry] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: doc, Value: value}
|
||||
}
|
||||
|
||||
func validDocument() *source.SourceDocument {
|
||||
@@ -83,6 +83,6 @@ func validDocument() *source.SourceDocument {
|
||||
}}
|
||||
}
|
||||
|
||||
func validNPCList() dnd.NPCList {
|
||||
return dnd.NPCList{NPCs: []dnd.NPC{{ID: "candidate", Name: "Mira Thorn", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 2}}}}}
|
||||
func validNPCRegistry() dnd.NPCRegistry {
|
||||
return dnd.NPCRegistry{NPCs: []dnd.NPC{{ID: "candidate", Name: "Mira Thorn", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 2}}}}}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
type Options struct{}
|
||||
type Validator struct{}
|
||||
|
||||
var _ contracts.TypedValidator[dnd.NPCList] = (*Validator)(nil)
|
||||
var _ contracts.TypedValidator[dnd.NPCRegistry] = (*Validator)(nil)
|
||||
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
|
||||
|
||||
func New(Options) *Validator { return &Validator{} }
|
||||
@@ -33,7 +33,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCList]) (contracts.ValidationResult, error) {
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCRegistry]) (contracts.ValidationResult, error) {
|
||||
if err := npcshape.Validate(req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func Spec() pipeline.ValidatorSpec {
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCList], error) {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCRegistry], error) {
|
||||
options, err := DecodeOptions(request.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatorMatchesCanonicalNamesWithUnicodeVariants(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: []dnd.NPC{
|
||||
value := dnd.NPCRegistry{NPCs: []dnd.NPC{
|
||||
{ID: "one", Name: "O'Rin Thorn", SourceRefs: []source.SourceRef{
|
||||
{SourceID: "session", StartUnitID: 2, EndUnitID: 2},
|
||||
{SourceID: "session", StartUnitID: 1, EndUnitID: 2},
|
||||
@@ -25,17 +25,17 @@ func TestValidatorMatchesCanonicalNamesWithUnicodeVariants(t *testing.T) {
|
||||
{ID: 1, Kind: "message", Text: " o’rin\u2003thorn appears."},
|
||||
{ID: 2, Kind: "message", Text: "The greencloak watches."},
|
||||
}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: doc, Value: value})
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: doc, Value: value})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 0 {
|
||||
t.Fatalf("Validate() = %#v, %v; want canonical-name relatedness approval", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorWarnsAtMostOncePerNPCForUnrelatedCitations(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: []dnd.NPC{
|
||||
value := dnd.NPCRegistry{NPCs: []dnd.NPC{
|
||||
{ID: "one", Name: "Missing\nName", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}, {SourceID: "session", StartUnitID: 1, EndUnitID: 1}}},
|
||||
}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: relatednessDocument(), Value: value})
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: relatednessDocument(), Value: value})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 1 {
|
||||
t.Fatalf("Validate() = %#v, %v; want one warning", result, err)
|
||||
}
|
||||
@@ -46,33 +46,33 @@ func TestValidatorWarnsAtMostOncePerNPCForUnrelatedCitations(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorDoesNotMatchShortNameSubstring(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: []dnd.NPC{{
|
||||
value := dnd.NPCRegistry{NPCs: []dnd.NPC{{
|
||||
ID: "one", Name: "Art", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}},
|
||||
}}}
|
||||
doc := &source.SourceDocument{ID: "session", Kind: "transcript", Format: "application/json", Digest: "sha256:session", Units: []source.SourceUnit{{ID: 1, Kind: "message", Text: "A cart rolls past."}}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: doc, Value: value})
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: doc, Value: value})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 1 {
|
||||
t.Fatalf("Validate() = %#v, %v; want short-name boundary warning", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorDefersMalformedShapeAndInvalidRangesDoNotPanic(t *testing.T) {
|
||||
invalidShape := dnd.NPCList{NPCs: []dnd.NPC{{Name: "Mira Thorn"}}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: relatednessDocument(), Value: invalidShape})
|
||||
invalidShape := dnd.NPCRegistry{NPCs: []dnd.NPC{{Name: "Mira Thorn"}}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: relatednessDocument(), Value: invalidShape})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 0 {
|
||||
t.Fatalf("shape deferral = %#v, %v; want approval without warning", result, err)
|
||||
}
|
||||
invalidRange := dnd.NPCList{NPCs: []dnd.NPC{{ID: "one", Name: "Mira Thorn", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 99, EndUnitID: 99}}}}}
|
||||
result, err = New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: relatednessDocument(), Value: invalidRange})
|
||||
invalidRange := dnd.NPCRegistry{NPCs: []dnd.NPC{{ID: "one", Name: "Mira Thorn", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 99, EndUnitID: 99}}}}}
|
||||
result, err = New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: relatednessDocument(), Value: invalidRange})
|
||||
if err != nil || !result.Approved || len(result.Warnings) != 0 {
|
||||
t.Fatalf("invalid-range relatedness = %#v, %v; want approval without warning", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorUsesOnlyTranscriptEvidenceAndRegistersPolicy(t *testing.T) {
|
||||
value := dnd.NPCList{NPCs: []dnd.NPC{{ID: "one", Name: "Opaque NPC", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}
|
||||
value := dnd.NPCRegistry{NPCs: []dnd.NPC{{ID: "one", Name: "Opaque NPC", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}
|
||||
references := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("Opaque NPC")}}}}}
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCList]{Source: relatednessDocument(), References: references, Value: value})
|
||||
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCRegistry]{Source: relatednessDocument(), References: references, Value: value})
|
||||
if err != nil || len(result.Warnings) != 1 {
|
||||
t.Fatalf("reference-only relatedness = %#v, %v; want warning", result, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user