Harden diagnostic handling and warning presentation

This commit is contained in:
2026-08-27 18:41:59 +00:00
parent 1025001f20
commit 079d5af337
67 changed files with 518 additions and 318 deletions

View File

@@ -50,17 +50,17 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
}
citedTexts[locationIndex] = citedText
}
warnings := make([]diagnostics.Finding, 0)
findings := make([]diagnostics.Finding, 0)
for locationIndex, location := range req.Value.Locations {
if shared.ContainsTokenSequence(citedTexts[locationIndex], location.Name) {
continue
}
warnings = append(warnings, diagnostics.Finding{
findings = append(findings, diagnostics.Finding{
Scope: fmt.Sprintf("locations[%d]", locationIndex), ReasonCode: ReasonCode,
Message: fmt.Sprintf("Location %s was not found in cited source text", diagnostics.Quote(location.Name)),
})
}
return diagnostics.DataQualityResult(warnings)
return diagnostics.DataQualityResult(findings)
}
func Spec() pipeline.ValidatorSpec {

View File

@@ -17,14 +17,14 @@ func TestValidatorUsesOnlyCitedTranscriptText(t *testing.T) {
doc := &source.SourceDocument{ID: "session", Kind: "transcript", Format: "application/json", Digest: "sha256:session", Units: []source.SourceUnit{{ID: 1, Kind: "message", Text: "The party enters orins gate."}, {ID: 2, Kind: "message", Text: "Unrelated location."}}}
result, err := New(Options{}).Validate(context.Background(), request(doc, value, contracts.ReferenceSet{}))
if err != nil || !result.Approved || len(result.Diagnostics) != 0 {
t.Fatalf("cited match = %#v, %v; want approval without warnings", result, err)
t.Fatalf("cited match = %#v, %v; want approval without advisories", result, err)
}
value.Locations[0].Name = "Glossary Keep"
before := value
references := contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{"glossary": {Items: []contracts.ReferenceItem{{Content: []byte("Glossary Keep")}}}}}
result, err = New(Options{}).Validate(context.Background(), request(doc, value, references))
if err != nil || !result.Approved || len(result.Diagnostics) != 1 || result.Diagnostics[0].ReasonCode != ReasonCode || !strings.Contains(result.Diagnostics[0].Samples[0].Message, "Glossary Keep") || !reflect.DeepEqual(value, before) {
t.Fatalf("reference-only match = %#v, %v; want advisory warning", result, err)
t.Fatalf("reference-only match = %#v, %v; want advisory", result, err)
}
}
@@ -54,7 +54,7 @@ func TestValidatorRegisters(t *testing.T) {
}
}
func TestValidatorBoundsWarnings(t *testing.T) {
func TestValidatorBoundsAdvisories(t *testing.T) {
locations := make([]dnd.Location, contracts.MaxDiagnosticSamples+2)
for index := range locations {
locations[index] = dnd.Location{ID: "candidate", Name: "Missing", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}