Define typed producer assessment and native execution dependencies
This commit is contained in:
@@ -3,54 +3,34 @@ package pipeline
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
type ExecutionMode string
|
||||
|
||||
const (
|
||||
ModeStrict ExecutionMode = "strict"
|
||||
ModePermissive ExecutionMode = "permissive"
|
||||
)
|
||||
|
||||
func ParseExecutionMode(value string) (ExecutionMode, error) {
|
||||
mode := ExecutionMode(strings.TrimSpace(value))
|
||||
if mode != ModeStrict && mode != ModePermissive {
|
||||
func ParseExecutionMode(value string) (contracts.ExecutionMode, error) {
|
||||
mode := contracts.ExecutionMode(strings.TrimSpace(value))
|
||||
if mode != contracts.ModeStrict && mode != contracts.ModePermissive {
|
||||
return "", fmt.Errorf("mode must be strict or permissive")
|
||||
}
|
||||
return mode, nil
|
||||
}
|
||||
|
||||
type CacheMode string
|
||||
|
||||
const (
|
||||
CacheAuto CacheMode = "auto"
|
||||
CacheBypass CacheMode = "bypass"
|
||||
CacheRefresh CacheMode = "refresh"
|
||||
)
|
||||
|
||||
func ParseCacheMode(value string) (CacheMode, error) {
|
||||
mode := CacheMode(strings.TrimSpace(value))
|
||||
func ParseCacheMode(value string) (contracts.CacheMode, error) {
|
||||
mode := contracts.CacheMode(strings.TrimSpace(value))
|
||||
switch mode {
|
||||
case CacheAuto, CacheBypass, CacheRefresh:
|
||||
case contracts.CacheAuto, contracts.CacheBypass, contracts.CacheRefresh:
|
||||
return mode, nil
|
||||
}
|
||||
return "", fmt.Errorf("cache must be auto, bypass, or refresh")
|
||||
}
|
||||
|
||||
// ProducerControls contains final operation controls; execution does not inherit settings.
|
||||
type ProducerControls struct {
|
||||
Mode ExecutionMode `json:"mode"`
|
||||
MaxAdditionalTurns int `json:"max_additional_turns"`
|
||||
Cache CacheMode `json:"cache"`
|
||||
}
|
||||
|
||||
func ResolveProducerControls(binding ModuleBinding, profile PipelineProfile, invocationCache *CacheMode) (ProducerControls, error) {
|
||||
result := ProducerControls{Mode: ModeStrict, MaxAdditionalTurns: 2, Cache: CacheAuto}
|
||||
for _, mode := range []*ExecutionMode{profile.Mode, binding.Mode} {
|
||||
func ResolveProducerControls(binding ModuleBinding, profile PipelineProfile, invocationCache *contracts.CacheMode) (contracts.ProducerControls, error) {
|
||||
result := contracts.ProducerControls{Mode: contracts.ModeStrict, MaxAdditionalTurns: 2, Cache: contracts.CacheAuto}
|
||||
for _, mode := range []*contracts.ExecutionMode{profile.Mode, binding.Mode} {
|
||||
if mode != nil {
|
||||
parsed, err := ParseExecutionMode(string(*mode))
|
||||
if err != nil {
|
||||
return ProducerControls{}, err
|
||||
return contracts.ProducerControls{}, err
|
||||
}
|
||||
result.Mode = parsed
|
||||
}
|
||||
@@ -58,16 +38,16 @@ func ResolveProducerControls(binding ModuleBinding, profile PipelineProfile, inv
|
||||
for _, turns := range []*int{profile.MaxAdditionalTurns, binding.MaxAdditionalTurns} {
|
||||
if turns != nil {
|
||||
if *turns < 0 {
|
||||
return ProducerControls{}, fmt.Errorf("max_additional_turns must not be negative")
|
||||
return contracts.ProducerControls{}, fmt.Errorf("max_additional_turns must not be negative")
|
||||
}
|
||||
result.MaxAdditionalTurns = *turns
|
||||
}
|
||||
}
|
||||
for _, cache := range []*CacheMode{profile.Cache, binding.Cache, invocationCache} {
|
||||
for _, cache := range []*contracts.CacheMode{profile.Cache, binding.Cache, invocationCache} {
|
||||
if cache != nil {
|
||||
parsed, err := ParseCacheMode(string(*cache))
|
||||
if err != nil {
|
||||
return ProducerControls{}, err
|
||||
return contracts.ProducerControls{}, err
|
||||
}
|
||||
result.Cache = parsed
|
||||
}
|
||||
@@ -83,11 +63,11 @@ func cloneControl[T any](value *T) *T {
|
||||
return ©
|
||||
}
|
||||
|
||||
func applyEffectiveProducerControls(resolved *ResolvedPipeline, profile PipelineProfile, invocationCache *CacheMode) error {
|
||||
apply := func(binding ModuleBinding, scope string) (ProducerControls, error) {
|
||||
func applyEffectiveProducerControls(resolved *ResolvedPipeline, profile PipelineProfile, invocationCache *contracts.CacheMode) error {
|
||||
apply := func(binding ModuleBinding, scope string) (contracts.ProducerControls, error) {
|
||||
controls, err := ResolveProducerControls(binding, profile, invocationCache)
|
||||
if err != nil {
|
||||
return ProducerControls{}, fmt.Errorf("pipeline %q %s: %w", resolved.ID, scope, err)
|
||||
return contracts.ProducerControls{}, fmt.Errorf("pipeline %q %s: %w", resolved.ID, scope, err)
|
||||
}
|
||||
return controls, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user