Require validation preparation internally
This commit is contained in:
@@ -288,6 +288,10 @@ runner constructors, and their test doubles.
|
|||||||
compatibility adapters. Run applicable validation/preparation tests when this
|
compatibility adapters. Run applicable validation/preparation tests when this
|
||||||
signature change is wired; temporary compilation gaps may continue into Stage 11.
|
signature change is wired; temporary compilation gaps may continue into Stage 11.
|
||||||
|
|
||||||
|
Completion: runner and engine validation dependencies now require preparation;
|
||||||
|
concrete constructors retain direct validation, and nil-plan behavior is tested.
|
||||||
|
Validation, use-case, and engine tests pass on Go 1.27.3.
|
||||||
|
|
||||||
## Stage 11: Share Root Loading And Schema Compilation
|
## Stage 11: Share Root Loading And Schema Compilation
|
||||||
|
|
||||||
**Catalog:** 6, 21, compilation part. **Files:** `internal/validate` implementations.
|
**Catalog:** 6, 21, compilation part. **Files:** `internal/validate` implementations.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type ConfigurationSources struct {
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
llmClient llm.Client
|
llmClient llm.Client
|
||||||
artifactReader artifact.Reader
|
artifactReader artifact.Reader
|
||||||
validator validate.Validator
|
validator validate.ValidationPreparer
|
||||||
validatorSource bool
|
validatorSource bool
|
||||||
artifactSource bool
|
artifactSource bool
|
||||||
disableBundledOpenRouter bool
|
disableBundledOpenRouter bool
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ type recordingValidationPreparer struct {
|
|||||||
directValidateCalls int
|
directValidateCalls int
|
||||||
}
|
}
|
||||||
|
|
||||||
type validationOnly struct{}
|
type nilPlanPreparer struct{}
|
||||||
|
|
||||||
func (validationOnly) Validate(context.Context, *domain.Artifact, domain.OutputContract) (domain.ValidationResult, error) {
|
func (nilPlanPreparer) PrepareValidation(context.Context, domain.OutputContract) (validate.PreparedValidation, error) {
|
||||||
return domain.ValidationResult{}, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *recordingValidationPreparer) Validate(
|
func (v *recordingValidationPreparer) Validate(
|
||||||
@@ -791,7 +791,7 @@ func TestRunnerPreparedExecutionWithoutValidatorSkipsValidation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunnerPrepareExecutionRequiresValidationPreparer(t *testing.T) {
|
func TestRunnerPrepareExecutionRejectsNilValidationPlan(t *testing.T) {
|
||||||
reader := defaultArtifactReader()
|
reader := defaultArtifactReader()
|
||||||
runner := NewRunner(
|
runner := NewRunner(
|
||||||
&fakePromptRepo{def: promptDef(domain.FormatText, domain.ValidationBasic, 0)},
|
&fakePromptRepo{def: promptDef(domain.FormatText, domain.ValidationBasic, 0)},
|
||||||
@@ -800,7 +800,7 @@ func TestRunnerPrepareExecutionRequiresValidationPreparer(t *testing.T) {
|
|||||||
reader,
|
reader,
|
||||||
defaultRenderer(),
|
defaultRenderer(),
|
||||||
&fakeLLM{forbid: true},
|
&fakeLLM{forbid: true},
|
||||||
validationOnly{},
|
nilPlanPreparer{},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ type Runner struct {
|
|||||||
artifacts artifact.Reader
|
artifacts artifact.Reader
|
||||||
renderer prompt.Renderer
|
renderer prompt.Renderer
|
||||||
llm llm.Client
|
llm llm.Client
|
||||||
validator validate.Validator
|
validator validate.ValidationPreparer
|
||||||
repairer OutputRepairer
|
repairer OutputRepairer
|
||||||
admitter RunAdmitter
|
admitter RunAdmitter
|
||||||
defaultTransientRetries uint64
|
defaultTransientRetries uint64
|
||||||
@@ -87,7 +87,7 @@ func NewRunner(
|
|||||||
artifacts artifact.Reader,
|
artifacts artifact.Reader,
|
||||||
renderer prompt.Renderer,
|
renderer prompt.Renderer,
|
||||||
llmClient llm.Client,
|
llmClient llm.Client,
|
||||||
validator validate.Validator,
|
validator validate.ValidationPreparer,
|
||||||
admitter RunAdmitter,
|
admitter RunAdmitter,
|
||||||
) *Runner {
|
) *Runner {
|
||||||
return NewRunnerWithRepairer(
|
return NewRunnerWithRepairer(
|
||||||
@@ -108,7 +108,7 @@ func NewRunnerWithRepairer(
|
|||||||
artifacts artifact.Reader,
|
artifacts artifact.Reader,
|
||||||
renderer prompt.Renderer,
|
renderer prompt.Renderer,
|
||||||
llmClient llm.Client,
|
llmClient llm.Client,
|
||||||
validator validate.Validator,
|
validator validate.ValidationPreparer,
|
||||||
repairer OutputRepairer,
|
repairer OutputRepairer,
|
||||||
admitter RunAdmitter,
|
admitter RunAdmitter,
|
||||||
defaultTransientRetries ...uint64,
|
defaultTransientRetries ...uint64,
|
||||||
@@ -409,11 +409,7 @@ func (r *Runner) prepareValidation(
|
|||||||
if r.validator == nil {
|
if r.validator == nil {
|
||||||
return noOpPreparedValidation{contract: contract}, nil
|
return noOpPreparedValidation{contract: contract}, nil
|
||||||
}
|
}
|
||||||
preparer, ok := r.validator.(validate.ValidationPreparer)
|
plan, err := r.validator.PrepareValidation(ctx, contract)
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("%w: validator does not support prepared validation", ErrValidation)
|
|
||||||
}
|
|
||||||
plan, err := preparer.PrepareValidation(ctx, contract)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &OperationError{Category: ErrValidation, Cause: err}
|
return nil, &OperationError{Category: ErrValidation, Cause: err}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,11 +52,7 @@ func prepareSmokeInferenceCase(
|
|||||||
}, nil
|
}, nil
|
||||||
case domain.SmokeTestStructuredOutput:
|
case domain.SmokeTestStructuredOutput:
|
||||||
validator := validate.NewFSValidator(smokeSchemaFS, ".")
|
validator := validate.NewFSValidator(smokeSchemaFS, ".")
|
||||||
preparer, ok := validator.(validate.ValidationPreparer)
|
plan, err := validator.PrepareValidation(ctx, domain.OutputContract{
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("%w: private validator does not support prepared validation", ErrValidation)
|
|
||||||
}
|
|
||||||
plan, err := preparer.PrepareValidation(ctx, domain.OutputContract{
|
|
||||||
Format: domain.FormatJSON,
|
Format: domain.FormatJSON,
|
||||||
ValidationMode: domain.ValidationJSONSchema,
|
ValidationMode: domain.ValidationJSONSchema,
|
||||||
SchemaPath: smokeStructuredSchemaPath,
|
SchemaPath: smokeStructuredSchemaPath,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"go.maximumdirect.net/promptkit/internal/configuration"
|
"go.maximumdirect.net/promptkit/internal/configuration"
|
||||||
"go.maximumdirect.net/promptkit/internal/domain"
|
"go.maximumdirect.net/promptkit/internal/domain"
|
||||||
"go.maximumdirect.net/promptkit/internal/profile"
|
"go.maximumdirect.net/promptkit/internal/profile"
|
||||||
|
"go.maximumdirect.net/promptkit/internal/validate"
|
||||||
)
|
)
|
||||||
|
|
||||||
type selectionTestCollaborators struct {
|
type selectionTestCollaborators struct {
|
||||||
@@ -41,9 +42,9 @@ func (c selectionTestLLM) Generate(context.Context, domain.GenerateRequest) (*do
|
|||||||
|
|
||||||
type selectionTestValidator struct{ state *selectionTestCollaborators }
|
type selectionTestValidator struct{ state *selectionTestCollaborators }
|
||||||
|
|
||||||
func (v selectionTestValidator) Validate(context.Context, *domain.Artifact, domain.OutputContract) (domain.ValidationResult, error) {
|
func (v selectionTestValidator) PrepareValidation(context.Context, domain.OutputContract) (validate.PreparedValidation, error) {
|
||||||
v.state.validationCalls++
|
v.state.validationCalls++
|
||||||
return domain.ValidationResult{}, errors.New("validation must not occur during target selection")
|
return nil, errors.New("validation must not occur during target selection")
|
||||||
}
|
}
|
||||||
|
|
||||||
type selectionTestRepositories struct {
|
type selectionTestRepositories struct {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestValidationCancellationBeforeWorkDoesNotOpenSchemaSource(t *testing.T) {
|
|||||||
source := &countingSchemaFS{FS: fstest.MapFS{
|
source := &countingSchemaFS{FS: fstest.MapFS{
|
||||||
"schema.json": {Data: []byte(`{"type":"object"}`)},
|
"schema.json": {Data: []byte(`{"type":"object"}`)},
|
||||||
}}
|
}}
|
||||||
validator := NewFSValidator(source, ".").(ValidationPreparer)
|
validator := NewFSValidator(source, ".")
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func TestValidationCancellationBetweenReferencedSchemaReadChunks(t *testing.T) {
|
|||||||
target: "child.json",
|
target: "child.json",
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
validator := NewFSValidator(source, ".").(ValidationPreparer)
|
validator := NewFSValidator(source, ".")
|
||||||
|
|
||||||
plan, err := validator.PrepareValidation(ctx, domain.OutputContract{
|
plan, err := validator.PrepareValidation(ctx, domain.OutputContract{
|
||||||
ValidationMode: domain.ValidationJSONSchema,
|
ValidationMode: domain.ValidationJSONSchema,
|
||||||
@@ -113,7 +113,7 @@ func TestCancellationDoesNotDetachBlockedSchemaRead(t *testing.T) {
|
|||||||
started: started,
|
started: started,
|
||||||
release: release,
|
release: release,
|
||||||
}
|
}
|
||||||
validator := NewFSValidator(source, ".").(ValidationPreparer)
|
validator := NewFSValidator(source, ".")
|
||||||
type outcome struct {
|
type outcome struct {
|
||||||
plan PreparedValidation
|
plan PreparedValidation
|
||||||
err error
|
err error
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ type FSValidator struct {
|
|||||||
root string
|
root string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStandardValidator(schemaBaseDir string) Validator {
|
func NewStandardValidator(schemaBaseDir string) *StandardValidator {
|
||||||
return &StandardValidator{schemaBaseDir: schemaBaseDir}
|
return &StandardValidator{schemaBaseDir: schemaBaseDir}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFSValidator(fsys fs.FS, root string) Validator {
|
func NewFSValidator(fsys fs.FS, root string) *FSValidator {
|
||||||
return &FSValidator{fsys: fsys, root: root}
|
return &FSValidator{fsys: fsys, root: root}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -250,11 +250,7 @@ func TestStandardValidatorPreparedSchemaSurvivesSourceRemoval(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validator := NewStandardValidator(tmp)
|
validator := NewStandardValidator(tmp)
|
||||||
preparer, ok := validator.(ValidationPreparer)
|
prepared, err := validator.PrepareValidation(context.Background(), domain.OutputContract{
|
||||||
if !ok {
|
|
||||||
t.Fatal("standard validator does not support validation preparation")
|
|
||||||
}
|
|
||||||
prepared, err := preparer.PrepareValidation(context.Background(), domain.OutputContract{
|
|
||||||
ValidationMode: domain.ValidationJSONSchema,
|
ValidationMode: domain.ValidationJSONSchema,
|
||||||
SchemaPath: "schema.json",
|
SchemaPath: "schema.json",
|
||||||
})
|
})
|
||||||
@@ -432,11 +428,7 @@ func TestFSValidatorPreparedSchemaSurvivesSourceMutation(t *testing.T) {
|
|||||||
}`)},
|
}`)},
|
||||||
}
|
}
|
||||||
validator := NewFSValidator(fsys, ".")
|
validator := NewFSValidator(fsys, ".")
|
||||||
preparer, ok := validator.(ValidationPreparer)
|
prepared, err := validator.PrepareValidation(context.Background(), domain.OutputContract{
|
||||||
if !ok {
|
|
||||||
t.Fatal("filesystem validator does not support validation preparation")
|
|
||||||
}
|
|
||||||
prepared, err := preparer.PrepareValidation(context.Background(), domain.OutputContract{
|
|
||||||
ValidationMode: domain.ValidationJSONSchema,
|
ValidationMode: domain.ValidationJSONSchema,
|
||||||
SchemaPath: "schema.json",
|
SchemaPath: "schema.json",
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user