Remove direct output validation

This commit is contained in:
2026-11-05 20:01:28 +00:00
parent 4b4ce43796
commit 1fbd175e53
3 changed files with 10 additions and 56 deletions

View File

@@ -42,14 +42,6 @@ func NewFSValidator(fsys fs.FS, root string) *FSValidator {
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 {
contract domain.OutputContract
schemaDocument any
@@ -57,20 +49,13 @@ type preparedValidation struct {
}
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 {
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) {
if err := ctx.Err(); err != nil {
return nil, err
@@ -115,9 +100,7 @@ func (v *FSValidator) PrepareValidation(ctx context.Context, contract domain.Out
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, validateSchema schemaValidatorFunc) (domain.ValidationResult, error) {
func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract domain.OutputContract, schema schemaExecutor) (domain.ValidationResult, error) {
select {
case <-ctx.Done():
return domain.ValidationResult{}, ctx.Err()
@@ -178,7 +161,10 @@ func validateArtifact(ctx context.Context, artifact *domain.Artifact, contract d
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 {
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) {
if err := ctx.Err(); err != nil {
return nil, err

View File

@@ -6,14 +6,6 @@ import (
"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.
// Its cancellation boundary is synchronous: Validate does not detach schema
// execution, and an observed context error prevents publication of a result.