Share the source index with validators
This commit is contained in:
@@ -34,7 +34,7 @@ func (v *Validator) ExecutionClass() contracts.ExecutionClass {
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.CombatTurnList]) (contracts.ValidationResult, error) {
|
||||
if err := Validate(req.Source, req.Value); err != nil {
|
||||
if err := validate(req.Source, req.SourceIndex, req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: false, ReasonCode: ReasonCode, Message: err.Error(), CorrectionGuidance: "Return combat turns in transcript order, without duplicate turns, using consistent contextual combatant names and evidence for each turn."}, nil
|
||||
}
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
@@ -43,10 +43,14 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
// Validate checks only invariants owned by normalized combat-turn output. A
|
||||
// shape or source-reference failure is deliberately deferred to its owner.
|
||||
func Validate(doc *source.SourceDocument, value dnd.CombatTurnList) error {
|
||||
return validate(doc, nil, value)
|
||||
}
|
||||
|
||||
func validate(doc *source.SourceDocument, sourceIndex *source.DocumentIndex, value dnd.CombatTurnList) error {
|
||||
if combatshape.Validate(value) != nil {
|
||||
return nil
|
||||
}
|
||||
index := source.NewDocumentIndex(doc)
|
||||
index := shared.DocumentIndexForSource(doc, sourceIndex)
|
||||
if !sourceRefsValid(index, value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user