Enforce bounded output repair contracts
This commit is contained in:
@@ -174,9 +174,8 @@ func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract d
|
||||
}
|
||||
|
||||
res := domain.ValidationResult{
|
||||
Mode: contract.ValidationMode,
|
||||
SchemaPath: contract.SchemaPath,
|
||||
RepairAttempts: contract.RepairAttempts,
|
||||
Mode: contract.ValidationMode,
|
||||
SchemaPath: contract.SchemaPath,
|
||||
}
|
||||
|
||||
if artifact == nil {
|
||||
|
||||
@@ -64,6 +64,43 @@ func TestStandardValidatorBasicFailureEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStandardValidatorReportsZeroRepairAttempts(t *testing.T) {
|
||||
v := NewStandardValidator("")
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
body string
|
||||
contract domain.OutputContract
|
||||
}{
|
||||
{
|
||||
name: "passed basic validation",
|
||||
body: "answer",
|
||||
contract: domain.OutputContract{
|
||||
ValidationMode: domain.ValidationBasic,
|
||||
RepairAttempts: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "failed JSON validation",
|
||||
body: `{"answer":`,
|
||||
contract: domain.OutputContract{
|
||||
ValidationMode: domain.ValidationJSON,
|
||||
RepairAttempts: 3,
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
res, err := v.Validate(context.Background(), &domain.Artifact{Body: []byte(tc.body)}, tc.contract)
|
||||
if err != nil {
|
||||
t.Fatalf("validate: %v", err)
|
||||
}
|
||||
if res.RepairAttempts != 0 {
|
||||
t.Fatalf("repair attempts = %d, want 0", res.RepairAttempts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStandardValidatorJSONSuccess(t *testing.T) {
|
||||
v := NewStandardValidator("")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user