Classify source relatedness as data-quality advisories

This commit is contained in:
2026-08-27 15:49:53 +00:00
parent 1f1967c8d2
commit ccba2ce3f9
25 changed files with 232 additions and 189 deletions

View File

@@ -1,4 +1,4 @@
// Package sourcerelatedness warns about NPC occurrence evidence unrelated to its NPC.
// Package sourcerelatedness reports advisory findings about NPC occurrence evidence unrelated to its NPC.
package sourcerelatedness
import (
@@ -14,10 +14,9 @@ import (
)
const (
Key = "extract/dnd/npc-occurrences/source_relatedness"
WarningReasonCode = "npc_occurrence_not_near_source"
OmittedReasonCode = "npc_occurrence_relatedness_warnings_omitted"
policy = "dnd.npc_occurrences.validator.source_relatedness.v2"
Key = "extract/dnd/npc-occurrences/source_relatedness"
ReasonCode = "npc_occurrence_not_near_source"
policy = "dnd.npc_occurrences.validator.source_relatedness.v2"
)
type Options struct{}
@@ -58,14 +57,11 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
}
warnings = append(warnings, contracts.Warning{
Scope: fmt.Sprintf("occurrences[%d]", index),
ReasonCode: WarningReasonCode,
ReasonCode: ReasonCode,
Message: fmt.Sprintf("NPC occurrence name %s was not found in cited source text", diagnostics.Quote(occurrence.Name)),
})
}
return contracts.ValidationResult{
Approved: true,
Warnings: diagnostics.LimitWarnings(warnings, "npc_occurrences", OmittedReasonCode),
}, nil
return diagnostics.DataQualityResult(warnings)
}
func Spec() pipeline.ValidatorSpec {

View File

@@ -10,7 +10,6 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
)
func TestValidatorUsesOnlyCurrentTranscriptAndWarnsOncePerOccurrence(t *testing.T) {
@@ -21,11 +20,11 @@ func TestValidatorUsesOnlyCurrentTranscriptAndWarnsOncePerOccurrence(t *testing.
doc := &source.SourceDocument{ID: "session", Units: []source.SourceUnit{{ID: 1, Text: "ORin Thorn speaks."}, {ID: 2, Text: "The party waits."}}}
references := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("Missing NPC")}}}}}
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCOccurrenceList]{Source: doc, References: references, Value: value})
if err != nil || !result.Approved || len(result.Warnings) != 1 {
if err != nil || !result.Approved || len(result.Warnings) != 0 || len(result.Diagnostics) != 1 {
t.Fatalf("Validate() = %#v, %v", result, err)
}
if warning := result.Warnings[0]; warning.Scope != "occurrences[1]" || warning.ReasonCode != WarningReasonCode || !strings.Contains(warning.Message, `Missing\nNPC`) {
t.Fatalf("warning = %#v", warning)
if diagnostic := result.Diagnostics[0]; diagnostic.Samples[0].Scope != "occurrences[1]" || diagnostic.ReasonCode != ReasonCode || !strings.Contains(diagnostic.Samples[0].Message, `Missing\nNPC`) {
t.Fatalf("diagnostic = %#v", diagnostic)
}
}
@@ -35,7 +34,7 @@ func TestValidatorDefersMalformedShapeAndInvalidRanges(t *testing.T) {
{Occurrences: []dnd.NPCOccurrence{{NPCID: "npc:test", Name: "Mira Thorn", Kind: dnd.NPCOccurrenceKindDialogue, SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 99, EndUnitID: 99}}}}},
} {
result, err := New(Options{}).Validate(context.Background(), contracts.TypedValidationRequest[dnd.NPCOccurrenceList]{Source: &source.SourceDocument{ID: "session", Units: []source.SourceUnit{{ID: 1}}}, Value: value})
if err != nil || !result.Approved || len(result.Warnings) != 0 {
if err != nil || !result.Approved || len(result.Diagnostics) != 0 {
t.Fatalf("deferral = %#v, %v", result, err)
}
}
@@ -52,7 +51,7 @@ func TestValidatorDefersMalformedShapeAndInvalidRanges(t *testing.T) {
}
func TestValidatorBoundsWarnings(t *testing.T) {
count := diagnostics.MaxWarnings + 5
count := contracts.MaxDiagnosticSamples + 5
occurrences := make([]dnd.NPCOccurrence, count)
for index := range occurrences {
occurrences[index] = dnd.NPCOccurrence{
@@ -69,8 +68,7 @@ func TestValidatorBoundsWarnings(t *testing.T) {
if err != nil || !result.Approved {
t.Fatalf("Validate() = %#v, %v", result, err)
}
if len(result.Warnings) != diagnostics.MaxWarnings ||
result.Warnings[len(result.Warnings)-1].ReasonCode != OmittedReasonCode {
t.Fatalf("warnings = %#v", result.Warnings)
if len(result.Warnings) != 0 || len(result.Diagnostics) != 1 || result.Diagnostics[0].OccurrenceCount != count || len(result.Diagnostics[0].Samples) != contracts.MaxDiagnosticSamples {
t.Fatalf("diagnostics = %#v", result.Diagnostics)
}
}