2026-07-07 21:32:56 +00:00
package alwaysreject
import (
"context"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
)
const Key = "generic/always_reject"
const ReasonCode = "always_reject"
2026-07-17 07:02:30 +00:00
type Options struct { }
type ChunkValidator struct { }
type TypedValidator [ T any ] struct { }
2026-07-07 21:32:56 +00:00
2026-07-17 07:02:30 +00:00
func NewChunk ( Options ) * ChunkValidator { return & ChunkValidator { } }
func NewTyped [ T any ] ( Options ) * TypedValidator [ T ] { return & TypedValidator [ T ] { } }
2026-07-07 21:32:56 +00:00
2026-07-17 07:02:30 +00:00
func rejection ( ) contracts . ValidationResult {
2026-08-27 11:50:37 +00:00
return contracts . ValidationResult { Approved : false , ReasonCode : ReasonCode , Message : "output rejected by always-reject validator" , CorrectionGuidance : "Return one complete replacement response that satisfies the configured validation requirements." }
2026-07-07 21:32:56 +00:00
}
2026-07-17 07:02:30 +00:00
func ( v * ChunkValidator ) Name ( ) string { return Key }
func ( v * ChunkValidator ) ExecutionClass ( ) contracts . ExecutionClass {
return contracts . ExecutionClassDeterministic
2026-07-07 21:32:56 +00:00
}
2026-07-17 07:02:30 +00:00
func ( v * ChunkValidator ) Validate ( context . Context , contracts . ChunkValidationRequest ) ( contracts . ValidationResult , error ) {
return rejection ( ) , nil
}
func ( v * TypedValidator [ T ] ) Name ( ) string { return Key }
func ( v * TypedValidator [ T ] ) ExecutionClass ( ) contracts . ExecutionClass {
2026-07-07 21:32:56 +00:00
return contracts . ExecutionClassDeterministic
}
2026-07-17 07:02:30 +00:00
func ( v * TypedValidator [ T ] ) Validate ( context . Context , contracts . TypedValidationRequest [ T ] ) ( contracts . ValidationResult , error ) {
return rejection ( ) , nil
}
2026-07-07 21:32:56 +00:00
func Spec ( ) pipeline . ValidatorSpec {
2026-07-17 07:02:30 +00:00
return pipeline . ValidatorSpec { Key : Key , ExecutionClass : contracts . ExecutionClassDeterministic }
2026-07-07 21:32:56 +00:00
}
func Register ( registry * pipeline . ValidatorRegistry ) error {
2026-07-17 08:13:08 +00:00
return pipeline . RegisterChunkValidatorBuilder ( registry , Spec ( ) , validateOptions , func ( request pipeline . BuildRequest ) ( contracts . ChunkValidator , error ) {
2026-07-17 07:02:30 +00:00
options , err := DecodeOptions ( request . Options )
if err != nil {
return nil , err
}
return NewChunk ( options ) , nil
2026-07-07 21:32:56 +00:00
} )
}
2026-07-17 07:02:30 +00:00
func RegisterTyped [ T any ] ( registry * pipeline . ValidatorRegistry , kind contracts . ArtifactKind ) error {
return pipeline . RegisterTypedValidatorBuilder ( registry , kind , Spec ( ) , validateOptions , func ( request pipeline . BuildRequest ) ( contracts . TypedValidator [ T ] , error ) {
options , err := DecodeOptions ( request . Options )
if err != nil {
return nil , err
}
return NewTyped [ T ] ( options ) , nil
} )
}
func DecodeOptions ( options map [ string ] any ) ( Options , error ) {
if err := pipeline . RejectUnknownOptions ( options ) ; err != nil {
return Options { } , err
}
return Options { } , nil
}
func validateOptions ( options map [ string ] any ) error { _ , err := DecodeOptions ( options ) ; return err }