Improve D&D validation reliability
This commit is contained in:
@@ -14,9 +14,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Key = "normalize/dnd/location-registry/identity"
|
||||
ReasonCode = "invalid_location_identity"
|
||||
policy = domainidentity.Policy
|
||||
Key = "normalize/dnd/location-registry/identity"
|
||||
ReasonCode = "invalid_location_identity"
|
||||
policy = domainidentity.Policy
|
||||
correctionPolicy = "dnd.location_registry.validator.identity.v2"
|
||||
)
|
||||
|
||||
type Options struct{}
|
||||
@@ -31,7 +32,7 @@ func (v *Validator) ExecutionClass() contracts.ExecutionClass {
|
||||
return contracts.ExecutionClassDeterministic
|
||||
}
|
||||
func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}, {Name: "correction_policy", Value: correctionPolicy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.LocationRegistry]) (contracts.ValidationResult, error) {
|
||||
@@ -43,17 +44,38 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
issues := make([]string, len(identityIssues))
|
||||
var corrections diagnostics.Corrections
|
||||
for index, issue := range identityIssues {
|
||||
issues[index] = fmt.Sprintf("locations[%d] %s: %s", issue.RecordIndex, issue.Code, diagnostics.Quote(issue.Value))
|
||||
if issue.RecordIndex < 0 || issue.RecordIndex >= len(req.Value.Locations) {
|
||||
continue
|
||||
}
|
||||
location := req.Value.Locations[issue.RecordIndex]
|
||||
corrections.Add(string(issue.Code), locationIdentityCorrection(issue.Code), fmt.Sprintf("Affected location %s %s.", diagnostics.Quote(location.Name), diagnostics.SourceRange(location.SourceRefs)))
|
||||
}
|
||||
return contracts.ValidationResult{
|
||||
Approved: false,
|
||||
ReasonCode: ReasonCode,
|
||||
Message: diagnostics.Aggregate("invalid location identity", issues),
|
||||
CorrectionGuidance: "Return one canonical registry entry per distinct proper location name, combining duplicate mentions of the same location.",
|
||||
CorrectionGuidance: corrections.Guidance("Correct the duplicate-group proposals and return the complete replacement proposal response"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func locationIdentityCorrection(code domainidentity.IssueCode) string {
|
||||
switch code {
|
||||
case domainidentity.IssueEmptyCanonicalName:
|
||||
return "Select a canonical proposal member with a nonblank, transcript-supported proper location name."
|
||||
case domainidentity.IssueMissingEvidence:
|
||||
return "Select a canonical proposal member that has direct transcript evidence; do not discard all supported evidence for a location."
|
||||
case domainidentity.IssueInvalidID, domainidentity.IssueIDMismatch:
|
||||
return "Revise the proposal so its canonical location member has a valid name and evidence anchor; Notarius derives durable identity without model input."
|
||||
case domainidentity.IssueDuplicateID:
|
||||
return "Do not use proposals that collapse distinct locations or evidence anchors into one canonical identity; group only records that describe the same location."
|
||||
default:
|
||||
return "Revise the duplicate-group proposal so every canonical location is transcript-supported and distinct."
|
||||
}
|
||||
}
|
||||
|
||||
func Spec() pipeline.ValidatorSpec {
|
||||
return pipeline.ValidatorSpec{Key: Key, ExecutionClass: contracts.ExecutionClassDeterministic}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,13 @@ func TestValidatorDefersShapeAndRejectsDerivationAndDuplicateID(t *testing.T) {
|
||||
t.Fatalf("message %q missing %q", result.Message, want)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(result.CorrectionGuidance, "duplicate-group proposals") || !strings.Contains(result.CorrectionGuidance, "Gate") || strings.Contains(result.CorrectionGuidance, "not-an-id") || strings.Contains(result.CorrectionGuidance, "locations[") {
|
||||
t.Fatalf("CorrectionGuidance = %q, want contextual proposal guidance without IDs or operator paths", result.CorrectionGuidance)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorRegistersIdentityPolicy(t *testing.T) {
|
||||
if got := New(Options{}).CheckpointFingerprints(); len(got) != 1 || got[0].Value != domainidentity.Policy {
|
||||
if got := New(Options{}).CheckpointFingerprints(); len(got) != 2 || got[0].Value != domainidentity.Policy || got[1].Name != "correction_policy" || got[1].Value != correctionPolicy {
|
||||
t.Fatalf("fingerprints = %#v", got)
|
||||
}
|
||||
registry := pipeline.NewValidatorRegistry()
|
||||
|
||||
Reference in New Issue
Block a user