Remove direct output validation
This commit is contained in:
@@ -229,6 +229,10 @@ matching schema, cancellation, and native schema dispatch. Reuse existing covera
|
|||||||
|
|
||||||
## Stage 8: Remove Standalone Direct Output Validation
|
## Stage 8: Remove Standalone Direct Output Validation
|
||||||
|
|
||||||
|
**Completed:** Output validation now executes only prepared plans, with direct
|
||||||
|
on-demand schema callbacks removed. Go 1.27.3 `go build ./...` passed. Tests
|
||||||
|
using the retired private API are deferred to the next stage.
|
||||||
|
|
||||||
**Finding:** 4. **Files:** `internal/validate/validator.go`, `standard_validator.go`.
|
**Finding:** 4. **Files:** `internal/validate/validator.go`, `standard_validator.go`.
|
||||||
|
|
||||||
1. Remove the standalone `Validator` interface and concrete host/FS
|
1. Remove the standalone `Validator` interface and concrete host/FS
|
||||||
|
|||||||
@@ -42,14 +42,6 @@ func NewFSValidator(fsys fs.FS, root string) *FSValidator {
|
|||||||
return &FSValidator{fsys: fsys, root: root}
|
return &FSValidator{fsys: fsys, root: root}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *StandardValidator) Validate(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract) (domain.ValidationResult, error) {
|
|
||||||
return validateArtifact(ctx, artifact, contract, v.validateJSONSchema)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *FSValidator) Validate(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract) (domain.ValidationResult, error) {
|
|
||||||
return validateArtifact(ctx, artifact, contract, v.validateJSONSchema)
|
|
||||||
}
|
|
||||||
|
|
||||||
type preparedValidation struct {
|
type preparedValidation struct {
|
||||||
contract domain.OutputContract
|
contract domain.OutputContract
|
||||||
schemaDocument any
|
schemaDocument any
|
||||||
@@ -57,20 +49,13 @@ type preparedValidation struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *preparedValidation) Validate(ctx context.Context, artifact *domain.Artifact) (domain.ValidationResult, error) {
|
func (p *preparedValidation) Validate(ctx context.Context, artifact *domain.Artifact) (domain.ValidationResult, error) {
|
||||||
return validateArtifact(ctx, artifact, p.contract, p.validateJSONSchema)
|
return validateArtifact(ctx, artifact, p.contract, p.schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *preparedValidation) SchemaDocument() any {
|
func (p *preparedValidation) SchemaDocument() any {
|
||||||
return p.schemaDocument
|
return p.schemaDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *preparedValidation) validateJSONSchema(ctx context.Context, instance any, _ string) ([]string, error) {
|
|
||||||
if p.schema == nil {
|
|
||||||
return nil, errors.New("prepared JSON schema is unavailable")
|
|
||||||
}
|
|
||||||
return executeJSONSchema(ctx, p.schema, instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *StandardValidator) PrepareValidation(ctx context.Context, contract domain.OutputContract) (PreparedValidation, error) {
|
func (v *StandardValidator) PrepareValidation(ctx context.Context, contract domain.OutputContract) (PreparedValidation, error) {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -115,9 +100,7 @@ func (v *FSValidator) PrepareValidation(ctx context.Context, contract domain.Out
|
|||||||
return prepared, nil
|
return prepared, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type schemaValidatorFunc func(ctx context.Context, instance any, schemaPath string) ([]string, error)
|
func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract, schema schemaExecutor) (domain.ValidationResult, error) {
|
||||||
|
|
||||||
func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract, validateSchema schemaValidatorFunc) (domain.ValidationResult, error) {
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return domain.ValidationResult{}, ctx.Err()
|
return domain.ValidationResult{}, ctx.Err()
|
||||||
@@ -178,7 +161,10 @@ func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract d
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
validationErrors, err := validateSchema(ctx, instance, contract.SchemaPath)
|
if schema == nil {
|
||||||
|
return domain.ValidationResult{}, errors.New("prepared JSON schema is unavailable")
|
||||||
|
}
|
||||||
|
validationErrors, err := executeJSONSchema(ctx, schema, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return domain.ValidationResult{}, err
|
return domain.ValidationResult{}, err
|
||||||
}
|
}
|
||||||
@@ -197,34 +183,6 @@ func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *StandardValidator) validateJSONSchema(ctx context.Context, instance any, schemaPath string) ([]string, error) {
|
|
||||||
name, err := v.resolveSchemaPath(ctx, schemaPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
document, err := loadJSONSchemaFile(ctx, name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to compile JSON schema %q: %w", name, err)
|
|
||||||
}
|
|
||||||
schema, err := compileSchemaDocument(ctx, fileSchemaResourceURL(name).String(), document)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to compile JSON schema %q: %w", name, err)
|
|
||||||
}
|
|
||||||
return executeJSONSchema(ctx, schema, instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *FSValidator) validateJSONSchema(ctx context.Context, instance any, schemaPath string) ([]string, error) {
|
|
||||||
name, document, err := v.loadSchemaDocument(ctx, schemaPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
schema, err := compileSchemaDocument(ctx, fsSchemaResourceURL(name).String(), document)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to compile JSON schema %q: %w", name, err)
|
|
||||||
}
|
|
||||||
return executeJSONSchema(ctx, schema, instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeJSONValue(ctx context.Context, body []byte) (any, error) {
|
func decodeJSONValue(ctx context.Context, body []byte) (any, error) {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -6,14 +6,6 @@ import (
|
|||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validator validates the generated artifact based on the output contract.
|
|
||||||
// Validation checks ctx around Promptkit-controlled work and synchronous
|
|
||||||
// dependency calls. A dependency call already in progress cannot be preempted;
|
|
||||||
// after it returns, cancellation takes precedence over its result.
|
|
||||||
type Validator interface {
|
|
||||||
Validate(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract) (domain.ValidationResult, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PreparedValidation validates artifacts against one frozen output contract.
|
// PreparedValidation validates artifacts against one frozen output contract.
|
||||||
// Its cancellation boundary is synchronous: Validate does not detach schema
|
// Its cancellation boundary is synchronous: Validate does not detach schema
|
||||||
// execution, and an observed context error prevents publication of a result.
|
// execution, and an observed context error prevents publication of a result.
|
||||||
|
|||||||
Reference in New Issue
Block a user