Capture native execution facts and complete scoped debug evidence
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
@@ -124,6 +125,56 @@ func assessmentNotesCodec(t *testing.T) artifactCodecEntry {
|
||||
return entry
|
||||
}
|
||||
|
||||
func TestTypedAssessmentCapturesCodecCandidateAndFullScopedGuidance(t *testing.T) {
|
||||
evidence := &nativeEvidence{}
|
||||
content := strings.Repeat("sk-ordinary content ", 1000)
|
||||
candidate := codecNotes{Items: []string{content}}
|
||||
validator := assessmentNotesValidator(t, "domain", func(_ context.Context, request contracts.TypedValidationRequest[codecNotes]) (contracts.ValidationResult, error) {
|
||||
if request.Execution.Capture == nil {
|
||||
t.Fatal("validator has no scoped capture")
|
||||
}
|
||||
return contracts.ValidationResult{ReasonCode: "rejected", CorrectionGuidance: content}, nil
|
||||
})
|
||||
assess := typedCandidateAssessor[codecNotes](assessmentNotesCodec(t), typedValidationTarget{execution: contracts.ExecutionOptions{Capture: evidence}}, preparedValidatorChain{validators: []preparedValidator{validator}})
|
||||
for range 2 {
|
||||
assessment, err := assess(context.Background(), candidate)
|
||||
if err != nil || assessment.Accepted() {
|
||||
t.Fatalf("assessment=%#v %v", assessment, err)
|
||||
}
|
||||
}
|
||||
if nativeEvidenceCount(evidence, "/candidate.json") != 2 || nativeEvidenceCount(evidence, "/finding.json") != 2 {
|
||||
t.Fatal("revised candidates or findings were overwritten")
|
||||
}
|
||||
for name, data := range evidence.files {
|
||||
if strings.HasSuffix(name, "/candidate.json") {
|
||||
decoded, err := assessmentNotesCodec(t).decodeCandidate(data)
|
||||
if err != nil || !reflect.DeepEqual(decoded, candidate) {
|
||||
t.Fatalf("codec candidate changed: %#v, %v", decoded, err)
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(name, "/finding.json") {
|
||||
var finding struct {
|
||||
Guidance string `json:"correction_guidance"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &finding); err != nil || finding.Guidance != content {
|
||||
t.Fatalf("guidance was omitted, rewritten, or truncated: %#v %v", finding, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCandidateAssessmentCaptureFailureIsNotSemanticNonacceptance(t *testing.T) {
|
||||
primary := errors.New("capture failed")
|
||||
called := 0
|
||||
_, err := executeValidationChain(context.Background(), preparedValidatorChain{validators: []preparedValidator{{}, {}}}, func(context.Context, preparedValidator) (contracts.ValidationResult, error) {
|
||||
called++
|
||||
return contracts.ValidationResult{}, &contracts.CaptureError{Cause: primary}
|
||||
})
|
||||
if called != 1 || !errors.Is(err, primary) {
|
||||
t.Fatalf("capture failure was treated as a validator failure: calls=%d, %v", called, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypedAssessmentIsolatesCandidateAndContextViews(t *testing.T) {
|
||||
candidate := codecNotes{Items: []string{"original"}, Labels: map[string]string{"label": "original"}, Details: &codecNoteDetails{Name: "original"}}
|
||||
doc := typedTestDocument()
|
||||
|
||||
Reference in New Issue
Block a user