Resolve producer modes turn allowances cache controls and shared workers
This commit is contained in:
@@ -175,6 +175,18 @@ Stage 5; no fake result or YAML round-trip is an acceptable substitute.
|
|||||||
|
|
||||||
## Stage 3: Resolve The New Application Controls
|
## Stage 3: Resolve The New Application Controls
|
||||||
|
|
||||||
|
**Status:** Complete. Added omission-aware producer controls and final resolution,
|
||||||
|
invocation-wide cache precedence, independent positive workers, source-relative
|
||||||
|
state roots, and explicit-empty debug behavior. Removed the superseded application
|
||||||
|
retry/repair/failure-policy and nested cache configuration surfaces. Updated
|
||||||
|
focused loading, inheritance, directory, and resolution coverage.
|
||||||
|
The isolated cache-root test and `git diff --check` pass. Full focused package
|
||||||
|
tests are blocked by not-yet-migrated pipeline preparation, attempts, and debug
|
||||||
|
callers of removed fields/types (for example `ValidationPolicy` and `Retries`),
|
||||||
|
plus old-path ConfigKit's removed YAML `plugin/limit` import. Their scheduled
|
||||||
|
caller migration and final whole-tree validation remain required; these tests
|
||||||
|
are not claimed as passing.
|
||||||
|
|
||||||
**Goal:** define the selected budgets, modes, workers, and state paths once.
|
**Goal:** define the selected budgets, modes, workers, and state paths once.
|
||||||
|
|
||||||
**Inspect/change:** configuration document/runtime conversion and validation,
|
**Inspect/change:** configuration document/runtime conversion and validation,
|
||||||
|
|||||||
@@ -3,19 +3,9 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultChunkPlanRoot resolves the existing per-user chunk-plan cache root.
|
func DefaultCacheRoot(userCacheDir func() (string, error)) (string, error) {
|
||||||
func DefaultChunkPlanRoot(userCacheDir func() (string, error)) (string, error) {
|
|
||||||
return defaultCacheFamilyRoot(userCacheDir, "chunk-plans")
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultCheckpointRoot(userCacheDir func() (string, error)) (string, error) {
|
|
||||||
return defaultCacheFamilyRoot(userCacheDir, "checkpoints")
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultCacheFamilyRoot(userCacheDir func() (string, error), family string) (string, error) {
|
|
||||||
if userCacheDir == nil {
|
if userCacheDir == nil {
|
||||||
return "", fmt.Errorf("user cache directory resolver must not be nil")
|
return "", fmt.Errorf("user cache directory resolver must not be nil")
|
||||||
}
|
}
|
||||||
@@ -23,9 +13,8 @@ func defaultCacheFamilyRoot(userCacheDir func() (string, error), family string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("resolve user cache directory: %w", err)
|
return "", fmt.Errorf("resolve user cache directory: %w", err)
|
||||||
}
|
}
|
||||||
root = strings.TrimSpace(root)
|
|
||||||
if root == "" {
|
if root == "" {
|
||||||
return "", fmt.Errorf("user cache directory must not be empty")
|
return "", fmt.Errorf("user cache directory must not be empty")
|
||||||
}
|
}
|
||||||
return filepath.Join(filepath.Clean(root), "notarius", family), nil
|
return filepath.Join(root, "notarius"), nil
|
||||||
}
|
}
|
||||||
|
|||||||
21
internal/core/config/cache_test.go
Normal file
21
internal/core/config/cache_test.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultCacheRootUsesOneApplicationDirectory(t *testing.T) {
|
||||||
|
root, err := DefaultCacheRoot(func() (string, error) { return "/tmp/user-cache", nil })
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if root != filepath.Join("/tmp/user-cache", "notarius") {
|
||||||
|
t.Fatalf("root = %q", root)
|
||||||
|
}
|
||||||
|
failure := errors.New("cache home unavailable")
|
||||||
|
if _, err := DefaultCacheRoot(func() (string, error) { return "", failure }); !errors.Is(err, failure) {
|
||||||
|
t.Fatalf("lost cache discovery error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ config:
|
|||||||
steps:
|
steps:
|
||||||
- id: first
|
- id: first
|
||||||
references: {source: {path: ./first.txt}}
|
references: {source: {path: ./first.txt}}
|
||||||
artifacts: {first: {extract: {module: extract, retries: 4}}}
|
artifacts: {first: {extract: {module: extract, max_additional_turns: 4}}}
|
||||||
`)
|
`)
|
||||||
write("two/pipeline.yml", `pipelines:
|
write("two/pipeline.yml", `pipelines:
|
||||||
session:
|
session:
|
||||||
@@ -156,7 +156,7 @@ pipelines:
|
|||||||
input: {module: input}
|
input: {module: input}
|
||||||
steps:
|
steps:
|
||||||
- id: first
|
- id: first
|
||||||
artifacts: {old: {extract: {module: extract, retries: 4}}}
|
artifacts: {old: {extract: {module: extract, max_additional_turns: 4}}}
|
||||||
- id: second
|
- id: second
|
||||||
artifacts: {second: {extract: {module: extract}}}
|
artifacts: {second: {extract: {module: extract}}}
|
||||||
child:
|
child:
|
||||||
|
|||||||
@@ -5,60 +5,38 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Pipelines map[string]pipeline.PipelineProfile `json:"pipelines"`
|
Pipelines map[string]pipeline.PipelineProfile `json:"pipelines"`
|
||||||
Concurrency ConcurrencyConfig `json:"concurrency"`
|
Concurrency ConcurrencyConfig `json:"concurrency"`
|
||||||
Output OutputConfig `json:"output"`
|
Output OutputConfig `json:"output"`
|
||||||
Cache CacheConfig `json:"cache"`
|
CacheDirectory string `json:"cache_directory"`
|
||||||
Debug DebugConfig `json:"debug"`
|
Debug DebugConfig `json:"debug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConcurrencyConfig struct {
|
type ConcurrencyConfig struct {
|
||||||
TotalLLM int `json:"total_llm"`
|
Workers int `json:"workers"`
|
||||||
StageWorkers map[string]int `json:"stage_workers"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const defaultWorkers = 64
|
||||||
defaultLLMConcurrency = 16
|
|
||||||
)
|
|
||||||
|
|
||||||
type OutputConfig struct {
|
type OutputConfig struct {
|
||||||
Directory string `json:"directory"`
|
Directory string `json:"directory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheConfig struct {
|
|
||||||
ChunkPlans ChunkPlanCacheConfig `json:"chunk_plans"`
|
|
||||||
Checkpoints CheckpointCacheConfig `json:"checkpoints"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChunkPlanCacheConfig struct {
|
|
||||||
Directory string `json:"directory,omitempty"`
|
|
||||||
Mode pipeline.ChunkCacheMode `json:"mode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CheckpointCacheConfig struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
Directory string `json:"directory,omitempty"`
|
|
||||||
}
|
|
||||||
type DebugConfig struct {
|
type DebugConfig struct {
|
||||||
Directory string `json:"directory"`
|
Directory string `json:"directory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Default() Config {
|
func Default() Config {
|
||||||
return Config{
|
return Config{
|
||||||
Pipelines: map[string]pipeline.PipelineProfile{},
|
Pipelines: map[string]pipeline.PipelineProfile{},
|
||||||
Concurrency: ConcurrencyConfig{
|
Concurrency: ConcurrencyConfig{Workers: defaultWorkers},
|
||||||
TotalLLM: defaultLLMConcurrency,
|
Output: OutputConfig{Directory: "./notarius-output"},
|
||||||
StageWorkers: map[string]int{"extract": defaultLLMConcurrency},
|
Debug: DebugConfig{Directory: "/tmp/notarius-debug"},
|
||||||
},
|
|
||||||
Output: OutputConfig{Directory: "./notarius-output"},
|
|
||||||
Cache: CacheConfig{ChunkPlans: ChunkPlanCacheConfig{Mode: pipeline.ChunkCacheAuto}},
|
|
||||||
Debug: DebugConfig{Directory: "./notarius-debug"},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneConfig(in Config) Config {
|
func cloneConfig(in Config) Config {
|
||||||
out := in
|
out := in
|
||||||
out.Concurrency.StageWorkers = cloneIntMap(in.Concurrency.StageWorkers)
|
|
||||||
out.Pipelines = make(map[string]pipeline.PipelineProfile, len(in.Pipelines))
|
out.Pipelines = make(map[string]pipeline.PipelineProfile, len(in.Pipelines))
|
||||||
for key, profile := range in.Pipelines {
|
for key, profile := range in.Pipelines {
|
||||||
out.Pipelines[key] = clonePipelineProfile(profile)
|
out.Pipelines[key] = clonePipelineProfile(profile)
|
||||||
@@ -66,35 +44,11 @@ func cloneConfig(in Config) Config {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneIntMap(in map[string]int) map[string]int {
|
|
||||||
if len(in) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := make(map[string]int, len(in))
|
|
||||||
for key, value := range in {
|
|
||||||
out[key] = value
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Config) withDerivedStageWorkers() Config {
|
|
||||||
c = cloneConfig(c)
|
|
||||||
if _, exists := c.Concurrency.StageWorkers["extract"]; !exists {
|
|
||||||
if c.Concurrency.StageWorkers == nil {
|
|
||||||
c.Concurrency.StageWorkers = make(map[string]int)
|
|
||||||
}
|
|
||||||
c.Concurrency.StageWorkers["extract"] = c.Concurrency.TotalLLM
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func clonePipelineProfile(in pipeline.PipelineProfile) pipeline.PipelineProfile {
|
func clonePipelineProfile(in pipeline.PipelineProfile) pipeline.PipelineProfile {
|
||||||
out := in
|
out := in
|
||||||
out.ValidationPolicy = cloneValidationPolicyOverride(in.ValidationPolicy)
|
out.Mode = cloneValue(in.Mode)
|
||||||
if in.StructuredOutputRepairAttempts != nil {
|
out.MaxAdditionalTurns = cloneValue(in.MaxAdditionalTurns)
|
||||||
value := *in.StructuredOutputRepairAttempts
|
out.Cache = cloneValue(in.Cache)
|
||||||
out.StructuredOutputRepairAttempts = &value
|
|
||||||
}
|
|
||||||
out.Input = cloneModuleBinding(in.Input)
|
out.Input = cloneModuleBinding(in.Input)
|
||||||
out.Chunk = cloneModuleBinding(in.Chunk)
|
out.Chunk = cloneModuleBinding(in.Chunk)
|
||||||
out.Output = cloneModuleBinding(in.Output)
|
out.Output = cloneModuleBinding(in.Output)
|
||||||
@@ -175,11 +129,9 @@ func cloneReferenceSource(in pipeline.ReferenceSource) pipeline.ReferenceSource
|
|||||||
|
|
||||||
func cloneModuleBinding(in pipeline.ModuleBinding) pipeline.ModuleBinding {
|
func cloneModuleBinding(in pipeline.ModuleBinding) pipeline.ModuleBinding {
|
||||||
out := in
|
out := in
|
||||||
out.ValidationPolicy = cloneValidationPolicyOverride(in.ValidationPolicy)
|
out.Mode = cloneValue(in.Mode)
|
||||||
if in.StructuredOutputRepairAttempts != nil {
|
out.MaxAdditionalTurns = cloneValue(in.MaxAdditionalTurns)
|
||||||
value := *in.StructuredOutputRepairAttempts
|
out.Cache = cloneValue(in.Cache)
|
||||||
out.StructuredOutputRepairAttempts = &value
|
|
||||||
}
|
|
||||||
if len(in.Options) > 0 {
|
if len(in.Options) > 0 {
|
||||||
out.Options = cloneOptions(in.Options)
|
out.Options = cloneOptions(in.Options)
|
||||||
}
|
}
|
||||||
@@ -188,26 +140,6 @@ func cloneModuleBinding(in pipeline.ModuleBinding) pipeline.ModuleBinding {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneValidationPolicyOverride(in *pipeline.ValidationPolicyOverride) *pipeline.ValidationPolicyOverride {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := *in
|
|
||||||
if in.ProducerStructuralFailure != nil {
|
|
||||||
value := *in.ProducerStructuralFailure
|
|
||||||
out.ProducerStructuralFailure = &value
|
|
||||||
}
|
|
||||||
if in.SemanticRejection != nil {
|
|
||||||
value := *in.SemanticRejection
|
|
||||||
out.SemanticRejection = &value
|
|
||||||
}
|
|
||||||
if in.ValidatorFailure != nil {
|
|
||||||
value := *in.ValidatorFailure
|
|
||||||
out.ValidatorFailure = &value
|
|
||||||
}
|
|
||||||
return &out
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneValidatorOverride(in pipeline.ValidatorOverride) pipeline.ValidatorOverride {
|
func cloneValidatorOverride(in pipeline.ValidatorOverride) pipeline.ValidatorOverride {
|
||||||
out := pipeline.ValidatorOverride{Set: in.Set}
|
out := pipeline.ValidatorOverride{Set: in.Set}
|
||||||
if len(in.Validators) > 0 {
|
if len(in.Validators) > 0 {
|
||||||
@@ -244,3 +176,11 @@ func cloneOptionValue(value any) any {
|
|||||||
return typed
|
return typed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cloneValue[T any](value *T) *T {
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
copy := *value
|
||||||
|
return ©
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,25 +9,26 @@ import (
|
|||||||
// deliberately separate from Config so YAML presence and composition concerns
|
// deliberately separate from Config so YAML presence and composition concerns
|
||||||
// do not reach runtime pipeline types.
|
// do not reach runtime pipeline types.
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version"`
|
||||||
PromptKit promptkit.Settings `yaml:"promptkit"`
|
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||||
Pipelines map[string]PipelineDocument `yaml:"pipelines,omitempty"`
|
Pipelines map[string]PipelineDocument `yaml:"pipelines,omitempty"`
|
||||||
Concurrency *ConcurrencyDocument `yaml:"concurrency,omitempty"`
|
Concurrency *ConcurrencyDocument `yaml:"concurrency,omitempty"`
|
||||||
Output *OutputDocument `yaml:"output,omitempty"`
|
Output *OutputDocument `yaml:"output,omitempty"`
|
||||||
Cache *CacheDocument `yaml:"cache,omitempty"`
|
CacheDirectory *string `yaml:"cache_directory,omitempty"`
|
||||||
Debug *DebugDocument `yaml:"debug,omitempty"`
|
Debug *DebugDocument `yaml:"debug,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PipelineDocument struct {
|
type PipelineDocument struct {
|
||||||
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
Mode *pipeline.ExecutionMode `yaml:"mode,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `yaml:"structured_output_repair_attempts,omitempty"`
|
MaxAdditionalTurns *int `yaml:"max_additional_turns,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyDocument `yaml:"validation_policy,omitempty"`
|
Cache *pipeline.CacheMode `yaml:"cache,omitempty"`
|
||||||
Input BindingDocument `yaml:"input"`
|
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
||||||
Chunk *BindingDocument `yaml:"chunk,omitempty"`
|
Input BindingDocument `yaml:"input"`
|
||||||
Artifacts map[string]ArtifactLaneDocument `yaml:"artifacts,omitempty"`
|
Chunk *BindingDocument `yaml:"chunk,omitempty"`
|
||||||
Steps []PipelineStepDocument `yaml:"steps,omitempty"`
|
Artifacts map[string]ArtifactLaneDocument `yaml:"artifacts,omitempty"`
|
||||||
Output *BindingDocument `yaml:"output,omitempty"`
|
Steps []PipelineStepDocument `yaml:"steps,omitempty"`
|
||||||
References map[string]ReferenceDocument `yaml:"references,omitempty"`
|
Output *BindingDocument `yaml:"output,omitempty"`
|
||||||
|
References map[string]ReferenceDocument `yaml:"references,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PipelineStepDocument struct {
|
type PipelineStepDocument struct {
|
||||||
@@ -48,22 +49,20 @@ type ArtifactLaneDocument struct {
|
|||||||
// deliberately finite subset so nested validator-only fields are rejected by
|
// deliberately finite subset so nested validator-only fields are rejected by
|
||||||
// ConfigKit's strict decoder.
|
// ConfigKit's strict decoder.
|
||||||
type BindingDocument struct {
|
type BindingDocument struct {
|
||||||
Module string `yaml:"module"`
|
Mode *pipeline.ExecutionMode `yaml:"mode,omitempty"`
|
||||||
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
MaxAdditionalTurns *int `yaml:"max_additional_turns,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `yaml:"structured_output_repair_attempts,omitempty"`
|
Cache *pipeline.CacheMode `yaml:"cache,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyDocument `yaml:"validation_policy,omitempty"`
|
Module string `yaml:"module"`
|
||||||
Retries int `yaml:"retries,omitempty"`
|
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
||||||
Options map[string]any `yaml:"options,omitempty"`
|
Options map[string]any `yaml:"options,omitempty"`
|
||||||
References map[string]ReferenceDocument `yaml:"references,omitempty"`
|
References map[string]ReferenceDocument `yaml:"references,omitempty"`
|
||||||
Validators []ValidatorDocument `yaml:"validators,omitempty"`
|
Validators []ValidatorDocument `yaml:"validators,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidatorDocument struct {
|
type ValidatorDocument struct {
|
||||||
Module string `yaml:"module"`
|
Module string `yaml:"module"`
|
||||||
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
LLMProfile *string `yaml:"llm_profile,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `yaml:"structured_output_repair_attempts,omitempty"`
|
Options map[string]any `yaml:"options,omitempty"`
|
||||||
Retries int `yaml:"retries,omitempty"`
|
|
||||||
Options map[string]any `yaml:"options,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReferenceDocument is the explicit version 6 union. Later document
|
// ReferenceDocument is the explicit version 6 union. Later document
|
||||||
@@ -79,36 +78,14 @@ type ArtifactReferenceDocument struct {
|
|||||||
Lane string `yaml:"lane"`
|
Lane string `yaml:"lane"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidationPolicyDocument struct {
|
|
||||||
ProducerStructuralFailure *pipeline.ProducerStructuralFailureAction `yaml:"producer_structural_failure,omitempty"`
|
|
||||||
SemanticRejection *pipeline.SemanticRejectionAction `yaml:"semantic_rejection,omitempty"`
|
|
||||||
ValidatorFailure *pipeline.ValidatorFailureAction `yaml:"validator_failure,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConcurrencyDocument struct {
|
type ConcurrencyDocument struct {
|
||||||
TotalLLM *int `yaml:"total_llm,omitempty"`
|
Workers *int `yaml:"workers,omitempty"`
|
||||||
StageWorkers map[string]int `yaml:"stage_workers,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputDocument struct {
|
type OutputDocument struct {
|
||||||
Directory *string `yaml:"directory,omitempty"`
|
Directory *string `yaml:"directory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheDocument struct {
|
|
||||||
ChunkPlans *ChunkPlanCacheDocument `yaml:"chunk_plans,omitempty"`
|
|
||||||
Checkpoints *CheckpointCacheDocument `yaml:"checkpoints,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChunkPlanCacheDocument struct {
|
|
||||||
Directory *string `yaml:"directory,omitempty"`
|
|
||||||
Mode *string `yaml:"mode,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CheckpointCacheDocument struct {
|
|
||||||
Enabled *bool `yaml:"enabled,omitempty"`
|
|
||||||
Directory *string `yaml:"directory,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DebugDocument struct {
|
type DebugDocument struct {
|
||||||
Directory *string `yaml:"directory,omitempty"`
|
Directory *string `yaml:"directory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,9 @@ func normalizeDocumentPaths(document *Document, resolution *configkit.Resolution
|
|||||||
if document.Output != nil {
|
if document.Output != nil {
|
||||||
normalizeDocumentPath(resolution, state, configkit.Keys("output", "directory"), &document.Output.Directory, false, "resolved output directory")
|
normalizeDocumentPath(resolution, state, configkit.Keys("output", "directory"), &document.Output.Directory, false, "resolved output directory")
|
||||||
}
|
}
|
||||||
if document.Cache != nil {
|
normalizeDocumentPath(resolution, state, configkit.Keys("cache_directory"), &document.CacheDirectory, true, "resolved cache directory")
|
||||||
if document.Cache.ChunkPlans != nil {
|
|
||||||
normalizeDocumentPath(resolution, state, configkit.Keys("cache", "chunk_plans", "directory"), &document.Cache.ChunkPlans.Directory, true, "resolved chunk-plan cache directory")
|
|
||||||
}
|
|
||||||
if document.Cache.Checkpoints != nil {
|
|
||||||
normalizeDocumentPath(resolution, state, configkit.Keys("cache", "checkpoints", "directory"), &document.Cache.Checkpoints.Directory, true, "resolved checkpoint cache directory")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if document.Debug != nil {
|
if document.Debug != nil {
|
||||||
normalizeDocumentPath(resolution, state, configkit.Keys("debug", "directory"), &document.Debug.Directory, false, "resolved debug directory")
|
normalizeDocumentPath(resolution, state, configkit.Keys("debug", "directory"), &document.Debug.Directory, true, "resolved debug directory")
|
||||||
}
|
}
|
||||||
for _, id := range sortedPipelineDocumentKeys(document.Pipelines) {
|
for _, id := range sortedPipelineDocumentKeys(document.Pipelines) {
|
||||||
profile := document.Pipelines[id]
|
profile := document.Pipelines[id]
|
||||||
|
|||||||
@@ -242,15 +242,15 @@ func TestDocumentPathsKeepEmptyCacheDirectoriesAndAbsolutePaths(t *testing.T) {
|
|||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
configPath := filepath.Join(root, "notarius.yml")
|
configPath := filepath.Join(root, "notarius.yml")
|
||||||
abs := filepath.Join(t.TempDir(), "outside.txt")
|
abs := filepath.Join(t.TempDir(), "outside.txt")
|
||||||
if err := os.WriteFile(configPath, []byte("version: 6\ncache:\n chunk_plans: {directory: ''}\n checkpoints: {directory: ''}\npipelines:\n main:\n input: {module: input}\n references:\n outside: {path: "+abs+"}\n"), 0o600); err != nil {
|
if err := os.WriteFile(configPath, []byte("version: 6\ncache_directory: ''\npipelines:\n main:\n input: {module: input}\n references:\n outside: {path: "+abs+"}\n"), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
loaded, err := loadConfig(configPath, LoadOptions{})
|
loaded, err := loadConfig(configPath, LoadOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("loadConfig() error = %v", err)
|
t.Fatalf("loadConfig() error = %v", err)
|
||||||
}
|
}
|
||||||
if loaded.Config.Cache.ChunkPlans.Directory != "" || loaded.Config.Cache.Checkpoints.Directory != "" {
|
if loaded.Config.CacheDirectory == "" {
|
||||||
t.Fatalf("cache directories = %#v", loaded.Config.Cache)
|
t.Fatalf("cache directories = %#v", loaded.Config.CacheDirectory)
|
||||||
}
|
}
|
||||||
if got := loaded.Config.Pipelines["main"].References["outside"].Path; got != abs {
|
if got := loaded.Config.Pipelines["main"].References["outside"].Path; got != abs {
|
||||||
t.Fatalf("absolute reference = %q", got)
|
t.Fatalf("absolute reference = %q", got)
|
||||||
|
|||||||
@@ -142,13 +142,13 @@ func TestDocumentDefinitionReturnsIndependentDefaults(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
first.Config.Pipelines["changed"] = PipelineDocument{}
|
first.Config.Pipelines["changed"] = PipelineDocument{}
|
||||||
first.Config.Concurrency.StageWorkers["extract"] = 3
|
*first.Config.Concurrency.Workers = 3
|
||||||
|
|
||||||
second, err := loadDocumentSource(configkit.Bytes("second.yml", []byte("version: 6\n")), LoadOptions{})
|
second, err := loadDocumentSource(configkit.Bytes("second.yml", []byte("version: 6\n")), LoadOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(second.Config.Pipelines) != 0 || second.Config.Concurrency.StageWorkers["extract"] != defaultLLMConcurrency || len(second.Config.Concurrency.StageWorkers) != 1 {
|
if len(second.Config.Pipelines) != 0 || *second.Config.Concurrency.Workers != defaultWorkers {
|
||||||
t.Fatalf("defaults aliased across loads: %#v", second.Config)
|
t.Fatalf("defaults aliased across loads: %#v", second.Config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResolveInput struct {
|
type ResolveInput struct {
|
||||||
|
CacheOverride *pipeline.CacheMode
|
||||||
PipelineID string
|
PipelineID string
|
||||||
Only []string
|
Only []string
|
||||||
Catalog pipeline.ModuleCatalog
|
Catalog pipeline.ModuleCatalog
|
||||||
@@ -26,7 +28,14 @@ type EffectiveConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) Resolve(input ResolveInput) (EffectiveConfig, error) {
|
func (c Config) Resolve(input ResolveInput) (EffectiveConfig, error) {
|
||||||
c = c.withDerivedStageWorkers()
|
c = cloneConfig(c)
|
||||||
|
if c.CacheDirectory == "" {
|
||||||
|
var err error
|
||||||
|
c.CacheDirectory, err = DefaultCacheRoot(os.UserCacheDir)
|
||||||
|
if err != nil {
|
||||||
|
return EffectiveConfig{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := c.Validate(); err != nil {
|
if err := c.Validate(); err != nil {
|
||||||
return EffectiveConfig{}, err
|
return EffectiveConfig{}, err
|
||||||
}
|
}
|
||||||
@@ -45,6 +54,7 @@ func (c Config) Resolve(input ResolveInput) (EffectiveConfig, error) {
|
|||||||
|
|
||||||
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{
|
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{
|
||||||
Only: input.Only,
|
Only: input.Only,
|
||||||
|
CacheOverride: cloneValue(input.CacheOverride),
|
||||||
LLMProfileOverride: input.LLMProfileOverride,
|
LLMProfileOverride: input.LLMProfileOverride,
|
||||||
ReferenceOverrides: append([]pipeline.ReferenceBinding(nil), input.ReferenceOverrides...),
|
ReferenceOverrides: append([]pipeline.ReferenceBinding(nil), input.ReferenceOverrides...),
|
||||||
ReferenceUnbinds: append([]pipeline.ReferenceUnbind(nil), input.ReferenceUnbinds...),
|
ReferenceUnbinds: append([]pipeline.ReferenceUnbind(nil), input.ReferenceUnbinds...),
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ func TestPipelineInheritancePreservesAndUpsertsSteps(t *testing.T) {
|
|||||||
pipelines:
|
pipelines:
|
||||||
parent:
|
parent:
|
||||||
input: {module: input}
|
input: {module: input}
|
||||||
structured_output_repair_attempts: 2
|
max_additional_turns: 2
|
||||||
steps:
|
steps:
|
||||||
- id: prepare
|
- id: prepare
|
||||||
artifacts:
|
artifacts:
|
||||||
score:
|
score:
|
||||||
extract: {module: extract, retries: 2}
|
extract: {module: extract, max_additional_turns: 2}
|
||||||
- id: summarize
|
- id: summarize
|
||||||
artifacts:
|
artifacts:
|
||||||
notes:
|
notes:
|
||||||
@@ -54,7 +54,7 @@ pipelines:
|
|||||||
child:
|
child:
|
||||||
extends: parent
|
extends: parent
|
||||||
llm_profile: local
|
llm_profile: local
|
||||||
structured_output_repair_attempts: 0` + test.childSteps + "\n"
|
max_additional_turns: 0` + test.childSteps + "\n"
|
||||||
loaded, err := loadConfigSource(configkit.Bytes("inheritance.yml", []byte(source)), LoadOptions{})
|
loaded, err := loadConfigSource(configkit.Bytes("inheritance.yml", []byte(source)), LoadOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("loadConfigSource() error = %v", err)
|
t.Fatalf("loadConfigSource() error = %v", err)
|
||||||
@@ -66,10 +66,10 @@ pipelines:
|
|||||||
t.Fatalf("parent/child inputs = %#v / %#v", parent.Input, child.Input)
|
t.Fatalf("parent/child inputs = %#v / %#v", parent.Input, child.Input)
|
||||||
}
|
}
|
||||||
if child.LLMProfile != "local" ||
|
if child.LLMProfile != "local" ||
|
||||||
child.StructuredOutputRepairAttempts == nil || *child.StructuredOutputRepairAttempts != 0 {
|
child.MaxAdditionalTurns == nil || *child.MaxAdditionalTurns != 0 {
|
||||||
t.Fatalf("child overrides = %#v", child)
|
t.Fatalf("child overrides = %#v", child)
|
||||||
}
|
}
|
||||||
if parent.StructuredOutputRepairAttempts == nil || *parent.StructuredOutputRepairAttempts != 2 {
|
if parent.MaxAdditionalTurns == nil || *parent.MaxAdditionalTurns != 2 {
|
||||||
t.Fatalf("parent settings changed: %#v", parent)
|
t.Fatalf("parent settings changed: %#v", parent)
|
||||||
}
|
}
|
||||||
if len(child.Steps) != len(test.wantStepIDs) {
|
if len(child.Steps) != len(test.wantStepIDs) {
|
||||||
@@ -116,20 +116,20 @@ pipelines:
|
|||||||
input: {module: input}
|
input: {module: input}
|
||||||
artifacts:
|
artifacts:
|
||||||
base:
|
base:
|
||||||
extract: {module: extract, retries: 2}
|
extract: {module: extract, max_additional_turns: 2}
|
||||||
derived:
|
derived:
|
||||||
extends: base
|
extends: base
|
||||||
extract: {retries: 4}
|
extract: {max_additional_turns: 4}
|
||||||
`)), LoadOptions{})
|
`)), LoadOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("loadConfigSource() error = %v", err)
|
t.Fatalf("loadConfigSource() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lanes := loaded.Config.Pipelines["session"].Artifacts
|
lanes := loaded.Config.Pipelines["session"].Artifacts
|
||||||
if lanes["base"].Extract.Module != "extract" || lanes["base"].Extract.Retries != 2 {
|
if lanes["base"].Extract.Module != "extract" || *lanes["base"].Extract.MaxAdditionalTurns != 2 {
|
||||||
t.Fatalf("base lane = %#v", lanes["base"])
|
t.Fatalf("base lane = %#v", lanes["base"])
|
||||||
}
|
}
|
||||||
if lanes["derived"].Extract.Module != "extract" || lanes["derived"].Extract.Retries != 4 {
|
if lanes["derived"].Extract.Module != "extract" || *lanes["derived"].Extract.MaxAdditionalTurns != 4 {
|
||||||
t.Fatalf("derived lane = %#v", lanes["derived"])
|
t.Fatalf("derived lane = %#v", lanes["derived"])
|
||||||
}
|
}
|
||||||
if _, err := loaded.Config.Resolve(ResolveInput{PipelineID: "session", Catalog: effectiveCatalog(t)}); err != nil {
|
if _, err := loaded.Config.Resolve(ResolveInput{PipelineID: "session", Catalog: effectiveCatalog(t)}); err != nil {
|
||||||
@@ -144,7 +144,7 @@ func TestInheritedPresenceOverridesRemainExplicit(t *testing.T) {
|
|||||||
pipelines:
|
pipelines:
|
||||||
parent:
|
parent:
|
||||||
input: {module: input}
|
input: {module: input}
|
||||||
structured_output_repair_attempts: 3
|
max_additional_turns: 3
|
||||||
chunk:
|
chunk:
|
||||||
module: generic
|
module: generic
|
||||||
validators: []
|
validators: []
|
||||||
@@ -155,7 +155,7 @@ pipelines:
|
|||||||
validators: [{module: configured-a}]
|
validators: [{module: configured-a}]
|
||||||
child:
|
child:
|
||||||
extends: parent
|
extends: parent
|
||||||
structured_output_repair_attempts: 0
|
max_additional_turns: 0
|
||||||
artifacts:
|
artifacts:
|
||||||
score:
|
score:
|
||||||
extract:
|
extract:
|
||||||
@@ -178,11 +178,11 @@ pipelines:
|
|||||||
parent.Artifacts["score"].Extract.Validators.Validators[0].Module != "configured-a" {
|
parent.Artifacts["score"].Extract.Validators.Validators[0].Module != "configured-a" {
|
||||||
t.Fatalf("parent extraction validators = %#v", parent.Artifacts["score"].Extract.Validators)
|
t.Fatalf("parent extraction validators = %#v", parent.Artifacts["score"].Extract.Validators)
|
||||||
}
|
}
|
||||||
if parent.StructuredOutputRepairAttempts == nil || *parent.StructuredOutputRepairAttempts != 3 {
|
if parent.MaxAdditionalTurns == nil || *parent.MaxAdditionalTurns != 3 {
|
||||||
t.Fatalf("parent repair budget = %#v", parent.StructuredOutputRepairAttempts)
|
t.Fatalf("parent turn allowance = %#v", parent.MaxAdditionalTurns)
|
||||||
}
|
}
|
||||||
if child.StructuredOutputRepairAttempts == nil || *child.StructuredOutputRepairAttempts != 0 {
|
if child.MaxAdditionalTurns == nil || *child.MaxAdditionalTurns != 0 {
|
||||||
t.Fatalf("child zero repair budget = %#v", child.StructuredOutputRepairAttempts)
|
t.Fatalf("child zero turn allowance = %#v", child.MaxAdditionalTurns)
|
||||||
}
|
}
|
||||||
extract := child.Artifacts["score"].Extract
|
extract := child.Artifacts["score"].Extract
|
||||||
if !extract.Validators.Set || extract.Validators.Validators == nil || len(extract.Validators.Validators) != 0 {
|
if !extract.Validators.Set || extract.Validators.Validators == nil || len(extract.Validators.Validators) != 0 {
|
||||||
@@ -197,8 +197,8 @@ pipelines:
|
|||||||
t.Fatalf("Resolve(child) error = %v", err)
|
t.Fatalf("Resolve(child) error = %v", err)
|
||||||
}
|
}
|
||||||
lanes := resolved.ResolvedPipeline.AllArtifactLanes()
|
lanes := resolved.ResolvedPipeline.AllArtifactLanes()
|
||||||
if len(lanes) != 1 || lanes[0].Extract.StructuredOutputRepairAttempts == nil || *lanes[0].Extract.StructuredOutputRepairAttempts != 0 {
|
if len(lanes) != 1 || lanes[0].Extract.MaxAdditionalTurns == nil || *lanes[0].Extract.MaxAdditionalTurns != 0 {
|
||||||
t.Fatalf("resolved child repair budget = %#v", lanes)
|
t.Fatalf("resolved child turn allowance = %#v", lanes)
|
||||||
}
|
}
|
||||||
if !resolved.ResolvedPipeline.Chunk.Validators.Set || len(resolved.ResolvedPipeline.Chunk.Validators.Validators) != 0 ||
|
if !resolved.ResolvedPipeline.Chunk.Validators.Set || len(resolved.ResolvedPipeline.Chunk.Validators.Validators) != 0 ||
|
||||||
!lanes[0].Extract.Validators.Set || len(lanes[0].Extract.Validators.Validators) != 0 {
|
!lanes[0].Extract.Validators.Set || len(lanes[0].Extract.Validators.Validators) != 0 {
|
||||||
@@ -234,42 +234,6 @@ pipelines:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInheritedAndDirectNullRepairBudgetsRemainInvalid(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
for _, test := range []struct {
|
|
||||||
name string
|
|
||||||
source string
|
|
||||||
path string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "child null",
|
|
||||||
source: `version: 6
|
|
||||||
pipelines:
|
|
||||||
parent: {input: {module: input}, structured_output_repair_attempts: 2}
|
|
||||||
child:
|
|
||||||
extends: parent
|
|
||||||
structured_output_repair_attempts: null
|
|
||||||
`,
|
|
||||||
path: "/pipelines/child/structured_output_repair_attempts",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "inherited null",
|
|
||||||
source: `version: 6
|
|
||||||
pipelines:
|
|
||||||
parent: {input: {module: input}, structured_output_repair_attempts: null}
|
|
||||||
child: {extends: parent}
|
|
||||||
`,
|
|
||||||
path: "/pipelines/parent/structured_output_repair_attempts",
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
_, err := loadConfigSource(configkit.Bytes("null.yml", []byte(test.source)), LoadOptions{})
|
|
||||||
assertDocumentDiagnosticAt(t, err, test.path)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestOverlayInheritancePrecedesOverrides(t *testing.T) {
|
func TestOverlayInheritancePrecedesOverrides(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -283,12 +247,12 @@ func TestOverlayInheritancePrecedesOverrides(t *testing.T) {
|
|||||||
pipelines:
|
pipelines:
|
||||||
parent:
|
parent:
|
||||||
input: {module: input}
|
input: {module: input}
|
||||||
structured_output_repair_attempts: 1
|
max_additional_turns: 1
|
||||||
inherited:
|
inherited:
|
||||||
extends: parent
|
extends: parent
|
||||||
overridden:
|
overridden:
|
||||||
extends: parent
|
extends: parent
|
||||||
structured_output_repair_attempts: 0
|
max_additional_turns: 0
|
||||||
cancelled:
|
cancelled:
|
||||||
extends: parent
|
extends: parent
|
||||||
input: {module: input}
|
input: {module: input}
|
||||||
@@ -297,7 +261,7 @@ pipelines:
|
|||||||
}
|
}
|
||||||
if err := os.WriteFile(filepath.Join(overlays, "development.yml"), []byte(`pipelines:
|
if err := os.WriteFile(filepath.Join(overlays, "development.yml"), []byte(`pipelines:
|
||||||
parent:
|
parent:
|
||||||
structured_output_repair_attempts: 2
|
max_additional_turns: 2
|
||||||
cancelled:
|
cancelled:
|
||||||
extends: null
|
extends: null
|
||||||
`), 0o600); err != nil {
|
`), 0o600); err != nil {
|
||||||
@@ -308,32 +272,32 @@ pipelines:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Load() error = %v", err)
|
t.Fatalf("Load() error = %v", err)
|
||||||
}
|
}
|
||||||
if got := *loaded.Config.Pipelines["inherited"].StructuredOutputRepairAttempts; got != 2 {
|
if got := *loaded.Config.Pipelines["inherited"].MaxAdditionalTurns; got != 2 {
|
||||||
t.Fatalf("overlay-inherited repair budget = %d, want 2", got)
|
t.Fatalf("overlay-inherited turn allowance = %d, want 2", got)
|
||||||
}
|
}
|
||||||
if got := *loaded.Config.Pipelines["overridden"].StructuredOutputRepairAttempts; got != 0 {
|
if got := *loaded.Config.Pipelines["overridden"].MaxAdditionalTurns; got != 0 {
|
||||||
t.Fatalf("child replacement repair budget = %d, want 0", got)
|
t.Fatalf("child replacement turn allowance = %d, want 0", got)
|
||||||
}
|
}
|
||||||
if loaded.Config.Pipelines["cancelled"].StructuredOutputRepairAttempts != nil {
|
if loaded.Config.Pipelines["cancelled"].MaxAdditionalTurns != nil {
|
||||||
t.Fatalf("cancelled child inherited parent settings: %#v", loaded.Config.Pipelines["cancelled"])
|
t.Fatalf("cancelled child inherited parent settings: %#v", loaded.Config.Pipelines["cancelled"])
|
||||||
}
|
}
|
||||||
|
|
||||||
withOverride, err := Load(main, LoadOptions{
|
withOverride, err := Load(main, LoadOptions{
|
||||||
Overlay: "development",
|
Overlay: "development",
|
||||||
Overrides: []configkit.Override{{
|
Overrides: []configkit.Override{{
|
||||||
Path: configkit.Keys("pipelines", "parent", "structured_output_repair_attempts"),
|
Path: configkit.Keys("pipelines", "parent", "max_additional_turns"),
|
||||||
Value: 3,
|
Value: 3,
|
||||||
Flag: "--repair-budget",
|
Flag: "--set",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Load() with explicit override error = %v", err)
|
t.Fatalf("Load() with explicit override error = %v", err)
|
||||||
}
|
}
|
||||||
if got := *withOverride.Config.Pipelines["inherited"].StructuredOutputRepairAttempts; got != 2 {
|
if got := *withOverride.Config.Pipelines["inherited"].MaxAdditionalTurns; got != 2 {
|
||||||
t.Fatalf("inherited repair budget after parent override = %d, want 2", got)
|
t.Fatalf("inherited turn allowance after parent override = %d, want 2", got)
|
||||||
}
|
}
|
||||||
if got := *withOverride.Config.Pipelines["parent"].StructuredOutputRepairAttempts; got != 3 {
|
if got := *withOverride.Config.Pipelines["parent"].MaxAdditionalTurns; got != 3 {
|
||||||
t.Fatalf("parent override repair budget = %d, want 3", got)
|
t.Fatalf("parent override turn allowance = %d, want 3", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +429,7 @@ func TestInheritedInspectionRetainsOriginsRedactionAndOwnership(t *testing.T) {
|
|||||||
if err := os.WriteFile(parentFile, []byte(`pipelines:
|
if err := os.WriteFile(parentFile, []byte(`pipelines:
|
||||||
parent:
|
parent:
|
||||||
input: {module: input}
|
input: {module: input}
|
||||||
structured_output_repair_attempts: 2
|
max_additional_turns: 2
|
||||||
references:
|
references:
|
||||||
source: {path: ./shared.txt}
|
source: {path: ./shared.txt}
|
||||||
artifacts:
|
artifacts:
|
||||||
@@ -485,7 +449,7 @@ func TestInheritedInspectionRetainsOriginsRedactionAndOwnership(t *testing.T) {
|
|||||||
if err := os.WriteFile(childFile, []byte(`pipelines:
|
if err := os.WriteFile(childFile, []byte(`pipelines:
|
||||||
child:
|
child:
|
||||||
extends: parent
|
extends: parent
|
||||||
structured_output_repair_attempts: 0
|
max_additional_turns: 0
|
||||||
`), 0o600); err != nil {
|
`), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -518,8 +482,8 @@ config:
|
|||||||
if got := child.References["source"].Path; got != wantPath {
|
if got := child.References["source"].Path; got != wantPath {
|
||||||
t.Fatalf("runtime inherited path = %q, want %q", got, wantPath)
|
t.Fatalf("runtime inherited path = %q, want %q", got, wantPath)
|
||||||
}
|
}
|
||||||
if child.StructuredOutputRepairAttempts == nil || *child.StructuredOutputRepairAttempts != 0 {
|
if child.MaxAdditionalTurns == nil || *child.MaxAdditionalTurns != 0 {
|
||||||
t.Fatalf("runtime inherited repair setting = %#v", child.StructuredOutputRepairAttempts)
|
t.Fatalf("runtime inherited turn allowance = %#v", child.MaxAdditionalTurns)
|
||||||
}
|
}
|
||||||
|
|
||||||
var effective bytes.Buffer
|
var effective bytes.Buffer
|
||||||
@@ -527,7 +491,7 @@ config:
|
|||||||
t.Fatalf("WriteEffective() error = %v", err)
|
t.Fatalf("WriteEffective() error = %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(effective.String(), wantPath) || strings.Contains(effective.String(), "extends:") ||
|
if !strings.Contains(effective.String(), wantPath) || strings.Contains(effective.String(), "extends:") ||
|
||||||
!strings.Contains(effective.String(), "structured_output_repair_attempts: 0") {
|
!strings.Contains(effective.String(), "max_additional_turns: 0") {
|
||||||
t.Fatalf("effective configuration is inconsistent with runtime conversion: %s", effective.String())
|
t.Fatalf("effective configuration is inconsistent with runtime conversion: %s", effective.String())
|
||||||
}
|
}
|
||||||
for _, secret := range []string{"fake-parent-secret", "fake-overlay-secret"} {
|
for _, secret := range []string{"fake-parent-secret", "fake-overlay-secret"} {
|
||||||
@@ -540,7 +504,7 @@ config:
|
|||||||
name string
|
name string
|
||||||
path configkit.Path
|
path configkit.Path
|
||||||
}{
|
}{
|
||||||
{name: "repair setting", path: configkit.Keys("pipelines", "child", "structured_output_repair_attempts")},
|
{name: "turn allowance", path: configkit.Keys("pipelines", "child", "max_additional_turns")},
|
||||||
{name: "normalized reference", path: configkit.Keys("pipelines", "child", "references", "source", "path")},
|
{name: "normalized reference", path: configkit.Keys("pipelines", "child", "references", "source", "path")},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -72,23 +72,11 @@ func documentDefinition(state *documentLoadState) configkit.Definition[Document]
|
|||||||
|
|
||||||
func documentDefaults() Document {
|
func documentDefaults() Document {
|
||||||
return Document{
|
return Document{
|
||||||
Pipelines: map[string]PipelineDocument{},
|
Pipelines: map[string]PipelineDocument{},
|
||||||
Concurrency: &ConcurrencyDocument{
|
Concurrency: &ConcurrencyDocument{Workers: documentValue(defaultWorkers)},
|
||||||
TotalLLM: documentValue(defaultLLMConcurrency),
|
Output: &OutputDocument{Directory: documentValue("./notarius-output")},
|
||||||
StageWorkers: map[string]int{},
|
CacheDirectory: documentValue(""),
|
||||||
},
|
Debug: &DebugDocument{Directory: documentValue("/tmp/notarius-debug")},
|
||||||
Output: &OutputDocument{Directory: documentValue("./notarius-output")},
|
|
||||||
Cache: &CacheDocument{
|
|
||||||
ChunkPlans: &ChunkPlanCacheDocument{
|
|
||||||
Directory: documentValue(""),
|
|
||||||
Mode: documentValue("auto"),
|
|
||||||
},
|
|
||||||
Checkpoints: &CheckpointCacheDocument{
|
|
||||||
Enabled: documentValue(false),
|
|
||||||
Directory: documentValue(""),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Debug: &DebugDocument{Directory: documentValue("./notarius-debug")},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,36 +112,14 @@ func newLoadedConfig(result *configkit.Result[Document]) (*LoadedConfig, error)
|
|||||||
func documentToConfig(document Document) (Config, error) {
|
func documentToConfig(document Document) (Config, error) {
|
||||||
config := Default()
|
config := Default()
|
||||||
config.Pipelines = documentPipelinesToRuntime(document.Pipelines)
|
config.Pipelines = documentPipelinesToRuntime(document.Pipelines)
|
||||||
if document.Concurrency != nil {
|
if document.Concurrency != nil && document.Concurrency.Workers != nil {
|
||||||
config.Concurrency.StageWorkers = documentIntMap(document.Concurrency.StageWorkers)
|
config.Concurrency.Workers = *document.Concurrency.Workers
|
||||||
if document.Concurrency.TotalLLM != nil {
|
|
||||||
config.Concurrency.TotalLLM = *document.Concurrency.TotalLLM
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if document.Output != nil && document.Output.Directory != nil {
|
if document.Output != nil && document.Output.Directory != nil {
|
||||||
config.Output.Directory = *document.Output.Directory
|
config.Output.Directory = *document.Output.Directory
|
||||||
}
|
}
|
||||||
if document.Cache != nil {
|
if document.CacheDirectory != nil {
|
||||||
if document.Cache.ChunkPlans != nil {
|
config.CacheDirectory = *document.CacheDirectory
|
||||||
if document.Cache.ChunkPlans.Directory != nil {
|
|
||||||
config.Cache.ChunkPlans.Directory = *document.Cache.ChunkPlans.Directory
|
|
||||||
}
|
|
||||||
if document.Cache.ChunkPlans.Mode != nil {
|
|
||||||
mode, err := pipeline.ParseChunkCacheMode(*document.Cache.ChunkPlans.Mode)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, fmt.Errorf("convert chunk-plan cache mode: %w", err)
|
|
||||||
}
|
|
||||||
config.Cache.ChunkPlans.Mode = mode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if document.Cache.Checkpoints != nil {
|
|
||||||
if document.Cache.Checkpoints.Enabled != nil {
|
|
||||||
config.Cache.Checkpoints.Enabled = *document.Cache.Checkpoints.Enabled
|
|
||||||
}
|
|
||||||
if document.Cache.Checkpoints.Directory != nil {
|
|
||||||
config.Cache.Checkpoints.Directory = *document.Cache.Checkpoints.Directory
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if document.Debug != nil && document.Debug.Directory != nil {
|
if document.Debug != nil && document.Debug.Directory != nil {
|
||||||
config.Debug.Directory = *document.Debug.Directory
|
config.Debug.Directory = *document.Debug.Directory
|
||||||
@@ -162,12 +140,13 @@ func documentPipelinesToRuntime(documents map[string]PipelineDocument) map[strin
|
|||||||
|
|
||||||
func documentPipelineToRuntime(id string, document PipelineDocument) pipeline.PipelineProfile {
|
func documentPipelineToRuntime(id string, document PipelineDocument) pipeline.PipelineProfile {
|
||||||
profile := pipeline.PipelineProfile{
|
profile := pipeline.PipelineProfile{
|
||||||
ID: id,
|
Mode: cloneValue(document.Mode),
|
||||||
StructuredOutputRepairAttempts: cloneDocumentInt(document.StructuredOutputRepairAttempts),
|
MaxAdditionalTurns: cloneValue(document.MaxAdditionalTurns),
|
||||||
ValidationPolicy: documentPolicyToRuntime(document.ValidationPolicy),
|
Cache: cloneValue(document.Cache),
|
||||||
Input: documentBindingToRuntime(document.Input),
|
ID: id,
|
||||||
Artifacts: documentLanesToRuntime(document.Artifacts),
|
Input: documentBindingToRuntime(document.Input),
|
||||||
References: documentReferencesToRuntime(document.References),
|
Artifacts: documentLanesToRuntime(document.Artifacts),
|
||||||
|
References: documentReferencesToRuntime(document.References),
|
||||||
}
|
}
|
||||||
if document.LLMProfile != nil {
|
if document.LLMProfile != nil {
|
||||||
profile.LLMProfile = *document.LLMProfile
|
profile.LLMProfile = *document.LLMProfile
|
||||||
@@ -220,12 +199,12 @@ func documentLanesToRuntime(documents map[string]ArtifactLaneDocument) map[strin
|
|||||||
|
|
||||||
func documentBindingToRuntime(document BindingDocument) pipeline.ModuleBinding {
|
func documentBindingToRuntime(document BindingDocument) pipeline.ModuleBinding {
|
||||||
binding := pipeline.ModuleBinding{
|
binding := pipeline.ModuleBinding{
|
||||||
Module: document.Module,
|
Mode: cloneValue(document.Mode),
|
||||||
StructuredOutputRepairAttempts: cloneDocumentInt(document.StructuredOutputRepairAttempts),
|
MaxAdditionalTurns: cloneValue(document.MaxAdditionalTurns),
|
||||||
ValidationPolicy: documentPolicyToRuntime(document.ValidationPolicy),
|
Cache: cloneValue(document.Cache),
|
||||||
Retries: document.Retries,
|
Module: document.Module,
|
||||||
Options: documentOptions(document.Options),
|
Options: documentOptions(document.Options),
|
||||||
References: documentReferencesToRuntime(document.References),
|
References: documentReferencesToRuntime(document.References),
|
||||||
}
|
}
|
||||||
if document.LLMProfile != nil {
|
if document.LLMProfile != nil {
|
||||||
binding.LLMProfile = *document.LLMProfile
|
binding.LLMProfile = *document.LLMProfile
|
||||||
@@ -242,10 +221,8 @@ func documentBindingToRuntime(document BindingDocument) pipeline.ModuleBinding {
|
|||||||
|
|
||||||
func documentValidatorToRuntime(document ValidatorDocument) pipeline.ModuleBinding {
|
func documentValidatorToRuntime(document ValidatorDocument) pipeline.ModuleBinding {
|
||||||
binding := pipeline.ModuleBinding{
|
binding := pipeline.ModuleBinding{
|
||||||
Module: document.Module,
|
Module: document.Module,
|
||||||
StructuredOutputRepairAttempts: cloneDocumentInt(document.StructuredOutputRepairAttempts),
|
Options: documentOptions(document.Options),
|
||||||
Retries: document.Retries,
|
|
||||||
Options: documentOptions(document.Options),
|
|
||||||
}
|
}
|
||||||
if document.LLMProfile != nil {
|
if document.LLMProfile != nil {
|
||||||
binding.LLMProfile = *document.LLMProfile
|
binding.LLMProfile = *document.LLMProfile
|
||||||
@@ -270,45 +247,6 @@ func documentReferencesToRuntime(documents map[string]ReferenceDocument) map[str
|
|||||||
return references
|
return references
|
||||||
}
|
}
|
||||||
|
|
||||||
func documentPolicyToRuntime(document *ValidationPolicyDocument) *pipeline.ValidationPolicyOverride {
|
|
||||||
if document == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
policy := pipeline.ValidationPolicyOverride{}
|
|
||||||
if document.ProducerStructuralFailure != nil {
|
|
||||||
value := *document.ProducerStructuralFailure
|
|
||||||
policy.ProducerStructuralFailure = &value
|
|
||||||
}
|
|
||||||
if document.SemanticRejection != nil {
|
|
||||||
value := *document.SemanticRejection
|
|
||||||
policy.SemanticRejection = &value
|
|
||||||
}
|
|
||||||
if document.ValidatorFailure != nil {
|
|
||||||
value := *document.ValidatorFailure
|
|
||||||
policy.ValidatorFailure = &value
|
|
||||||
}
|
|
||||||
return &policy
|
|
||||||
}
|
|
||||||
|
|
||||||
func documentIntMap(values map[string]int) map[string]int {
|
|
||||||
if values == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
result := make(map[string]int, len(values))
|
|
||||||
for key, value := range values {
|
|
||||||
result[key] = value
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneDocumentInt(value *int) *int {
|
|
||||||
if value == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
result := *value
|
|
||||||
return &result
|
|
||||||
}
|
|
||||||
|
|
||||||
func documentOptions(values map[string]any) map[string]any {
|
func documentOptions(values map[string]any) map[string]any {
|
||||||
if values == nil {
|
if values == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func TestLoadedConfigConvertsDocumentsAndResolvesRuntimePipeline(t *testing.T) {
|
|||||||
pipelines:
|
pipelines:
|
||||||
session:
|
session:
|
||||||
llm_profile: local
|
llm_profile: local
|
||||||
structured_output_repair_attempts: 0
|
max_additional_turns: 0
|
||||||
input:
|
input:
|
||||||
module: input
|
module: input
|
||||||
chunk:
|
chunk:
|
||||||
@@ -69,7 +69,7 @@ pipelines:
|
|||||||
t.Fatalf("loadConfigSource() error = %v", err)
|
t.Fatalf("loadConfigSource() error = %v", err)
|
||||||
}
|
}
|
||||||
profile := loaded.Config.Pipelines["session"]
|
profile := loaded.Config.Pipelines["session"]
|
||||||
if profile.LLMProfile != "local" || profile.StructuredOutputRepairAttempts == nil || *profile.StructuredOutputRepairAttempts != 0 {
|
if profile.LLMProfile != "local" || profile.MaxAdditionalTurns == nil || *profile.MaxAdditionalTurns != 0 {
|
||||||
t.Fatalf("pipeline profile = %#v", profile)
|
t.Fatalf("pipeline profile = %#v", profile)
|
||||||
}
|
}
|
||||||
if !profile.Chunk.Validators.Set || profile.Chunk.Validators.Validators == nil || len(profile.Chunk.Validators.Validators) != 0 {
|
if !profile.Chunk.Validators.Set || profile.Chunk.Validators.Validators == nil || len(profile.Chunk.Validators.Validators) != 0 {
|
||||||
@@ -177,8 +177,8 @@ pipelines:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestOverrideCannotRepairTypedDecodeFailure(t *testing.T) {
|
func TestOverrideCannotRepairTypedDecodeFailure(t *testing.T) {
|
||||||
_, err := loadConfigSource(configkit.Bytes("invalid.yml", []byte("version: 6\nconcurrency: {total_llm: invalid}\n")), LoadOptions{
|
_, err := loadConfigSource(configkit.Bytes("invalid.yml", []byte("version: 6\nconcurrency: {workers: invalid}\n")), LoadOptions{
|
||||||
Overrides: []configkit.Override{{Path: configkit.Keys("concurrency", "total_llm"), Value: 2, Flag: "--total-llm"}},
|
Overrides: []configkit.Override{{Path: configkit.Keys("concurrency", "workers"), Value: 2, Flag: "--workers"}},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("override unexpectedly repaired invalid typed input")
|
t.Fatal("override unexpectedly repaired invalid typed input")
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,13 +14,15 @@ func resolveDocumentOperations(document *Document, resolution *configkit.Resolut
|
|||||||
}
|
}
|
||||||
normalizeDocumentState(document, resolution)
|
normalizeDocumentState(document, resolution)
|
||||||
normalizeDocumentPaths(document, resolution, state)
|
normalizeDocumentPaths(document, resolution, state)
|
||||||
normalizeDocumentPipelines(document, resolution, state)
|
if document.CacheDirectory != nil && *document.CacheDirectory == "" {
|
||||||
if document.Concurrency != nil {
|
root, err := DefaultCacheRoot(os.UserCacheDir)
|
||||||
document.Concurrency.StageWorkers = normalizeDocumentMap(document.Concurrency.StageWorkers,
|
if err != nil {
|
||||||
configkit.Keys("concurrency", "stage_workers"), "stage worker identifier",
|
return err
|
||||||
documentNormalizer{Resolution: resolution}, state)
|
}
|
||||||
|
// Empty is an explicit selection of the per-user default, not a physical root.
|
||||||
|
configkit.Normalize(resolution, configkit.Keys("cache_directory"), &document.CacheDirectory, documentValue(root), "selected per-user cache directory")
|
||||||
}
|
}
|
||||||
deriveDocumentExtractWorkers(document, resolution, state)
|
normalizeDocumentPipelines(document, resolution, state)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +30,7 @@ func normalizeDocumentState(document *Document, resolution *configkit.Resolution
|
|||||||
if document.Output != nil {
|
if document.Output != nil {
|
||||||
normalizeDocumentString(resolution, configkit.Keys("output", "directory"), &document.Output.Directory, "trimmed output directory")
|
normalizeDocumentString(resolution, configkit.Keys("output", "directory"), &document.Output.Directory, "trimmed output directory")
|
||||||
}
|
}
|
||||||
if document.Cache != nil {
|
normalizeDocumentString(resolution, configkit.Keys("cache_directory"), &document.CacheDirectory, "trimmed cache directory")
|
||||||
if document.Cache.ChunkPlans != nil {
|
|
||||||
normalizeDocumentString(resolution, configkit.Keys("cache", "chunk_plans", "directory"), &document.Cache.ChunkPlans.Directory, "trimmed chunk-plan cache directory")
|
|
||||||
normalizeDocumentString(resolution, configkit.Keys("cache", "chunk_plans", "mode"), &document.Cache.ChunkPlans.Mode, "trimmed chunk-plan cache mode")
|
|
||||||
}
|
|
||||||
if document.Cache.Checkpoints != nil {
|
|
||||||
normalizeDocumentString(resolution, configkit.Keys("cache", "checkpoints", "directory"), &document.Cache.Checkpoints.Directory, "trimmed checkpoint cache directory")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if document.Debug != nil {
|
if document.Debug != nil {
|
||||||
normalizeDocumentString(resolution, configkit.Keys("debug", "directory"), &document.Debug.Directory, "trimmed debug directory")
|
normalizeDocumentString(resolution, configkit.Keys("debug", "directory"), &document.Debug.Directory, "trimmed debug directory")
|
||||||
}
|
}
|
||||||
@@ -50,120 +43,36 @@ func normalizeDocumentString(resolution *configkit.Resolution, path configkit.Pa
|
|||||||
configkit.Normalize(resolution, path, target, documentValue(strings.TrimSpace(**target)), reason)
|
configkit.Normalize(resolution, path, target, documentValue(strings.TrimSpace(**target)), reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deriveDocumentExtractWorkers(document *Document, resolution *configkit.Resolution, state *documentLoadState) {
|
|
||||||
if document.Concurrency == nil || document.Concurrency.TotalLLM == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if document.Concurrency.StageWorkers == nil {
|
|
||||||
document.Concurrency.StageWorkers = make(map[string]int)
|
|
||||||
}
|
|
||||||
path := configkit.Keys("concurrency", "stage_workers", "extract")
|
|
||||||
// Presence belongs to the input spelling, not the key produced by trimming.
|
|
||||||
// A moved explicit count must never be replaced by a derived default.
|
|
||||||
if resolution.IsExplicit(state.originalPath(path)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
workers := document.Concurrency.StageWorkers
|
|
||||||
value := workers["extract"]
|
|
||||||
configkit.Default(resolution, path, &value, *document.Concurrency.TotalLLM,
|
|
||||||
"derived extraction workers from total LLM concurrency", configkit.Keys("concurrency", "total_llm"))
|
|
||||||
workers["extract"] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateDocumentOperations(document *Document, validation *configkit.Validation) {
|
func validateDocumentOperations(document *Document, validation *configkit.Validation) {
|
||||||
if document == nil {
|
if document == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
validateDocumentConcurrency(document.Concurrency, validation)
|
if document.Concurrency == nil || document.Concurrency.Workers == nil {
|
||||||
validateDocumentState(document, validation)
|
validation.Error(configkit.Keys("concurrency", "workers"), "must be a positive integer")
|
||||||
validateDocumentPipelines(document, validation)
|
} else if err := validateWorkers(*document.Concurrency.Workers); err != nil {
|
||||||
}
|
validation.Error(configkit.Keys("concurrency", "workers"), err.Error())
|
||||||
|
|
||||||
func validateDocumentConcurrency(concurrency *ConcurrencyDocument, validation *configkit.Validation) {
|
|
||||||
if concurrency == nil {
|
|
||||||
validation.Error(configkit.Keys("concurrency"), "must not be null")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
totalPath := configkit.Keys("concurrency", "total_llm")
|
|
||||||
if concurrency.TotalLLM == nil {
|
|
||||||
validation.Error(totalPath, "must not be null")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
totalValid := true
|
|
||||||
if err := validateTotalLLMConcurrency(*concurrency.TotalLLM); err != nil {
|
|
||||||
validation.Error(totalPath, err.Error())
|
|
||||||
totalValid = false
|
|
||||||
}
|
|
||||||
keys := make([]string, 0, len(concurrency.StageWorkers))
|
|
||||||
for key := range concurrency.StageWorkers {
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
for _, key := range keys {
|
|
||||||
if err := validateStageWorkerKey(key); err != nil {
|
|
||||||
validation.Error(configkit.Keys("concurrency", "stage_workers").Key(key), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !totalValid {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if workers, ok := concurrency.StageWorkers["extract"]; ok {
|
|
||||||
if err := validateExtractWorkerCount(workers, *concurrency.TotalLLM); err != nil {
|
|
||||||
validation.Error(configkit.Keys("concurrency", "stage_workers", "extract"), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateDocumentState(document *Document, validation *configkit.Validation) {
|
|
||||||
if document.Output == nil || document.Output.Directory == nil {
|
if document.Output == nil || document.Output.Directory == nil {
|
||||||
validation.Error(configkit.Keys("output", "directory"), "must not be empty")
|
validation.Error(configkit.Keys("output", "directory"), "must not be empty")
|
||||||
} else if err := validateRequiredPath("output.directory", *document.Output.Directory); err != nil {
|
} else if err := validateRequiredPath("output.directory", *document.Output.Directory); err != nil {
|
||||||
validation.Error(configkit.Keys("output", "directory"), err.Error())
|
validation.Error(configkit.Keys("output", "directory"), err.Error())
|
||||||
}
|
}
|
||||||
|
if document.CacheDirectory == nil {
|
||||||
if document.Cache == nil || document.Cache.ChunkPlans == nil || document.Cache.ChunkPlans.Mode == nil {
|
validation.Error(configkit.Keys("cache_directory"), "must not be null")
|
||||||
validation.Error(configkit.Keys("cache", "chunk_plans", "mode"), "must be a supported cache mode")
|
} else if err := validateOptionalPath("cache_directory", *document.CacheDirectory); err != nil {
|
||||||
} else if err := validateChunkPlanCacheMode(*document.Cache.ChunkPlans.Mode); err != nil {
|
validation.Error(configkit.Keys("cache_directory"), err.Error())
|
||||||
validation.Error(configkit.Keys("cache", "chunk_plans", "mode"), err.Error())
|
|
||||||
}
|
}
|
||||||
if document.Cache != nil && document.Cache.ChunkPlans != nil && document.Cache.ChunkPlans.Directory != nil {
|
|
||||||
if err := validateOptionalPath("cache.chunk_plans.directory", *document.Cache.ChunkPlans.Directory); err != nil {
|
|
||||||
validation.Error(configkit.Keys("cache", "chunk_plans", "directory"), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if document.Cache != nil && document.Cache.Checkpoints != nil && document.Cache.Checkpoints.Directory != nil {
|
|
||||||
if err := validateOptionalPath("cache.checkpoints.directory", *document.Cache.Checkpoints.Directory); err != nil {
|
|
||||||
validation.Error(configkit.Keys("cache", "checkpoints", "directory"), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if document.Debug == nil || document.Debug.Directory == nil {
|
if document.Debug == nil || document.Debug.Directory == nil {
|
||||||
validation.Error(configkit.Keys("debug", "directory"), "must not be empty")
|
validation.Error(configkit.Keys("debug", "directory"), "must not be null")
|
||||||
} else if err := validateRequiredPath("debug.directory", *document.Debug.Directory); err != nil {
|
} else if err := validateOptionalPath("debug.directory", *document.Debug.Directory); err != nil {
|
||||||
validation.Error(configkit.Keys("debug", "directory"), err.Error())
|
validation.Error(configkit.Keys("debug", "directory"), err.Error())
|
||||||
}
|
}
|
||||||
|
validateDocumentPipelines(document, validation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateTotalLLMConcurrency(total int) error {
|
func validateWorkers(workers int) error {
|
||||||
if total <= 0 {
|
if workers <= 0 {
|
||||||
return fmt.Errorf("total LLM concurrency must be greater than zero")
|
return fmt.Errorf("concurrency.workers must be greater than zero")
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateStageWorkerKey(key string) error {
|
|
||||||
if strings.TrimSpace(key) == "" {
|
|
||||||
return fmt.Errorf("concurrency.stage_workers key must not be empty")
|
|
||||||
}
|
|
||||||
if key != "extract" {
|
|
||||||
return fmt.Errorf("concurrency.stage_workers key %q is not supported", key)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateExtractWorkerCount(workers, total int) error {
|
|
||||||
if workers < 1 || workers > total {
|
|
||||||
return fmt.Errorf("concurrency.stage_workers.extract must be between 1 and concurrency.total_llm (%d)", total)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -174,17 +83,9 @@ func validateRequiredPath(name, value string) error {
|
|||||||
}
|
}
|
||||||
return validateOptionalPath(name, value)
|
return validateOptionalPath(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateOptionalPath(name, value string) error {
|
func validateOptionalPath(name, value string) error {
|
||||||
if strings.ContainsRune(value, '\x00') {
|
if strings.ContainsRune(value, '\x00') {
|
||||||
return fmt.Errorf("%s must not contain NUL", name)
|
return fmt.Errorf("%s must not contain NUL", name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateChunkPlanCacheMode(value string) error {
|
|
||||||
if _, err := pipeline.ParseChunkCacheMode(value); err != nil {
|
|
||||||
return fmt.Errorf("cache.chunk_plans.mode: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,203 +5,109 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkerKeyNormalizationPreservesExplicitCount(t *testing.T) {
|
func TestDocumentWorkerCount(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
name, workers string
|
name, body string
|
||||||
want int
|
want int
|
||||||
errorPath string
|
invalid bool
|
||||||
}{
|
}{
|
||||||
{name: "omitted", workers: "{}", want: 4},
|
{"omitted", "", 64, false},
|
||||||
{name: "padded", workers: "{' extract ': 2}", want: 2},
|
{"serial", "concurrency: {workers: 1}", 1, false},
|
||||||
{name: "explicit invalid", workers: "{' extract ': 0}", errorPath: "/concurrency/stage_workers/extract"},
|
{"large", "concurrency: {workers: 1000000}", 1000000, false},
|
||||||
{name: "collision", workers: "{' extract ': 2, extract: 3}", errorPath: "/concurrency/stage_workers/extract"},
|
{"zero", "concurrency: {workers: 0}", 0, true},
|
||||||
|
{"negative", "concurrency: {workers: -1}", 0, true},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
loaded, err := loadConfigSource(configkit.Bytes("workers.yml", []byte(
|
loaded, err := loadConfigSource(configkit.Bytes("workers.yml", []byte("version: 6\n"+test.body+"\n")), LoadOptions{})
|
||||||
"version: 6\nconcurrency:\n total_llm: 4\n stage_workers: "+test.workers+"\n")), LoadOptions{})
|
if test.invalid {
|
||||||
if test.errorPath != "" {
|
assertDocumentDiagnosticAt(t, err, "/concurrency/workers")
|
||||||
assertDocumentDiagnosticAt(t, err, test.errorPath)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got := loaded.Config.Concurrency.StageWorkers["extract"]; got != test.want {
|
if loaded.Config.Concurrency.Workers != test.want {
|
||||||
t.Fatalf("workers = %d, want %d", got, test.want)
|
t.Fatalf("workers = %d", loaded.Config.Concurrency.Workers)
|
||||||
}
|
|
||||||
var explanation bytes.Buffer
|
|
||||||
if err := loaded.WriteExplanation(&explanation, "/concurrency/stage_workers"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if test.name == "padded" && (!strings.Contains(explanation.String(), "normalization") ||
|
|
||||||
!strings.Contains(explanation.String(), " extract ") ||
|
|
||||||
strings.Contains(explanation.String(), "derived extraction workers")) {
|
|
||||||
t.Fatalf("explicit worker provenance = %s", explanation.String())
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocumentLoadAppliesOperationalDefaultsAndNormalization(t *testing.T) {
|
func TestDocumentStateDirectorySelection(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
userRoot, err := os.UserCacheDir()
|
||||||
loaded, err := loadDocumentSource(configkit.Bytes("document.yml", []byte(`version: 6
|
|
||||||
concurrency:
|
|
||||||
total_llm: 4
|
|
||||||
output:
|
|
||||||
directory: " ./output "
|
|
||||||
cache:
|
|
||||||
chunk_plans:
|
|
||||||
mode: " refresh "
|
|
||||||
directory: " "
|
|
||||||
checkpoints:
|
|
||||||
directory: " "
|
|
||||||
debug:
|
|
||||||
directory: " ./debug "
|
|
||||||
`)), LoadOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if loaded.Config.Concurrency.TotalLLM == nil || *loaded.Config.Concurrency.TotalLLM != 4 || loaded.Config.Concurrency.StageWorkers["extract"] != 4 {
|
for _, test := range []struct{ name, body, cache, debug string }{
|
||||||
t.Fatalf("concurrency = %#v", loaded.Config.Concurrency)
|
{"omitted", "", filepath.Join(userRoot, "notarius"), "/tmp/notarius-debug"},
|
||||||
}
|
{"empty", "cache_directory: ''\ndebug: {directory: ''}", filepath.Join(userRoot, "notarius"), ""},
|
||||||
workingDirectory, err := os.Getwd()
|
{"explicit", "cache_directory: /var/cache/fixture\ndebug: {directory: /tmp/fixture-debug}", "/var/cache/fixture", "/tmp/fixture-debug"},
|
||||||
if err != nil {
|
} {
|
||||||
t.Fatal(err)
|
t.Run(test.name, func(t *testing.T) {
|
||||||
}
|
loaded, err := loadConfigSource(configkit.Bytes("directories.yml", []byte("version: 6\n"+test.body+"\n")), LoadOptions{})
|
||||||
if loaded.Config.Output.Directory == nil || *loaded.Config.Output.Directory != filepath.Join(workingDirectory, "output") ||
|
if err != nil {
|
||||||
loaded.Config.Cache.ChunkPlans.Mode == nil || *loaded.Config.Cache.ChunkPlans.Mode != "refresh" ||
|
t.Fatal(err)
|
||||||
loaded.Config.Cache.ChunkPlans.Directory == nil || *loaded.Config.Cache.ChunkPlans.Directory != "" ||
|
}
|
||||||
loaded.Config.Cache.Checkpoints.Directory == nil || *loaded.Config.Cache.Checkpoints.Directory != "" ||
|
if loaded.Config.CacheDirectory != test.cache || loaded.Config.Debug.Directory != test.debug {
|
||||||
loaded.Config.Debug.Directory == nil || *loaded.Config.Debug.Directory != filepath.Join(workingDirectory, "debug") {
|
t.Fatalf("directories = %q, %q", loaded.Config.CacheDirectory, loaded.Config.Debug.Directory)
|
||||||
t.Fatalf("state = %#v, %#v, %#v", loaded.Config.Output, loaded.Config.Cache, loaded.Config.Debug)
|
}
|
||||||
}
|
var effective bytes.Buffer
|
||||||
if diagnostics := loaded.Diagnostics(); len(diagnostics) != 0 {
|
if err := loaded.WriteEffective(&effective); err != nil {
|
||||||
t.Fatalf("diagnostics = %#v", diagnostics)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
extractHistory := loaded.Metadata().History(configkit.Keys("concurrency", "stage_workers", "extract"))
|
})
|
||||||
if len(extractHistory) == 0 || extractHistory[len(extractHistory)-1].Origin.Operation != configkit.ChangeDerivedDefault {
|
|
||||||
t.Fatalf("extract history = %#v", extractHistory)
|
|
||||||
}
|
|
||||||
outputHistory := loaded.Metadata().History(configkit.Keys("output", "directory"))
|
|
||||||
if len(outputHistory) == 0 || outputHistory[len(outputHistory)-1].Origin.Operation != configkit.ChangeNormalization {
|
|
||||||
t.Fatalf("output history = %#v", outputHistory)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocumentLoadDerivesWorkersAfterOverlayAndCLIOverrides(t *testing.T) {
|
func TestDirectoryPathsFollowImportedSource(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
dir := t.TempDir()
|
||||||
directory := t.TempDir()
|
fragmentDir := filepath.Join(dir, "fragments")
|
||||||
main := filepath.Join(directory, "config.yml")
|
if err := os.Mkdir(fragmentDir, 0755); err != nil {
|
||||||
overlays := filepath.Join(directory, "overlays")
|
|
||||||
if err := os.Mkdir(overlays, 0o755); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(main, []byte("version: 6\nconcurrency:\n total_llm: 4\n"), 0o600); err != nil {
|
main := filepath.Join(dir, "config.yml")
|
||||||
|
if err := os.WriteFile(main, []byte("version: 6\nconfig:\n imports:\n - path: fragments/state.yml\n required: true\n"), 0600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(filepath.Join(overlays, "development.yml"), []byte("concurrency:\n total_llm: 3\n"), 0o600); err != nil {
|
if err := os.WriteFile(filepath.Join(fragmentDir, "state.yml"), []byte("cache_directory: selected\ndebug: {directory: evidence}\noutput: {directory: deliverables}\n"), 0600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
loaded, err := Load(main, LoadOptions{})
|
||||||
overlaid, err := loadDocument(main, LoadOptions{Overlay: "development"})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if overlaid.Config.Concurrency.TotalLLM == nil || *overlaid.Config.Concurrency.TotalLLM != 3 || overlaid.Config.Concurrency.StageWorkers["extract"] != 3 {
|
if loaded.Config.CacheDirectory != filepath.Join(fragmentDir, "selected") || loaded.Config.Debug.Directory != filepath.Join(fragmentDir, "evidence") || loaded.Config.Output.Directory != filepath.Join(fragmentDir, "deliverables") {
|
||||||
t.Fatalf("overlaid concurrency = %#v", overlaid.Config.Concurrency)
|
t.Fatalf("source-relative directories lost: %#v", loaded.Config)
|
||||||
}
|
|
||||||
|
|
||||||
overridden, err := loadDocument(main, LoadOptions{Overrides: []configkit.Override{{
|
|
||||||
Path: configkit.Keys("concurrency", "total_llm"), Value: 2, Flag: "--total-llm",
|
|
||||||
}}})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if overridden.Config.Concurrency.TotalLLM == nil || *overridden.Config.Concurrency.TotalLLM != 2 || overridden.Config.Concurrency.StageWorkers["extract"] != 2 {
|
|
||||||
t.Fatalf("overridden concurrency = %#v", overridden.Config.Concurrency)
|
|
||||||
}
|
|
||||||
|
|
||||||
overlaidAndOverridden, err := loadDocument(main, LoadOptions{Overlay: "development", Overrides: []configkit.Override{{
|
|
||||||
Path: configkit.Keys("concurrency", "total_llm"), Value: 2, Flag: "--total-llm",
|
|
||||||
}}})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if overlaidAndOverridden.Config.Concurrency.TotalLLM == nil || *overlaidAndOverridden.Config.Concurrency.TotalLLM != 2 || overlaidAndOverridden.Config.Concurrency.StageWorkers["extract"] != 2 {
|
|
||||||
t.Fatalf("overlaid and overridden concurrency = %#v", overlaidAndOverridden.Config.Concurrency)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocumentLoadRetainsExplicitWorkerAndRejectsInvalidOperationalValues(t *testing.T) {
|
func TestDocumentRejectsRetiredControls(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
for _, body := range []string{
|
||||||
loaded, err := loadDocumentSource(configkit.Bytes("explicit.yml", []byte(`version: 6
|
"concurrency: {total_llm: 4}",
|
||||||
concurrency:
|
"concurrency: {stage_workers: {extract: 4}}",
|
||||||
total_llm: 4
|
"cache: {chunk_plans: {mode: auto}}",
|
||||||
stage_workers:
|
"pipelines: {main: {input: {module: input}, retries: 1}}",
|
||||||
extract: 0
|
"pipelines: {main: {input: {module: input}, structured_output_repair_attempts: 0}}",
|
||||||
`)), LoadOptions{})
|
"pipelines: {main: {input: {module: input}, validation_policy: {validator_failure: fail_run}}}",
|
||||||
if loaded != nil {
|
"pipelines: {main: {input: {module: input}, chunk: {module: chunk, retries: 1}}}",
|
||||||
t.Fatalf("loaded = %#v, want validation failure", loaded.Config)
|
"pipelines: {main: {input: {module: input}, chunk: {module: chunk, validators: [{module: validate, max_additional_turns: 1}]}}}",
|
||||||
}
|
} {
|
||||||
assertDocumentDiagnostic(t, err, configkit.CodeValidateError, "/concurrency/stage_workers/extract")
|
_, err := loadConfigSource(configkit.Bytes("retired.yml", []byte("version: 6\n"+body+"\n")), LoadOptions{})
|
||||||
|
if err == nil {
|
||||||
_, err = loadDocumentSource(configkit.Bytes("invalid.yml", []byte(`version: 6
|
t.Fatalf("accepted retired controls: %s", body)
|
||||||
concurrency:
|
|
||||||
total_llm: 0
|
|
||||||
output:
|
|
||||||
directory: ""
|
|
||||||
`)), LoadOptions{})
|
|
||||||
var loadError *configkit.LoadError
|
|
||||||
if !errors.As(err, &loadError) {
|
|
||||||
t.Fatalf("error = %v, want ConfigKit load error", err)
|
|
||||||
}
|
|
||||||
seen := make(map[string]bool)
|
|
||||||
for _, diagnostic := range loadError.Diagnostics() {
|
|
||||||
if diagnostic.Code != configkit.CodeValidateError || diagnostic.Primary == nil {
|
|
||||||
t.Fatalf("diagnostic = %#v", diagnostic)
|
|
||||||
}
|
|
||||||
seen[diagnostic.Path.String()] = true
|
|
||||||
}
|
|
||||||
for _, path := range []string{"/concurrency/total_llm", "/output/directory"} {
|
|
||||||
if !seen[path] {
|
|
||||||
t.Fatalf("diagnostics missing %s: %#v", path, loadError.Diagnostics())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocumentLoadDistinguishesRequiredAndOptionalPathValues(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
loaded, err := loadDocumentSource(configkit.Bytes("cache.yml", []byte(`version: 6
|
|
||||||
cache:
|
|
||||||
chunk_plans:
|
|
||||||
directory: " "
|
|
||||||
checkpoints:
|
|
||||||
directory: " "
|
|
||||||
`)), LoadOptions{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if loaded.Config.Cache.ChunkPlans.Directory == nil || *loaded.Config.Cache.ChunkPlans.Directory != "" ||
|
|
||||||
loaded.Config.Cache.Checkpoints.Directory == nil || *loaded.Config.Cache.Checkpoints.Directory != "" {
|
|
||||||
t.Fatalf("cache directories = %#v", loaded.Config.Cache)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = loadDocumentSource(configkit.Bytes("output.yml", []byte("version: 6\noutput:\n directory: ' '\n")), LoadOptions{})
|
|
||||||
assertDocumentDiagnostic(t, err, configkit.CodeValidateError, "/output/directory")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertDocumentDiagnostic(t *testing.T, err error, code configkit.Code, path string) {
|
func assertDocumentDiagnostic(t *testing.T, err error, code configkit.Code, path string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
var loadError *configkit.LoadError
|
var loadError *configkit.LoadError
|
||||||
|
|||||||
@@ -83,10 +83,8 @@ func validateDocumentPipelinePresence(document *Document, resolution *configkit.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validatePipelineDocumentPresence(profile PipelineDocument, path configkit.Path, resolution *configkit.Resolution) {
|
func validatePipelineDocumentPresence(profile PipelineDocument, path configkit.Path, resolution *configkit.Resolution) {
|
||||||
|
validateDocumentControls(profile.Mode, profile.MaxAdditionalTurns, profile.Cache, path, validation)
|
||||||
rejectDocumentNull(resolution, path.Key("llm_profile"), profile.LLMProfile == nil)
|
rejectDocumentNull(resolution, path.Key("llm_profile"), profile.LLMProfile == nil)
|
||||||
rejectDocumentNull(resolution, path.Key("structured_output_repair_attempts"), profile.StructuredOutputRepairAttempts == nil)
|
|
||||||
rejectDocumentNull(resolution, path.Key("validation_policy"), profile.ValidationPolicy == nil)
|
|
||||||
validateDocumentPolicyPresence(profile.ValidationPolicy, path.Key("validation_policy"), resolution)
|
|
||||||
|
|
||||||
stepsPath := path.Key("steps")
|
stepsPath := path.Key("steps")
|
||||||
if resolution.IsExplicit(stepsPath) && profile.Steps == nil {
|
if resolution.IsExplicit(stepsPath) && profile.Steps == nil {
|
||||||
@@ -136,9 +134,6 @@ func validateOptionalBindingDocumentPresence(binding *BindingDocument, path conf
|
|||||||
|
|
||||||
func validateBindingDocumentPresence(binding BindingDocument, path configkit.Path, resolution *configkit.Resolution) {
|
func validateBindingDocumentPresence(binding BindingDocument, path configkit.Path, resolution *configkit.Resolution) {
|
||||||
rejectDocumentNull(resolution, path.Key("llm_profile"), binding.LLMProfile == nil)
|
rejectDocumentNull(resolution, path.Key("llm_profile"), binding.LLMProfile == nil)
|
||||||
rejectDocumentNull(resolution, path.Key("structured_output_repair_attempts"), binding.StructuredOutputRepairAttempts == nil)
|
|
||||||
rejectDocumentNull(resolution, path.Key("validation_policy"), binding.ValidationPolicy == nil)
|
|
||||||
validateDocumentPolicyPresence(binding.ValidationPolicy, path.Key("validation_policy"), resolution)
|
|
||||||
if binding.Validators == nil && resolution.IsExplicit(path.Key("validators")) {
|
if binding.Validators == nil && resolution.IsExplicit(path.Key("validators")) {
|
||||||
resolution.Error(path.Key("validators"), "must not be null")
|
resolution.Error(path.Key("validators"), "must not be null")
|
||||||
}
|
}
|
||||||
@@ -146,7 +141,6 @@ func validateBindingDocumentPresence(binding BindingDocument, path configkit.Pat
|
|||||||
for index, validator := range binding.Validators {
|
for index, validator := range binding.Validators {
|
||||||
validatorPath := path.Key("validators").Index(index)
|
validatorPath := path.Key("validators").Index(index)
|
||||||
rejectDocumentNull(resolution, validatorPath.Key("llm_profile"), validator.LLMProfile == nil)
|
rejectDocumentNull(resolution, validatorPath.Key("llm_profile"), validator.LLMProfile == nil)
|
||||||
rejectDocumentNull(resolution, validatorPath.Key("structured_output_repair_attempts"), validator.StructuredOutputRepairAttempts == nil)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,16 +159,8 @@ func rejectDocumentNull(resolution *configkit.Resolution, path configkit.Path, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDocumentPolicyPresence(policy *ValidationPolicyDocument, path configkit.Path, resolution *configkit.Resolution) {
|
|
||||||
if policy == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rejectDocumentNull(resolution, path.Key("producer_structural_failure"), policy.ProducerStructuralFailure == nil)
|
|
||||||
rejectDocumentNull(resolution, path.Key("semantic_rejection"), policy.SemanticRejection == nil)
|
|
||||||
rejectDocumentNull(resolution, path.Key("validator_failure"), policy.ValidatorFailure == nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func normalizePipelineDocument(profile *PipelineDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
func normalizePipelineDocument(profile *PipelineDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
||||||
|
normalizeDocumentControls(&profile.Mode, &profile.Cache, path, resolution)
|
||||||
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &profile.LLMProfile, "trimmed pipeline LLM profile")
|
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &profile.LLMProfile, "trimmed pipeline LLM profile")
|
||||||
normalizeDocumentBinding(&profile.Input, path.Key("input"), resolution, state)
|
normalizeDocumentBinding(&profile.Input, path.Key("input"), resolution, state)
|
||||||
if profile.Chunk != nil {
|
if profile.Chunk != nil {
|
||||||
@@ -220,6 +206,7 @@ func normalizeArtifactLaneDocument(lane *ArtifactLaneDocument, path configkit.Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func normalizeDocumentBinding(binding *BindingDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
func normalizeDocumentBinding(binding *BindingDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
||||||
|
normalizeDocumentControls(&binding.Mode, &binding.Cache, path, resolution)
|
||||||
normalizeDocumentValue(resolution, path.Key("module"), &binding.Module, strings.TrimSpace(binding.Module), "trimmed module identifier")
|
normalizeDocumentValue(resolution, path.Key("module"), &binding.Module, strings.TrimSpace(binding.Module), "trimmed module identifier")
|
||||||
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &binding.LLMProfile, "trimmed binding LLM profile")
|
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &binding.LLMProfile, "trimmed binding LLM profile")
|
||||||
binding.References = normalizeDocumentReferences(binding.References, path.Key("references"), resolution, state)
|
binding.References = normalizeDocumentReferences(binding.References, path.Key("references"), resolution, state)
|
||||||
@@ -329,8 +316,6 @@ func validateDocumentPipelines(document *Document, validation *configkit.Validat
|
|||||||
|
|
||||||
func validatePipelineDocument(profile PipelineDocument, path configkit.Path, validation *configkit.Validation) {
|
func validatePipelineDocument(profile PipelineDocument, path configkit.Path, validation *configkit.Validation) {
|
||||||
validateSelectedDocumentProfile(profile.LLMProfile, path.Key("llm_profile"), validation)
|
validateSelectedDocumentProfile(profile.LLMProfile, path.Key("llm_profile"), validation)
|
||||||
validateDocumentRepairAttempts(profile.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
|
||||||
validateDocumentPolicy(profile.ValidationPolicy, path.Key("validation_policy"), validation)
|
|
||||||
validateDocumentBinding(profile.Input, path.Key("input"), "input", false, false, validation)
|
validateDocumentBinding(profile.Input, path.Key("input"), "input", false, false, validation)
|
||||||
if profile.Chunk != nil {
|
if profile.Chunk != nil {
|
||||||
validateDocumentBinding(*profile.Chunk, path.Key("chunk"), "chunk", true, true, validation)
|
validateDocumentBinding(*profile.Chunk, path.Key("chunk"), "chunk", true, true, validation)
|
||||||
@@ -383,20 +368,12 @@ func validateDocumentLanes(lanes map[string]ArtifactLaneDocument, path configkit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateDocumentBinding(binding BindingDocument, path configkit.Path, slot string, referencesAllowed, validatorsAllowed bool, validation *configkit.Validation) {
|
func validateDocumentBinding(binding BindingDocument, path configkit.Path, slot string, referencesAllowed, validatorsAllowed bool, validation *configkit.Validation) {
|
||||||
|
validateDocumentControls(binding.Mode, binding.MaxAdditionalTurns, binding.Cache, path, validation)
|
||||||
if strings.TrimSpace(binding.Module) == "" {
|
if strings.TrimSpace(binding.Module) == "" {
|
||||||
validation.Error(path.Key("module"), "must not be empty")
|
validation.Error(path.Key("module"), "must not be empty")
|
||||||
}
|
}
|
||||||
validateSelectedDocumentProfile(binding.LLMProfile, path.Key("llm_profile"), validation)
|
validateSelectedDocumentProfile(binding.LLMProfile, path.Key("llm_profile"), validation)
|
||||||
validateDocumentRepairAttempts(binding.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
|
||||||
if binding.Retries < 0 {
|
|
||||||
validation.Error(path.Key("retries"), "must be greater than or equal to zero")
|
|
||||||
}
|
|
||||||
if binding.ValidationPolicy != nil {
|
|
||||||
if slot != "chunk" && slot != "extract" && slot != "merge" && slot != "normalize" {
|
|
||||||
validation.Error(path.Key("validation_policy"), "is not supported for this binding")
|
|
||||||
}
|
|
||||||
validateDocumentPolicy(binding.ValidationPolicy, path.Key("validation_policy"), validation)
|
|
||||||
}
|
|
||||||
if len(binding.References) > 0 && !referencesAllowed {
|
if len(binding.References) > 0 && !referencesAllowed {
|
||||||
validation.Error(path.Key("references"), "are not supported for this binding")
|
validation.Error(path.Key("references"), "are not supported for this binding")
|
||||||
}
|
}
|
||||||
@@ -416,10 +393,7 @@ func validateValidatorDocument(validator ValidatorDocument, path configkit.Path,
|
|||||||
validation.Error(path.Key("module"), "must not be empty")
|
validation.Error(path.Key("module"), "must not be empty")
|
||||||
}
|
}
|
||||||
validateSelectedDocumentProfile(validator.LLMProfile, path.Key("llm_profile"), validation)
|
validateSelectedDocumentProfile(validator.LLMProfile, path.Key("llm_profile"), validation)
|
||||||
validateDocumentRepairAttempts(validator.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
|
||||||
if validator.Retries < 0 {
|
|
||||||
validation.Error(path.Key("retries"), "must be greater than or equal to zero")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDocumentReferences(references map[string]ReferenceDocument, path configkit.Path, generatedAllowed bool, validation *configkit.Validation) {
|
func validateDocumentReferences(references map[string]ReferenceDocument, path configkit.Path, generatedAllowed bool, validation *configkit.Validation) {
|
||||||
@@ -457,39 +431,6 @@ func validateSelectedDocumentProfile(value *string, path configkit.Path, validat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDocumentRepairAttempts(value *int, path configkit.Path, validation *configkit.Validation) {
|
|
||||||
if value != nil && (*value < 0 || *value > 3) {
|
|
||||||
validation.Error(path, "must be between zero and three")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateDocumentPolicy(policy *ValidationPolicyDocument, path configkit.Path, validation *configkit.Validation) {
|
|
||||||
if policy == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if policy.ProducerStructuralFailure != nil {
|
|
||||||
switch *policy.ProducerStructuralFailure {
|
|
||||||
case pipeline.ProducerStructuralFailureFailRun, pipeline.ProducerStructuralFailureRejectOutput:
|
|
||||||
default:
|
|
||||||
validation.Error(path.Key("producer_structural_failure"), "must be fail_run or reject_output")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if policy.SemanticRejection != nil {
|
|
||||||
switch *policy.SemanticRejection {
|
|
||||||
case pipeline.SemanticRejectionFailRun, pipeline.SemanticRejectionRejectOutput:
|
|
||||||
default:
|
|
||||||
validation.Error(path.Key("semantic_rejection"), "must be fail_run or reject_output")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if policy.ValidatorFailure != nil {
|
|
||||||
switch *policy.ValidatorFailure {
|
|
||||||
case pipeline.ValidatorFailureWarnContinue, pipeline.ValidatorFailureFailRun:
|
|
||||||
default:
|
|
||||||
validation.Error(path.Key("validator_failure"), "must be warn_continue or fail_run")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortedPipelineDocumentKeys(values map[string]PipelineDocument) []string {
|
func sortedPipelineDocumentKeys(values map[string]PipelineDocument) []string {
|
||||||
return sortedDocumentKeys(values)
|
return sortedDocumentKeys(values)
|
||||||
}
|
}
|
||||||
@@ -508,3 +449,32 @@ func sortedDocumentKeys[T any](values map[string]T) []string {
|
|||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
func normalizeDocumentControls(mode **pipeline.ExecutionMode, cache **pipeline.CacheMode, path configkit.Path, resolution documentNormalizer) {
|
||||||
|
if *mode != nil {
|
||||||
|
value := pipeline.ExecutionMode(strings.TrimSpace(string(**mode)))
|
||||||
|
if **mode != value {
|
||||||
|
normalizeDocumentValue(resolution, path.Key("mode"), mode, &value, "trimmed execution mode")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if *cache != nil {
|
||||||
|
value := pipeline.CacheMode(strings.TrimSpace(string(**cache)))
|
||||||
|
if **cache != value {
|
||||||
|
normalizeDocumentValue(resolution, path.Key("cache"), cache, &value, "trimmed cache mode")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func validateDocumentControls(mode *pipeline.ExecutionMode, turns *int, cache *pipeline.CacheMode, path configkit.Path, validation *configkit.Validation) {
|
||||||
|
if mode != nil {
|
||||||
|
if _, err := pipeline.ParseExecutionMode(string(*mode)); err != nil {
|
||||||
|
validation.Error(path.Key("mode"), err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cache != nil {
|
||||||
|
if _, err := pipeline.ParseCacheMode(string(*cache)); err != nil {
|
||||||
|
validation.Error(path.Key("cache"), err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if turns != nil && *turns < 0 {
|
||||||
|
validation.Error(path.Key("max_additional_turns"), "must not be negative")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ pipelines:
|
|||||||
" spells ":
|
" spells ":
|
||||||
extract:
|
extract:
|
||||||
module: " dnd/spells "
|
module: " dnd/spells "
|
||||||
structured_output_repair_attempts: 0
|
max_additional_turns: 0
|
||||||
validators: []
|
validators: []
|
||||||
merge:
|
merge:
|
||||||
module: dnd/merge
|
module: dnd/merge
|
||||||
@@ -108,7 +108,7 @@ pipelines:
|
|||||||
t.Fatalf("normalized pipeline = %#v", loaded.Config.Pipelines)
|
t.Fatalf("normalized pipeline = %#v", loaded.Config.Pipelines)
|
||||||
}
|
}
|
||||||
lane, ok := profile.Artifacts["spells"]
|
lane, ok := profile.Artifacts["spells"]
|
||||||
if !ok || lane.Extract.StructuredOutputRepairAttempts == nil || *lane.Extract.StructuredOutputRepairAttempts != 0 || lane.Extract.Validators == nil || len(lane.Extract.Validators) != 0 {
|
if !ok || lane.Extract.MaxAdditionalTurns == nil || *lane.Extract.MaxAdditionalTurns != 0 || lane.Extract.Validators == nil || len(lane.Extract.Validators) != 0 {
|
||||||
t.Fatalf("normalized lane = %#v", profile.Artifacts)
|
t.Fatalf("normalized lane = %#v", profile.Artifacts)
|
||||||
}
|
}
|
||||||
selector := lane.Merge.References["previous"].Artifact
|
selector := lane.Merge.References["previous"].Artifact
|
||||||
@@ -231,13 +231,13 @@ pipelines:
|
|||||||
path: "/pipelines/session/chunk/validators",
|
path: "/pipelines/session/chunk/validators",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "negative retry budget",
|
name: "negative turn allowance",
|
||||||
source: `version: 6
|
source: `version: 6
|
||||||
pipelines:
|
pipelines:
|
||||||
session:
|
session:
|
||||||
input: {module: seriatim, retries: -1}
|
input: {module: seriatim, max_additional_turns: -1}
|
||||||
`,
|
`,
|
||||||
path: "/pipelines/session/input/retries",
|
path: "/pipelines/session/input/max_additional_turns",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ func (e EffectiveConfig) RedactedResolvedPipelinePayload() pipeline.ResolvedPipe
|
|||||||
|
|
||||||
func cloneResolvedPipeline(in pipeline.ResolvedPipeline) pipeline.ResolvedPipeline {
|
func cloneResolvedPipeline(in pipeline.ResolvedPipeline) pipeline.ResolvedPipeline {
|
||||||
out := in
|
out := in
|
||||||
out.ConfiguredValidationPolicy = cloneValidationPolicyOverride(in.ConfiguredValidationPolicy)
|
|
||||||
out.Input = redactBinding(cloneModuleBinding(in.Input))
|
out.Input = redactBinding(cloneModuleBinding(in.Input))
|
||||||
out.Chunk = redactBinding(cloneModuleBinding(in.Chunk))
|
out.Chunk = redactBinding(cloneModuleBinding(in.Chunk))
|
||||||
out.ChunkReferences = pipeline.CloneReferenceTarget(in.ChunkReferences)
|
out.ChunkReferences = pipeline.CloneReferenceTarget(in.ChunkReferences)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
@@ -12,50 +11,20 @@ func (c Config) Validate() error {
|
|||||||
if err := validateStateSurfaces(c); err != nil {
|
if err := validateStateSurfaces(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := validateTotalLLMConcurrency(c.Concurrency.TotalLLM); err != nil {
|
if err := validateWorkers(c.Concurrency.Workers); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := validateStageWorkers(c.Concurrency); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return validatePipelineProfiles(c.Pipelines)
|
return validatePipelineProfiles(c.Pipelines)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateStageWorkers(cfg ConcurrencyConfig) error {
|
|
||||||
keys := make([]string, 0, len(cfg.StageWorkers))
|
|
||||||
for key := range cfg.StageWorkers {
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
for _, key := range keys {
|
|
||||||
if err := validateStageWorkerKey(key); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
extractWorkers, ok := cfg.StageWorkers["extract"]
|
|
||||||
if !ok {
|
|
||||||
extractWorkers = cfg.TotalLLM
|
|
||||||
}
|
|
||||||
return validateExtractWorkerCount(extractWorkers, cfg.TotalLLM)
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateStateSurfaces(cfg Config) error {
|
func validateStateSurfaces(cfg Config) error {
|
||||||
if err := validateRequiredPath("output.directory", cfg.Output.Directory); err != nil {
|
if err := validateRequiredPath("output.directory", cfg.Output.Directory); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := validateRequiredPath("debug.directory", cfg.Debug.Directory); err != nil {
|
if err := validateOptionalPath("debug.directory", cfg.Debug.Directory); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := validateChunkPlanCacheMode(string(cfg.Cache.ChunkPlans.Mode)); err != nil {
|
return validateOptionalPath("cache_directory", cfg.CacheDirectory)
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := validateOptionalPath("cache.chunk_plans.directory", cfg.Cache.ChunkPlans.Directory); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := validateOptionalPath("cache.checkpoints.directory", cfg.Cache.Checkpoints.Directory); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) error {
|
func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) error {
|
||||||
@@ -73,13 +42,8 @@ func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) erro
|
|||||||
if profile.ID != "" && strings.TrimSpace(profile.ID) != id {
|
if profile.ID != "" && strings.TrimSpace(profile.ID) != id {
|
||||||
return fmt.Errorf("pipeline %q profile id %q does not match map key", id, profile.ID)
|
return fmt.Errorf("pipeline %q profile id %q does not match map key", id, profile.ID)
|
||||||
}
|
}
|
||||||
if err := validateStructuredOutputRepairAttempts(fmt.Sprintf("pipeline %q", id), profile.StructuredOutputRepairAttempts); err != nil {
|
if _, err := pipeline.ResolveProducerControls(pipeline.ModuleBinding{}, profile, nil); err != nil {
|
||||||
return err
|
return fmt.Errorf("pipeline %q: %w", id, err)
|
||||||
}
|
|
||||||
if profile.ValidationPolicy != nil {
|
|
||||||
if err := profile.ValidationPolicy.Validate(); err != nil {
|
|
||||||
return fmt.Errorf("pipeline %q validation_policy: %w", id, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := validateBinding(id, "", "input", profile.Input, false); err != nil {
|
if err := validateBinding(id, "", "input", profile.Input, false); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -160,28 +124,12 @@ func validateBinding(
|
|||||||
binding pipeline.ModuleBinding,
|
binding pipeline.ModuleBinding,
|
||||||
referencesAllowed bool,
|
referencesAllowed bool,
|
||||||
) error {
|
) error {
|
||||||
if binding.ValidationPolicy != nil {
|
if _, err := pipeline.ResolveProducerControls(binding, pipeline.PipelineProfile{}, nil); err != nil {
|
||||||
switch slot {
|
return fmt.Errorf("%s: %w", referenceContext(pipelineID, laneID, slot), err)
|
||||||
case "chunk", "extract", "merge", "normalize":
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("%s validation_policy is not supported", referenceContext(pipelineID, laneID, slot))
|
|
||||||
}
|
|
||||||
if err := binding.ValidationPolicy.Validate(); err != nil {
|
|
||||||
return fmt.Errorf("%s validation_policy: %w", referenceContext(pipelineID, laneID, slot), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := validateStructuredOutputRepairAttempts(referenceContext(pipelineID, laneID, slot), binding.StructuredOutputRepairAttempts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if err := validateBindingLLMProfile(pipelineID, laneID, slot, binding); err != nil {
|
if err := validateBindingLLMProfile(pipelineID, laneID, slot, binding); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if binding.Retries < 0 {
|
|
||||||
if laneID != "" {
|
|
||||||
return fmt.Errorf("pipeline %q lane %q %s retries must be greater than or equal to zero", pipelineID, laneID, slot)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("pipeline %q %s retries must be greater than or equal to zero", pipelineID, slot)
|
|
||||||
}
|
|
||||||
if err := validateValidatorOverride(pipelineID, laneID, slot, binding.Validators); err != nil {
|
if err := validateValidatorOverride(pipelineID, laneID, slot, binding.Validators); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -197,13 +145,6 @@ func validateBinding(
|
|||||||
return validateReferenceMapForContext(pipelineID, laneID, slot, binding.References, true)
|
return validateReferenceMapForContext(pipelineID, laneID, slot, binding.References, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateStructuredOutputRepairAttempts(context string, attempts *int) error {
|
|
||||||
if attempts != nil && (*attempts < 0 || *attempts > 3) {
|
|
||||||
return fmt.Errorf("%s structured_output_repair_attempts must be between zero and three", context)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateValidatorOverride(pipelineID string, laneID string, slot string, override pipeline.ValidatorOverride) error {
|
func validateValidatorOverride(pipelineID string, laneID string, slot string, override pipeline.ValidatorOverride) error {
|
||||||
if !override.Set {
|
if !override.Set {
|
||||||
return nil
|
return nil
|
||||||
@@ -215,9 +156,6 @@ func validateValidatorOverride(pipelineID string, laneID string, slot string, ov
|
|||||||
}
|
}
|
||||||
for i, validator := range override.Validators {
|
for i, validator := range override.Validators {
|
||||||
context := fmt.Sprintf("%s validators[%d]", referenceContext(pipelineID, laneID, slot), i)
|
context := fmt.Sprintf("%s validators[%d]", referenceContext(pipelineID, laneID, slot), i)
|
||||||
if err := validateStructuredOutputRepairAttempts(context, validator.StructuredOutputRepairAttempts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(validator.Module) == "" {
|
if strings.TrimSpace(validator.Module) == "" {
|
||||||
return fmt.Errorf("%s module must not be empty", context)
|
return fmt.Errorf("%s module must not be empty", context)
|
||||||
}
|
}
|
||||||
@@ -227,11 +165,8 @@ func validateValidatorOverride(pipelineID string, laneID string, slot string, ov
|
|||||||
if validator.Validators.Set {
|
if validator.Validators.Set {
|
||||||
return fmt.Errorf("%s nested validators are not supported", context)
|
return fmt.Errorf("%s nested validators are not supported", context)
|
||||||
}
|
}
|
||||||
if validator.ValidationPolicy != nil {
|
if validator.Mode != nil || validator.Cache != nil || validator.MaxAdditionalTurns != nil {
|
||||||
return fmt.Errorf("%s validation_policy is not supported", context)
|
return fmt.Errorf("%s producer controls are not supported for validators", context)
|
||||||
}
|
|
||||||
if validator.Retries < 0 {
|
|
||||||
return fmt.Errorf("%s retries must be greater than or equal to zero", context)
|
|
||||||
}
|
}
|
||||||
if validator.LLMProfile != "" && strings.TrimSpace(validator.LLMProfile) == "" {
|
if validator.LLMProfile != "" && strings.TrimSpace(validator.LLMProfile) == "" {
|
||||||
return fmt.Errorf("%s llm_profile must not be empty when set", context)
|
return fmt.Errorf("%s llm_profile must not be empty when set", context)
|
||||||
|
|||||||
@@ -8,142 +8,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateConcurrencyRules(t *testing.T) {
|
func TestValidateConcurrencyRules(t *testing.T) {
|
||||||
tests := []struct {
|
for _, workers := range []int{0, -1, 1, 64, 1000000} {
|
||||||
name string
|
cfg := Default()
|
||||||
setup func(*Config)
|
cfg.Concurrency.Workers = workers
|
||||||
want string
|
err := cfg.Validate()
|
||||||
}{
|
if (err != nil) != (workers <= 0) {
|
||||||
{
|
t.Fatalf("workers %d: %v", workers, err)
|
||||||
name: "non-positive total",
|
}
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.TotalLLM = 0
|
|
||||||
},
|
|
||||||
want: "total LLM concurrency must be greater than zero",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "worker below one",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.TotalLLM = 3
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{"extract": 0}
|
|
||||||
},
|
|
||||||
want: "stage_workers.extract must be between 1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "worker above total",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.TotalLLM = 3
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{"extract": 4}
|
|
||||||
},
|
|
||||||
want: "stage_workers.extract must be between 1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "worker lower boundary",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.TotalLLM = 3
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{"extract": 1}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "worker upper boundary",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.TotalLLM = 3
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{"extract": 3}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "unknown worker key",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{"worker": 1}
|
|
||||||
},
|
|
||||||
want: "stage_workers key \"worker\" is not supported",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "blank worker key",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Concurrency.StageWorkers = map[string]int{" ": 1}
|
|
||||||
},
|
|
||||||
want: "stage_workers key must not be empty",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
cfg := Default()
|
|
||||||
tt.setup(&cfg)
|
|
||||||
err := cfg.Validate()
|
|
||||||
if tt.want == "" {
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Validate() error = %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err == nil || !strings.Contains(err.Error(), tt.want) {
|
|
||||||
t.Fatalf("Validate() error = %v, want context %q", err, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateStateSurfaceRules(t *testing.T) {
|
func TestValidateStateSurfaceRules(t *testing.T) {
|
||||||
tests := []struct {
|
for _, test := range []struct {
|
||||||
name string
|
name string
|
||||||
setup func(*Config)
|
setup func(*Config)
|
||||||
want string
|
|
||||||
}{
|
}{
|
||||||
{
|
{"output", func(c *Config) { c.Output.Directory = "" }},
|
||||||
name: "blank output root",
|
{"cache", func(c *Config) { c.CacheDirectory = "\\x00" }},
|
||||||
setup: func(cfg *Config) {
|
{"debug", func(c *Config) { c.Debug.Directory = "\\x00" }},
|
||||||
cfg.Output.Directory = " "
|
} {
|
||||||
},
|
t.Run(test.name, func(t *testing.T) {
|
||||||
want: "output.directory must not be empty",
|
c := Default()
|
||||||
},
|
test.setup(&c)
|
||||||
{
|
if c.Validate() == nil {
|
||||||
name: "blank debug root",
|
t.Fatal("accepted invalid path")
|
||||||
setup: func(cfg *Config) {
|
}
|
||||||
cfg.Debug.Directory = " "
|
|
||||||
},
|
|
||||||
want: "debug.directory must not be empty",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "NUL in output root",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Output.Directory = "./out\x00put"
|
|
||||||
},
|
|
||||||
want: "output.directory must not contain NUL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "NUL in chunk plan root",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Cache.ChunkPlans.Directory = "./plans\x00"
|
|
||||||
},
|
|
||||||
want: "cache.chunk_plans.directory must not contain NUL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "NUL in checkpoint root",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Cache.Checkpoints.Directory = "./checkpoints\x00"
|
|
||||||
},
|
|
||||||
want: "cache.checkpoints.directory must not contain NUL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "NUL in debug root",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Debug.Directory = "./debug\x00"
|
|
||||||
},
|
|
||||||
want: "debug.directory must not contain NUL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "invalid chunk plan mode",
|
|
||||||
setup: func(cfg *Config) {
|
|
||||||
cfg.Cache.ChunkPlans.Mode = pipeline.ChunkCacheMode("invalid")
|
|
||||||
},
|
|
||||||
want: "cache.chunk_plans.mode:",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
cfg := Default()
|
|
||||||
tt.setup(&cfg)
|
|
||||||
assertValidationContains(t, cfg, tt.want)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,20 +103,21 @@ func TestValidateIdentifiersAfterTrimming(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateBindingRetriesAndProfiles(t *testing.T) {
|
func TestValidateBindingControlsAndProfiles(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
setup func(*Config)
|
setup func(*Config)
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "negative retries",
|
name: "negative turns",
|
||||||
setup: func(cfg *Config) {
|
setup: func(cfg *Config) {
|
||||||
profile := validationProfile()
|
profile := validationProfile()
|
||||||
profile.Input.Retries = -1
|
value := -1
|
||||||
|
profile.Input.MaxAdditionalTurns = &value
|
||||||
cfg.Pipelines = map[string]pipeline.PipelineProfile{"main": profile}
|
cfg.Pipelines = map[string]pipeline.PipelineProfile{"main": profile}
|
||||||
},
|
},
|
||||||
want: "input retries must be greater than or equal to zero",
|
want: "input: max_additional_turns must not be negative",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "whitespace-only input profile",
|
name: "whitespace-only input profile",
|
||||||
@@ -302,12 +192,12 @@ func TestValidateValidatorBindingRules(t *testing.T) {
|
|||||||
profile.Chunk.Validators = pipeline.ValidatorOverride{
|
profile.Chunk.Validators = pipeline.ValidatorOverride{
|
||||||
Set: true,
|
Set: true,
|
||||||
Validators: []pipeline.ModuleBinding{{
|
Validators: []pipeline.ModuleBinding{{
|
||||||
Module: "validator",
|
Module: "validator",
|
||||||
Retries: -1,
|
MaxAdditionalTurns: documentValue(-1),
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
want: "chunk validators[0] retries must be greater than or equal to zero",
|
want: "chunk validators[0] producer controls are not supported for validators",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "validator references",
|
name: "validator references",
|
||||||
|
|||||||
@@ -1,103 +1,67 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidationPolicyFileConfigurationIsStrictAndPresenceAware(t *testing.T) {
|
func TestLoadedProducerControlsPreserveOmissionAndZero(t *testing.T) {
|
||||||
const valid = `version: 6
|
t.Parallel()
|
||||||
|
loaded, err := loadConfigSource(configkit.Bytes("controls.yml", []byte(`version: 6
|
||||||
pipelines:
|
pipelines:
|
||||||
main:
|
main:
|
||||||
validation_policy:
|
mode: " permissive "
|
||||||
producer_structural_failure: reject_output
|
max_additional_turns: 5
|
||||||
semantic_rejection: fail_run
|
cache: refresh
|
||||||
input:
|
input: {module: input}
|
||||||
module: seriatim
|
|
||||||
chunk:
|
chunk:
|
||||||
module: generic
|
module: chunk
|
||||||
validation_policy:
|
mode: strict
|
||||||
validator_failure: fail_run
|
max_additional_turns: 0
|
||||||
|
cache: bypass
|
||||||
artifacts:
|
artifacts:
|
||||||
lane:
|
lane:
|
||||||
extract:
|
extract: {module: extract}
|
||||||
module: extract
|
`)), LoadOptions{})
|
||||||
validation_policy:
|
|
||||||
semantic_rejection: reject_output
|
|
||||||
`
|
|
||||||
loaded, err := loadDocumentSource(configkit.Bytes("valid.yml", []byte(valid)), LoadOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
cfg := loaded.Config
|
profile := loaded.Config.Pipelines["main"]
|
||||||
profile := cfg.Pipelines["main"]
|
if profile.Mode == nil || *profile.Mode != pipeline.ModePermissive {
|
||||||
if profile.ValidationPolicy == nil || profile.ValidationPolicy.ProducerStructuralFailure == nil || *profile.ValidationPolicy.ProducerStructuralFailure != pipeline.ProducerStructuralFailureRejectOutput || profile.ValidationPolicy.SemanticRejection == nil || *profile.ValidationPolicy.SemanticRejection != pipeline.SemanticRejectionFailRun || profile.ValidationPolicy.ValidatorFailure != nil {
|
t.Fatalf("mode = %v", profile.Mode)
|
||||||
t.Fatalf("pipeline validation policy = %#v", profile.ValidationPolicy)
|
|
||||||
}
|
}
|
||||||
if profile.Chunk.ValidationPolicy == nil || profile.Chunk.ValidationPolicy.ValidatorFailure == nil || *profile.Chunk.ValidationPolicy.ValidatorFailure != pipeline.ValidatorFailureFailRun {
|
if profile.Artifacts["lane"].Extract.Mode != nil || profile.Artifacts["lane"].Extract.MaxAdditionalTurns != nil {
|
||||||
t.Fatalf("chunk validation policy = %#v", profile.Chunk.ValidationPolicy)
|
t.Fatal("omitted binding controls became explicit")
|
||||||
}
|
}
|
||||||
lane := profile.Artifacts["lane"]
|
got, err := pipeline.ResolveProducerControls(profile.Chunk, profile, nil)
|
||||||
if lane.Extract.ValidationPolicy == nil || lane.Extract.ValidationPolicy.SemanticRejection == nil || *lane.Extract.ValidationPolicy.SemanticRejection != pipeline.SemanticRejectionRejectOutput {
|
if err != nil {
|
||||||
t.Fatalf("extract validation policy = %#v", lane.Extract.ValidationPolicy)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if got != (pipeline.ProducerControls{Mode: pipeline.ModeStrict, MaxAdditionalTurns: 0, Cache: pipeline.CacheBypass}) {
|
||||||
for _, test := range []struct {
|
t.Fatalf("chunk controls = %#v", got)
|
||||||
name string
|
}
|
||||||
yaml string
|
got, err = pipeline.ResolveProducerControls(profile.Artifacts["lane"].Extract, profile, nil)
|
||||||
}{
|
if err != nil {
|
||||||
{"null object", strings.Replace(valid, "validation_policy:\n producer_structural_failure: reject_output\n semantic_rejection: fail_run", "validation_policy: null", 1)},
|
t.Fatal(err)
|
||||||
{"null field", strings.Replace(valid, "semantic_rejection: fail_run", "semantic_rejection: null", 1)},
|
}
|
||||||
{"unknown field", strings.Replace(valid, "semantic_rejection: fail_run", "unknown: fail_run", 1)},
|
if got != (pipeline.ProducerControls{Mode: pipeline.ModePermissive, MaxAdditionalTurns: 5, Cache: pipeline.CacheRefresh}) {
|
||||||
{"duplicate field", strings.Replace(valid, "semantic_rejection: fail_run", "semantic_rejection: fail_run\n semantic_rejection: reject_output", 1)},
|
t.Fatalf("inherited controls = %#v", got)
|
||||||
{"invalid enum", strings.Replace(valid, "semantic_rejection: fail_run", "semantic_rejection: continue", 1)},
|
}
|
||||||
} {
|
invocation := pipeline.CacheAuto
|
||||||
t.Run(test.name, func(t *testing.T) {
|
got, err = pipeline.ResolveProducerControls(profile.Chunk, profile, &invocation)
|
||||||
if _, err := loadDocumentSource(configkit.Bytes("invalid.yml", []byte(test.yaml)), LoadOptions{}); err == nil {
|
if err != nil || got.Cache != pipeline.CacheAuto {
|
||||||
t.Fatal("loadDocumentSource() error = nil, want strict validation-policy rejection")
|
t.Fatalf("invocation cache = %#v, %v", got, err)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidationPolicyPlacementRules(t *testing.T) {
|
func TestLoadedProducerControlsValidateAtTheirPaths(t *testing.T) {
|
||||||
policy := &pipeline.ValidationPolicyOverride{}
|
t.Parallel()
|
||||||
semantic := pipeline.SemanticRejectionRejectOutput
|
for _, test := range []struct{ field, value string }{
|
||||||
policy.SemanticRejection = &semantic
|
{"mode", "unknown"}, {"cache", "unknown"}, {"max_additional_turns", "-1"},
|
||||||
base := pipeline.PipelineProfile{
|
|
||||||
ID: "main",
|
|
||||||
Input: pipeline.Binding("input"),
|
|
||||||
Artifacts: map[string]pipeline.ArtifactLaneProfile{
|
|
||||||
"lane": {Extract: pipeline.Binding("extract")},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, test := range []struct {
|
|
||||||
name string
|
|
||||||
mutate func(*pipeline.PipelineProfile)
|
|
||||||
}{
|
|
||||||
{"input", func(profile *pipeline.PipelineProfile) { profile.Input.ValidationPolicy = policy }},
|
|
||||||
{"output", func(profile *pipeline.PipelineProfile) {
|
|
||||||
profile.Output = pipeline.Binding("output")
|
|
||||||
profile.Output.ValidationPolicy = policy
|
|
||||||
}},
|
|
||||||
{"validator", func(profile *pipeline.PipelineProfile) {
|
|
||||||
lane := profile.Artifacts["lane"]
|
|
||||||
lane.Extract.Validators = pipeline.ValidatorOverride{Set: true, Validators: []pipeline.ModuleBinding{{Module: "validator", ValidationPolicy: policy}}}
|
|
||||||
profile.Artifacts["lane"] = lane
|
|
||||||
}},
|
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
_, err := loadConfigSource(configkit.Bytes("invalid.yml", []byte("version: 6\npipelines:\n main:\n input: {module: input}\n "+test.field+": "+test.value+"\n")), LoadOptions{})
|
||||||
profile := base
|
assertDocumentDiagnosticAt(t, err, "/pipelines/main/"+test.field)
|
||||||
profile.Artifacts = map[string]pipeline.ArtifactLaneProfile{"lane": base.Artifacts["lane"]}
|
|
||||||
test.mutate(&profile)
|
|
||||||
cfg := Default()
|
|
||||||
cfg.Pipelines = map[string]pipeline.PipelineProfile{"main": profile}
|
|
||||||
if err := cfg.Validate(); err == nil || !strings.Contains(err.Error(), "validation_policy") {
|
|
||||||
t.Fatalf("Config.Validate() error = %v, want placement rejection", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ModuleBinding struct {
|
type ModuleBinding struct {
|
||||||
Module string `json:"module"`
|
Mode *ExecutionMode `json:"mode,omitempty"`
|
||||||
LLMProfile string `json:"llm_profile,omitempty"`
|
MaxAdditionalTurns *int `json:"max_additional_turns,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
|
Cache *CacheMode `json:"cache,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyOverride `json:"validation_policy,omitempty"`
|
Module string `json:"module"`
|
||||||
Retries int `json:"retries,omitempty"`
|
LLMProfile string `json:"llm_profile,omitempty"`
|
||||||
Options map[string]any `json:"options,omitempty"`
|
Options map[string]any `json:"options,omitempty"`
|
||||||
References map[string]ReferenceSource `json:"references,omitempty"`
|
References map[string]ReferenceSource `json:"references,omitempty"`
|
||||||
Validators ValidatorOverride `json:"validators,omitempty"`
|
Validators ValidatorOverride `json:"validators,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtifactReference identifies a normalized artifact produced by an earlier
|
// ArtifactReference identifies a normalized artifact produced by an earlier
|
||||||
@@ -82,23 +82,23 @@ type ValidatorOverride struct {
|
|||||||
|
|
||||||
func (binding ModuleBinding) MarshalJSON() ([]byte, error) {
|
func (binding ModuleBinding) MarshalJSON() ([]byte, error) {
|
||||||
type moduleBindingJSON struct {
|
type moduleBindingJSON struct {
|
||||||
Module string `json:"module"`
|
Mode *ExecutionMode `json:"mode,omitempty"`
|
||||||
LLMProfile string `json:"llm_profile,omitempty"`
|
MaxAdditionalTurns *int `json:"max_additional_turns,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
|
Cache *CacheMode `json:"cache,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyOverride `json:"validation_policy,omitempty"`
|
Module string `json:"module"`
|
||||||
Retries int `json:"retries,omitempty"`
|
LLMProfile string `json:"llm_profile,omitempty"`
|
||||||
Options map[string]any `json:"options,omitempty"`
|
Options map[string]any `json:"options,omitempty"`
|
||||||
References map[string]ReferenceSource `json:"references,omitempty"`
|
References map[string]ReferenceSource `json:"references,omitempty"`
|
||||||
Validators *[]ModuleBinding `json:"validators,omitempty"`
|
Validators *[]ModuleBinding `json:"validators,omitempty"`
|
||||||
}
|
}
|
||||||
out := moduleBindingJSON{
|
out := moduleBindingJSON{
|
||||||
Module: binding.Module,
|
Module: binding.Module,
|
||||||
LLMProfile: binding.LLMProfile,
|
Mode: cloneControl(binding.Mode),
|
||||||
StructuredOutputRepairAttempts: binding.StructuredOutputRepairAttempts,
|
MaxAdditionalTurns: cloneControl(binding.MaxAdditionalTurns),
|
||||||
ValidationPolicy: cloneValidationPolicyOverride(binding.ValidationPolicy),
|
Cache: cloneControl(binding.Cache),
|
||||||
Retries: binding.Retries,
|
LLMProfile: binding.LLMProfile,
|
||||||
Options: binding.Options,
|
Options: binding.Options,
|
||||||
References: binding.References,
|
References: binding.References,
|
||||||
}
|
}
|
||||||
if binding.Validators.Set {
|
if binding.Validators.Set {
|
||||||
validators := cloneModuleBindings(binding.Validators.Validators)
|
validators := cloneModuleBindings(binding.Validators.Validators)
|
||||||
@@ -112,27 +112,27 @@ func (binding *ModuleBinding) UnmarshalJSON(data []byte) error {
|
|||||||
return fmt.Errorf("module binding must not be nil")
|
return fmt.Errorf("module binding must not be nil")
|
||||||
}
|
}
|
||||||
type moduleBindingJSON struct {
|
type moduleBindingJSON struct {
|
||||||
Module string `json:"module"`
|
Mode *ExecutionMode `json:"mode,omitempty"`
|
||||||
LLMProfile string `json:"llm_profile,omitempty"`
|
MaxAdditionalTurns *int `json:"max_additional_turns,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
|
Cache *CacheMode `json:"cache,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyOverride `json:"validation_policy,omitempty"`
|
Module string `json:"module"`
|
||||||
Retries int `json:"retries,omitempty"`
|
LLMProfile string `json:"llm_profile,omitempty"`
|
||||||
Options map[string]any `json:"options,omitempty"`
|
Options map[string]any `json:"options,omitempty"`
|
||||||
References map[string]ReferenceSource `json:"references,omitempty"`
|
References map[string]ReferenceSource `json:"references,omitempty"`
|
||||||
Validators json.RawMessage `json:"validators,omitempty"`
|
Validators json.RawMessage `json:"validators,omitempty"`
|
||||||
}
|
}
|
||||||
var decoded moduleBindingJSON
|
var decoded moduleBindingJSON
|
||||||
if err := json.Unmarshal(data, &decoded); err != nil {
|
if err := json.Unmarshal(data, &decoded); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out := ModuleBinding{
|
out := ModuleBinding{
|
||||||
Module: decoded.Module,
|
Module: decoded.Module,
|
||||||
LLMProfile: decoded.LLMProfile,
|
Mode: cloneControl(decoded.Mode),
|
||||||
StructuredOutputRepairAttempts: decoded.StructuredOutputRepairAttempts,
|
MaxAdditionalTurns: cloneControl(decoded.MaxAdditionalTurns),
|
||||||
ValidationPolicy: cloneValidationPolicyOverride(decoded.ValidationPolicy),
|
Cache: cloneControl(decoded.Cache),
|
||||||
Retries: decoded.Retries,
|
LLMProfile: decoded.LLMProfile,
|
||||||
Options: decoded.Options,
|
Options: decoded.Options,
|
||||||
References: decoded.References,
|
References: decoded.References,
|
||||||
}
|
}
|
||||||
if len(decoded.Validators) > 0 && string(decoded.Validators) != "null" {
|
if len(decoded.Validators) > 0 && string(decoded.Validators) != "null" {
|
||||||
var validators []ModuleBinding
|
var validators []ModuleBinding
|
||||||
@@ -160,19 +160,21 @@ type PipelineStepProfile struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PipelineProfile struct {
|
type PipelineProfile struct {
|
||||||
ID string `json:"id"`
|
Mode *ExecutionMode `json:"mode,omitempty"`
|
||||||
LLMProfile string `json:"llm_profile,omitempty"`
|
MaxAdditionalTurns *int `json:"max_additional_turns,omitempty"`
|
||||||
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
|
Cache *CacheMode `json:"cache,omitempty"`
|
||||||
ValidationPolicy *ValidationPolicyOverride `json:"validation_policy,omitempty"`
|
ID string `json:"id"`
|
||||||
Input ModuleBinding `json:"input"`
|
LLMProfile string `json:"llm_profile,omitempty"`
|
||||||
Chunk ModuleBinding `json:"chunk,omitempty"`
|
Input ModuleBinding `json:"input"`
|
||||||
Artifacts map[string]ArtifactLaneProfile `json:"artifacts"`
|
Chunk ModuleBinding `json:"chunk,omitempty"`
|
||||||
Steps []PipelineStepProfile `json:"steps,omitempty"`
|
Artifacts map[string]ArtifactLaneProfile `json:"artifacts"`
|
||||||
Output ModuleBinding `json:"output,omitempty"`
|
Steps []PipelineStepProfile `json:"steps,omitempty"`
|
||||||
References map[string]ReferenceSource `json:"references,omitempty"`
|
Output ModuleBinding `json:"output,omitempty"`
|
||||||
|
References map[string]ReferenceSource `json:"references,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResolveOptions struct {
|
type ResolveOptions struct {
|
||||||
|
CacheOverride *CacheMode
|
||||||
Only []string
|
Only []string
|
||||||
LLMProfileOverride string
|
LLMProfileOverride string
|
||||||
ReferenceOverrides []ReferenceBinding
|
ReferenceOverrides []ReferenceBinding
|
||||||
@@ -204,6 +206,9 @@ type ResolvedReferenceTarget struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedArtifactLane struct {
|
type ResolvedArtifactLane struct {
|
||||||
|
ExtractControls ProducerControls
|
||||||
|
MergeControls ProducerControls
|
||||||
|
NormalizeControls ProducerControls
|
||||||
StepID string
|
StepID string
|
||||||
ID string
|
ID string
|
||||||
ArtifactKind contracts.ArtifactKind `json:"artifact_kind,omitempty"`
|
ArtifactKind contracts.ArtifactKind `json:"artifact_kind,omitempty"`
|
||||||
@@ -214,15 +219,12 @@ type ResolvedArtifactLane struct {
|
|||||||
Extract ModuleBinding
|
Extract ModuleBinding
|
||||||
ExtractExecutionClass contracts.ExecutionClass `json:"extract_execution_class"`
|
ExtractExecutionClass contracts.ExecutionClass `json:"extract_execution_class"`
|
||||||
ExtractCorrectionProtocol contracts.CorrectionProtocol `json:"extract_correction_protocol,omitempty"`
|
ExtractCorrectionProtocol contracts.CorrectionProtocol `json:"extract_correction_protocol,omitempty"`
|
||||||
ExtractValidationPolicy ValidationPolicy `json:"extract_validation_policy"`
|
|
||||||
Merge ModuleBinding
|
Merge ModuleBinding
|
||||||
MergeExecutionClass contracts.ExecutionClass `json:"merge_execution_class"`
|
MergeExecutionClass contracts.ExecutionClass `json:"merge_execution_class"`
|
||||||
MergeCorrectionProtocol contracts.CorrectionProtocol `json:"merge_correction_protocol,omitempty"`
|
MergeCorrectionProtocol contracts.CorrectionProtocol `json:"merge_correction_protocol,omitempty"`
|
||||||
MergeValidationPolicy ValidationPolicy `json:"merge_validation_policy"`
|
|
||||||
Normalize ModuleBinding
|
Normalize ModuleBinding
|
||||||
NormalizeExecutionClass contracts.ExecutionClass `json:"normalize_execution_class"`
|
NormalizeExecutionClass contracts.ExecutionClass `json:"normalize_execution_class"`
|
||||||
NormalizeCorrectionProtocol contracts.CorrectionProtocol `json:"normalize_correction_protocol,omitempty"`
|
NormalizeCorrectionProtocol contracts.CorrectionProtocol `json:"normalize_correction_protocol,omitempty"`
|
||||||
NormalizeValidationPolicy ValidationPolicy `json:"normalize_validation_policy"`
|
|
||||||
Validators []ModuleBinding
|
Validators []ModuleBinding
|
||||||
ExtractReferences ResolvedReferenceTarget `json:"extract_references"`
|
ExtractReferences ResolvedReferenceTarget `json:"extract_references"`
|
||||||
MergeReferences ResolvedReferenceTarget `json:"merge_references"`
|
MergeReferences ResolvedReferenceTarget `json:"merge_references"`
|
||||||
@@ -249,20 +251,19 @@ type ResolvedValidator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResolvedPipeline struct {
|
type ResolvedPipeline struct {
|
||||||
ID string
|
ChunkControls ProducerControls
|
||||||
Digest string
|
ID string
|
||||||
ConfiguredValidationPolicy *ValidationPolicyOverride `json:"configured_validation_policy,omitempty"`
|
Digest string
|
||||||
Input ModuleBinding
|
Input ModuleBinding
|
||||||
InputExecutionClass contracts.ExecutionClass `json:"input_execution_class"`
|
InputExecutionClass contracts.ExecutionClass `json:"input_execution_class"`
|
||||||
Chunk ModuleBinding
|
Chunk ModuleBinding
|
||||||
ChunkExecutionClass contracts.ExecutionClass `json:"chunk_execution_class"`
|
ChunkExecutionClass contracts.ExecutionClass `json:"chunk_execution_class"`
|
||||||
ChunkCorrectionProtocol contracts.CorrectionProtocol `json:"chunk_correction_protocol,omitempty"`
|
ChunkCorrectionProtocol contracts.CorrectionProtocol `json:"chunk_correction_protocol,omitempty"`
|
||||||
ChunkValidationPolicy ValidationPolicy `json:"chunk_validation_policy"`
|
ChunkReferences ResolvedReferenceTarget `json:"chunk_references"`
|
||||||
ChunkReferences ResolvedReferenceTarget `json:"chunk_references"`
|
Steps []ResolvedPipelineStep
|
||||||
Steps []ResolvedPipelineStep
|
ValidatorChains []ResolvedValidatorChain `json:"validator_chains"`
|
||||||
ValidatorChains []ResolvedValidatorChain `json:"validator_chains"`
|
Output ModuleBinding
|
||||||
Output ModuleBinding
|
OutputExecutionClass contracts.ExecutionClass `json:"output_execution_class"`
|
||||||
OutputExecutionClass contracts.ExecutionClass `json:"output_execution_class"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllArtifactLanes returns lanes in deterministic step order for read-only
|
// AllArtifactLanes returns lanes in deterministic step order for read-only
|
||||||
@@ -429,15 +430,14 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
resolved := ResolvedPipeline{
|
resolved := ResolvedPipeline{
|
||||||
ID: pipelineID,
|
ID: pipelineID,
|
||||||
ConfiguredValidationPolicy: cloneValidationPolicyOverride(profile.ValidationPolicy),
|
Input: input,
|
||||||
Input: input,
|
InputExecutionClass: inputModuleSpec.ExecutionClass,
|
||||||
InputExecutionClass: inputModuleSpec.ExecutionClass,
|
Chunk: chunk,
|
||||||
Chunk: chunk,
|
ChunkExecutionClass: chunkSpec.ExecutionClass,
|
||||||
ChunkExecutionClass: chunkSpec.ExecutionClass,
|
ChunkCorrectionProtocol: chunkSpec.CorrectionProtocol,
|
||||||
ChunkCorrectionProtocol: chunkSpec.CorrectionProtocol,
|
ChunkReferences: referenceTarget(StageChunk, "", chunk.Module, chunkReferences),
|
||||||
ChunkReferences: referenceTarget(StageChunk, "", chunk.Module, chunkReferences),
|
Output: output,
|
||||||
Output: output,
|
|
||||||
}
|
}
|
||||||
chunkValidatorChain, err := resolveValidatorChain(pipelineID, "", StageChunk, chunk.Module, chunk.Validators, "", nil, catalog)
|
chunkValidatorChain, err := resolveValidatorChain(pipelineID, "", StageChunk, chunk.Module, chunk.Validators, "", nil, catalog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -507,10 +507,7 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
if err := applyEffectiveLLMProfiles(&resolved, profile.LLMProfile, options.LLMProfileOverride); err != nil {
|
if err := applyEffectiveLLMProfiles(&resolved, profile.LLMProfile, options.LLMProfileOverride); err != nil {
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
if err := applyEffectiveStructuredOutputRepairAttempts(&resolved, profile.StructuredOutputRepairAttempts); err != nil {
|
if err := applyEffectiveProducerControls(&resolved, profile, options.CacheOverride); err != nil {
|
||||||
return ResolvedPipeline{}, err
|
|
||||||
}
|
|
||||||
if err := applyEffectiveValidationPolicies(&resolved, profile.ValidationPolicy); err != nil {
|
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
if err := validateResolvedOptions(resolved, catalog, configuredLaneIDs); err != nil {
|
if err := validateResolvedOptions(resolved, catalog, configuredLaneIDs); err != nil {
|
||||||
@@ -936,9 +933,6 @@ func resolveValidatorChain(pipelineID string, laneID string, stage ModuleStage,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedValidatorChain{}, fmt.Errorf("pipeline %q %s validator chain for module %q: %w", pipelineID, stage, chain.ModuleKey, err)
|
return ResolvedValidatorChain{}, fmt.Errorf("pipeline %q %s validator chain for module %q: %w", pipelineID, stage, chain.ModuleKey, err)
|
||||||
}
|
}
|
||||||
if validator.Retries > 0 && spec.ExecutionClass != contracts.ExecutionClassLLMBacked {
|
|
||||||
return ResolvedValidatorChain{}, fmt.Errorf("pipeline %q %s validator %q retries require an LLM-backed execution class", pipelineID, stage, validator.Module)
|
|
||||||
}
|
|
||||||
chain.Validators = append(chain.Validators, ResolvedValidator{
|
chain.Validators = append(chain.Validators, ResolvedValidator{
|
||||||
Binding: cloneModuleBinding(validator),
|
Binding: cloneModuleBinding(validator),
|
||||||
ExecutionClass: spec.ExecutionClass,
|
ExecutionClass: spec.ExecutionClass,
|
||||||
@@ -1351,14 +1345,14 @@ func resolveBinding(binding ModuleBinding, defaultModule string, referenceSlotLa
|
|||||||
return ModuleBinding{}, err
|
return ModuleBinding{}, err
|
||||||
}
|
}
|
||||||
return ModuleBinding{
|
return ModuleBinding{
|
||||||
Module: module,
|
Module: module,
|
||||||
LLMProfile: llmProfile,
|
Mode: cloneControl(binding.Mode),
|
||||||
StructuredOutputRepairAttempts: cloneStructuredOutputRepairAttempts(binding.StructuredOutputRepairAttempts),
|
MaxAdditionalTurns: cloneControl(binding.MaxAdditionalTurns),
|
||||||
ValidationPolicy: cloneValidationPolicyOverride(binding.ValidationPolicy),
|
Cache: cloneControl(binding.Cache),
|
||||||
Retries: binding.Retries,
|
LLMProfile: llmProfile,
|
||||||
Options: cloneOptions(binding.Options),
|
Options: cloneOptions(binding.Options),
|
||||||
References: references,
|
References: references,
|
||||||
Validators: cloneValidatorOverride(binding.Validators),
|
Validators: cloneValidatorOverride(binding.Validators),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1430,125 +1424,6 @@ func applyEffectiveLLMProfiles(resolved *ResolvedPipeline, pipelineProfile, over
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyEffectiveStructuredOutputRepairAttempts(resolved *ResolvedPipeline, pipelineAttempts *int) error {
|
|
||||||
apply := func(stage ModuleStage, laneID, module string, binding *ModuleBinding, executionClass contracts.ExecutionClass, kind string) error {
|
|
||||||
binding.StructuredOutputRepairAttempts = cloneStructuredOutputRepairAttempts(binding.StructuredOutputRepairAttempts)
|
|
||||||
if executionClass != contracts.ExecutionClassLLMBacked {
|
|
||||||
if binding.StructuredOutputRepairAttempts != nil {
|
|
||||||
if laneID == "" {
|
|
||||||
return fmt.Errorf("pipeline %q %s %q assigns structured_output_repair_attempts to deterministic %s %q", resolved.ID, stage, module, kind, binding.Module)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("pipeline %q lane %q %s %q assigns structured_output_repair_attempts to deterministic %s %q", resolved.ID, laneID, stage, module, kind, binding.Module)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if binding.StructuredOutputRepairAttempts == nil {
|
|
||||||
binding.StructuredOutputRepairAttempts = cloneStructuredOutputRepairAttempts(pipelineAttempts)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := apply(StageInput, "", resolved.Input.Module, &resolved.Input, resolved.InputExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := apply(StageChunk, "", resolved.Chunk.Module, &resolved.Chunk, resolved.ChunkExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for stepIndex := range resolved.Steps {
|
|
||||||
for laneIndex := range resolved.Steps[stepIndex].ArtifactLanes {
|
|
||||||
lane := &resolved.Steps[stepIndex].ArtifactLanes[laneIndex]
|
|
||||||
if err := apply(StageExtract, lane.ID, lane.Extract.Module, &lane.Extract, lane.ExtractExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := apply(StageMerge, lane.ID, lane.Merge.Module, &lane.Merge, lane.MergeExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := apply(StageNormalize, lane.ID, lane.Normalize.Module, &lane.Normalize, lane.NormalizeExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := apply(StageOutput, "", resolved.Output.Module, &resolved.Output, resolved.OutputExecutionClass, "module"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for chainIndex := range resolved.ValidatorChains {
|
|
||||||
chain := &resolved.ValidatorChains[chainIndex]
|
|
||||||
for validatorIndex := range chain.Validators {
|
|
||||||
validator := &chain.Validators[validatorIndex]
|
|
||||||
if err := apply(chain.Stage, chain.LaneID, chain.ModuleKey, &validator.Binding, validator.ExecutionClass, "validator"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func applyEffectiveValidationPolicies(resolved *ResolvedPipeline, pipelinePolicy *ValidationPolicyOverride) error {
|
|
||||||
apply := func(stage ModuleStage, laneID string, binding ModuleBinding, executionClass contracts.ExecutionClass) (ValidationPolicy, error) {
|
|
||||||
binding.ValidationPolicy = cloneValidationPolicyOverride(binding.ValidationPolicy)
|
|
||||||
if binding.ValidationPolicy != nil {
|
|
||||||
if err := binding.ValidationPolicy.Validate(); err != nil {
|
|
||||||
return ValidationPolicy{}, fmt.Errorf("pipeline %q %s validation_policy: %w", resolved.ID, stage, err)
|
|
||||||
}
|
|
||||||
if executionClass == contracts.ExecutionClassDeterministic && binding.ValidationPolicy.ProducerStructuralFailure != nil {
|
|
||||||
if laneID == "" {
|
|
||||||
return ValidationPolicy{}, fmt.Errorf("pipeline %q %s %q assigns producer_structural_failure to deterministic module", resolved.ID, stage, binding.Module)
|
|
||||||
}
|
|
||||||
return ValidationPolicy{}, fmt.Errorf("pipeline %q lane %q %s %q assigns producer_structural_failure to deterministic module", resolved.ID, laneID, stage, binding.Module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ResolveValidationPolicy(binding.ValidationPolicy, pipelinePolicy), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if pipelinePolicy != nil {
|
|
||||||
if err := pipelinePolicy.Validate(); err != nil {
|
|
||||||
return fmt.Errorf("pipeline %q validation_policy: %w", resolved.ID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if resolved.Input.ValidationPolicy != nil {
|
|
||||||
return fmt.Errorf("pipeline %q input validation_policy is not supported", resolved.ID)
|
|
||||||
}
|
|
||||||
if resolved.Output.ValidationPolicy != nil {
|
|
||||||
return fmt.Errorf("pipeline %q output validation_policy is not supported", resolved.ID)
|
|
||||||
}
|
|
||||||
for _, chain := range resolved.ValidatorChains {
|
|
||||||
for _, validator := range chain.Validators {
|
|
||||||
if validator.Binding.ValidationPolicy != nil {
|
|
||||||
if chain.LaneID == "" {
|
|
||||||
return fmt.Errorf("pipeline %q %s validator %q validation_policy is not supported", resolved.ID, chain.Stage, validator.Binding.Module)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("pipeline %q lane %q %s validator %q validation_policy is not supported", resolved.ID, chain.LaneID, chain.Stage, validator.Binding.Module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
policy, err := apply(StageChunk, "", resolved.Chunk, resolved.ChunkExecutionClass)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resolved.ChunkValidationPolicy = policy
|
|
||||||
for stepIndex := range resolved.Steps {
|
|
||||||
for laneIndex := range resolved.Steps[stepIndex].ArtifactLanes {
|
|
||||||
lane := &resolved.Steps[stepIndex].ArtifactLanes[laneIndex]
|
|
||||||
policy, err = apply(StageExtract, lane.ID, lane.Extract, lane.ExtractExecutionClass)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lane.ExtractValidationPolicy = policy
|
|
||||||
policy, err = apply(StageMerge, lane.ID, lane.Merge, lane.MergeExecutionClass)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lane.MergeValidationPolicy = policy
|
|
||||||
policy, err = apply(StageNormalize, lane.ID, lane.Normalize, lane.NormalizeExecutionClass)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
lane.NormalizeValidationPolicy = policy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolveBindings(bindings []ModuleBinding, defaultModule string, referenceSlotLabel string) ([]ModuleBinding, error) {
|
func resolveBindings(bindings []ModuleBinding, defaultModule string, referenceSlotLabel string) ([]ModuleBinding, error) {
|
||||||
if len(bindings) == 0 {
|
if len(bindings) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -1642,33 +1517,31 @@ func selectedArtifactLanes(pipelineID string, artifacts map[string]ArtifactLaneP
|
|||||||
|
|
||||||
func resolvedPipelineDigest(resolved ResolvedPipeline) (string, error) {
|
func resolvedPipelineDigest(resolved ResolvedPipeline) (string, error) {
|
||||||
withoutDigest := struct {
|
withoutDigest := struct {
|
||||||
ID string
|
ChunkControls ProducerControls
|
||||||
ConfiguredValidationPolicy *ValidationPolicyOverride
|
ID string
|
||||||
Input ModuleBinding
|
Input ModuleBinding
|
||||||
InputExecutionClass contracts.ExecutionClass
|
InputExecutionClass contracts.ExecutionClass
|
||||||
Chunk ModuleBinding
|
Chunk ModuleBinding
|
||||||
ChunkExecutionClass contracts.ExecutionClass
|
ChunkExecutionClass contracts.ExecutionClass
|
||||||
ChunkCorrectionProtocol contracts.CorrectionProtocol
|
ChunkCorrectionProtocol contracts.CorrectionProtocol
|
||||||
ChunkValidationPolicy ValidationPolicy
|
ChunkReferences ResolvedReferenceTarget
|
||||||
ChunkReferences ResolvedReferenceTarget
|
Steps []ResolvedPipelineStep
|
||||||
Steps []ResolvedPipelineStep
|
ValidatorChains []ResolvedValidatorChain
|
||||||
ValidatorChains []ResolvedValidatorChain
|
Output ModuleBinding
|
||||||
Output ModuleBinding
|
OutputExecutionClass contracts.ExecutionClass
|
||||||
OutputExecutionClass contracts.ExecutionClass
|
|
||||||
}{
|
}{
|
||||||
ID: resolved.ID,
|
ID: resolved.ID,
|
||||||
ConfiguredValidationPolicy: cloneValidationPolicyOverride(resolved.ConfiguredValidationPolicy),
|
ChunkControls: resolved.ChunkControls,
|
||||||
ChunkValidationPolicy: resolved.ChunkValidationPolicy,
|
Input: resolved.Input,
|
||||||
Input: resolved.Input,
|
InputExecutionClass: resolved.InputExecutionClass,
|
||||||
InputExecutionClass: resolved.InputExecutionClass,
|
Chunk: resolved.Chunk,
|
||||||
Chunk: resolved.Chunk,
|
ChunkExecutionClass: resolved.ChunkExecutionClass,
|
||||||
ChunkExecutionClass: resolved.ChunkExecutionClass,
|
ChunkCorrectionProtocol: resolved.ChunkCorrectionProtocol,
|
||||||
ChunkCorrectionProtocol: resolved.ChunkCorrectionProtocol,
|
ChunkReferences: resolved.ChunkReferences,
|
||||||
ChunkReferences: resolved.ChunkReferences,
|
Steps: resolved.Steps,
|
||||||
Steps: resolved.Steps,
|
ValidatorChains: resolved.ValidatorChains,
|
||||||
ValidatorChains: resolved.ValidatorChains,
|
Output: resolved.Output,
|
||||||
Output: resolved.Output,
|
OutputExecutionClass: resolved.OutputExecutionClass,
|
||||||
OutputExecutionClass: resolved.OutputExecutionClass,
|
|
||||||
}
|
}
|
||||||
encoded, err := json.Marshal(withoutDigest)
|
encoded, err := json.Marshal(withoutDigest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,115 +1,117 @@
|
|||||||
package pipeline
|
package pipeline
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
type ProducerStructuralFailureAction string
|
"strings"
|
||||||
|
|
||||||
const (
|
|
||||||
ProducerStructuralFailureFailRun ProducerStructuralFailureAction = "fail_run"
|
|
||||||
ProducerStructuralFailureRejectOutput ProducerStructuralFailureAction = "reject_output"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SemanticRejectionAction string
|
type ExecutionMode string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SemanticRejectionFailRun SemanticRejectionAction = "fail_run"
|
ModeStrict ExecutionMode = "strict"
|
||||||
SemanticRejectionRejectOutput SemanticRejectionAction = "reject_output"
|
ModePermissive ExecutionMode = "permissive"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ValidatorFailureAction string
|
func ParseExecutionMode(value string) (ExecutionMode, error) {
|
||||||
|
mode := ExecutionMode(strings.TrimSpace(value))
|
||||||
const (
|
if mode != ModeStrict && mode != ModePermissive {
|
||||||
ValidatorFailureWarnContinue ValidatorFailureAction = "warn_continue"
|
return "", fmt.Errorf("mode must be strict or permissive")
|
||||||
ValidatorFailureFailRun ValidatorFailureAction = "fail_run"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ValidationPolicyOverride records only explicitly configured terminal-policy
|
|
||||||
// values. Nil fields inherit independently from the pipeline or application.
|
|
||||||
type ValidationPolicyOverride struct {
|
|
||||||
ProducerStructuralFailure *ProducerStructuralFailureAction `json:"producer_structural_failure,omitempty"`
|
|
||||||
SemanticRejection *SemanticRejectionAction `json:"semantic_rejection,omitempty"`
|
|
||||||
ValidatorFailure *ValidatorFailureAction `json:"validator_failure,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidationPolicy is the concrete terminal policy retained by each resolved
|
|
||||||
// producer. It contains no inherited pointers.
|
|
||||||
type ValidationPolicy struct {
|
|
||||||
ProducerStructuralFailure ProducerStructuralFailureAction `json:"producer_structural_failure"`
|
|
||||||
SemanticRejection SemanticRejectionAction `json:"semantic_rejection"`
|
|
||||||
ValidatorFailure ValidatorFailureAction `json:"validator_failure"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func DefaultValidationPolicy() ValidationPolicy {
|
|
||||||
return ValidationPolicy{
|
|
||||||
ProducerStructuralFailure: ProducerStructuralFailureFailRun,
|
|
||||||
SemanticRejection: SemanticRejectionFailRun,
|
|
||||||
ValidatorFailure: ValidatorFailureWarnContinue,
|
|
||||||
}
|
}
|
||||||
|
return mode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (override ValidationPolicyOverride) Validate() error {
|
type CacheMode string
|
||||||
if override.ProducerStructuralFailure != nil {
|
|
||||||
switch *override.ProducerStructuralFailure {
|
const (
|
||||||
case ProducerStructuralFailureFailRun, ProducerStructuralFailureRejectOutput:
|
CacheAuto CacheMode = "auto"
|
||||||
default:
|
CacheBypass CacheMode = "bypass"
|
||||||
return fmt.Errorf("producer_structural_failure must be fail_run or reject_output")
|
CacheRefresh CacheMode = "refresh"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ParseCacheMode(value string) (CacheMode, error) {
|
||||||
|
mode := CacheMode(strings.TrimSpace(value))
|
||||||
|
switch mode {
|
||||||
|
case CacheAuto, CacheBypass, 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} {
|
||||||
|
if mode != nil {
|
||||||
|
parsed, err := ParseExecutionMode(string(*mode))
|
||||||
|
if err != nil {
|
||||||
|
return ProducerControls{}, err
|
||||||
|
}
|
||||||
|
result.Mode = parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if override.SemanticRejection != nil {
|
for _, turns := range []*int{profile.MaxAdditionalTurns, binding.MaxAdditionalTurns} {
|
||||||
switch *override.SemanticRejection {
|
if turns != nil {
|
||||||
case SemanticRejectionFailRun, SemanticRejectionRejectOutput:
|
if *turns < 0 {
|
||||||
default:
|
return ProducerControls{}, fmt.Errorf("max_additional_turns must not be negative")
|
||||||
return fmt.Errorf("semantic_rejection must be fail_run or reject_output")
|
}
|
||||||
|
result.MaxAdditionalTurns = *turns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if override.ValidatorFailure != nil {
|
for _, cache := range []*CacheMode{profile.Cache, binding.Cache, invocationCache} {
|
||||||
switch *override.ValidatorFailure {
|
if cache != nil {
|
||||||
case ValidatorFailureWarnContinue, ValidatorFailureFailRun:
|
parsed, err := ParseCacheMode(string(*cache))
|
||||||
default:
|
if err != nil {
|
||||||
return fmt.Errorf("validator_failure must be warn_continue or fail_run")
|
return ProducerControls{}, err
|
||||||
|
}
|
||||||
|
result.Cache = parsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func cloneControl[T any](value *T) *T {
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
copy := *value
|
||||||
|
return ©
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyEffectiveProducerControls(resolved *ResolvedPipeline, profile PipelineProfile, invocationCache *CacheMode) error {
|
||||||
|
apply := func(binding ModuleBinding, scope string) (ProducerControls, error) {
|
||||||
|
controls, err := ResolveProducerControls(binding, profile, invocationCache)
|
||||||
|
if err != nil {
|
||||||
|
return ProducerControls{}, fmt.Errorf("pipeline %q %s: %w", resolved.ID, scope, err)
|
||||||
|
}
|
||||||
|
return controls, nil
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
resolved.ChunkControls, err = apply(resolved.Chunk, "chunk")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for stepIndex := range resolved.Steps {
|
||||||
|
for laneIndex := range resolved.Steps[stepIndex].ArtifactLanes {
|
||||||
|
lane := &resolved.Steps[stepIndex].ArtifactLanes[laneIndex]
|
||||||
|
lane.ExtractControls, err = apply(lane.Extract, fmt.Sprintf("lane %q extract", lane.ID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
lane.MergeControls, err = apply(lane.Merge, fmt.Sprintf("lane %q merge", lane.ID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
lane.NormalizeControls, err = apply(lane.Normalize, fmt.Sprintf("lane %q normalize", lane.ID))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResolveValidationPolicy(binding, pipeline *ValidationPolicyOverride) ValidationPolicy {
|
|
||||||
resolved := DefaultValidationPolicy()
|
|
||||||
applyValidationPolicyOverride(&resolved, pipeline)
|
|
||||||
applyValidationPolicyOverride(&resolved, binding)
|
|
||||||
return resolved
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneValidationPolicyOverride(override *ValidationPolicyOverride) *ValidationPolicyOverride {
|
|
||||||
if override == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := *override
|
|
||||||
if override.ProducerStructuralFailure != nil {
|
|
||||||
value := *override.ProducerStructuralFailure
|
|
||||||
out.ProducerStructuralFailure = &value
|
|
||||||
}
|
|
||||||
if override.SemanticRejection != nil {
|
|
||||||
value := *override.SemanticRejection
|
|
||||||
out.SemanticRejection = &value
|
|
||||||
}
|
|
||||||
if override.ValidatorFailure != nil {
|
|
||||||
value := *override.ValidatorFailure
|
|
||||||
out.ValidatorFailure = &value
|
|
||||||
}
|
|
||||||
return &out
|
|
||||||
}
|
|
||||||
|
|
||||||
func applyValidationPolicyOverride(policy *ValidationPolicy, override *ValidationPolicyOverride) {
|
|
||||||
if override == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if override.ProducerStructuralFailure != nil {
|
|
||||||
policy.ProducerStructuralFailure = *override.ProducerStructuralFailure
|
|
||||||
}
|
|
||||||
if override.SemanticRejection != nil {
|
|
||||||
policy.SemanticRejection = *override.SemanticRejection
|
|
||||||
}
|
|
||||||
if override.ValidatorFailure != nil {
|
|
||||||
policy.ValidatorFailure = *override.ValidatorFailure
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,102 +2,87 @@ package pipeline
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolvePipelineAppliesValidationPolicyFieldByField(t *testing.T) {
|
func TestProducerControlsResolvePrecedenceAndExplicitZero(t *testing.T) {
|
||||||
|
strict, permissive := ModeStrict, ModePermissive
|
||||||
|
auto, bypass, refresh := CacheAuto, CacheBypass, CacheRefresh
|
||||||
|
zero, five := 0, 5
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
profile PipelineProfile
|
||||||
|
binding ModuleBinding
|
||||||
|
invocation *CacheMode
|
||||||
|
want ProducerControls
|
||||||
|
}{
|
||||||
|
{"defaults", PipelineProfile{}, ModuleBinding{}, nil, ProducerControls{ModeStrict, 2, CacheAuto}},
|
||||||
|
{"pipeline", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{}, nil, ProducerControls{ModePermissive, 5, CacheRefresh}},
|
||||||
|
{"binding", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{Mode: &strict, MaxAdditionalTurns: &zero, Cache: &auto}, nil, ProducerControls{ModeStrict, 0, CacheAuto}},
|
||||||
|
{"invocation", PipelineProfile{Cache: &refresh}, ModuleBinding{Cache: &auto}, &bypass, ProducerControls{ModeStrict, 2, CacheBypass}},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got, err := ResolveProducerControls(test.binding, test.profile, test.invocation)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got != test.want {
|
||||||
|
t.Fatalf("controls = %#v, want %#v", got, test.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProducerControlsRejectInvalidValuesWithoutMaximumBudgets(t *testing.T) {
|
||||||
|
invalidMode, invalidCache := ExecutionMode("unknown"), CacheMode("unknown")
|
||||||
|
negative, large := -1, 1000000
|
||||||
|
for _, binding := range []ModuleBinding{{Mode: &invalidMode}, {Cache: &invalidCache}, {MaxAdditionalTurns: &negative}} {
|
||||||
|
if _, err := ResolveProducerControls(binding, PipelineProfile{}, nil); err == nil {
|
||||||
|
t.Fatalf("accepted invalid controls: %#v", binding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
got, err := ResolveProducerControls(ModuleBinding{MaxAdditionalTurns: &large}, PipelineProfile{}, nil)
|
||||||
|
if err != nil || got.MaxAdditionalTurns != large {
|
||||||
|
t.Fatalf("large allowance = %#v, %v", got, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestModuleBindingRoundTripRetainsExplicitControls(t *testing.T) {
|
||||||
|
strict, bypass, zero := ModeStrict, CacheBypass, 0
|
||||||
|
input := ModuleBinding{Module: "fixture", Mode: &strict, Cache: &bypass, MaxAdditionalTurns: &zero}
|
||||||
|
data, err := json.Marshal(input)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var output ModuleBinding
|
||||||
|
if err := json.Unmarshal(data, &output); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if output.Mode == nil || *output.Mode != strict || output.Cache == nil || *output.Cache != bypass || output.MaxAdditionalTurns == nil || *output.MaxAdditionalTurns != 0 {
|
||||||
|
t.Fatalf("controls lost in round-trip: %s", data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolvedProducerControlsApplyToEveryLaneOperation(t *testing.T) {
|
||||||
profile := baselineProfile()
|
profile := baselineProfile()
|
||||||
profile.ValidationPolicy = validationPolicyOverride(
|
permissive, bypass, zero := ModePermissive, CacheBypass, 0
|
||||||
ProducerStructuralFailureRejectOutput,
|
profile.Mode = &permissive
|
||||||
SemanticRejectionRejectOutput,
|
profile.Chunk.MaxAdditionalTurns = &zero
|
||||||
ValidatorFailureFailRun,
|
resolved, err := ResolvePipeline(profile, ResolveOptions{CacheOverride: &bypass}, newProfileCatalog(t))
|
||||||
)
|
|
||||||
profile.Chunk.ValidationPolicy = validationPolicyOverride("", "", ValidatorFailureWarnContinue)
|
|
||||||
lane := profile.Artifacts["events"]
|
|
||||||
lane.Extract.ValidationPolicy = validationPolicyOverride("", SemanticRejectionFailRun, "")
|
|
||||||
lane.Merge.ValidationPolicy = validationPolicyOverride("", "", ValidatorFailureWarnContinue)
|
|
||||||
profile.Artifacts["events"] = lane
|
|
||||||
|
|
||||||
resolved, err := ResolvePipeline(profile, ResolveOptions{}, newProfileCatalog(t))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ResolvePipeline() error = %v", err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got, want := resolved.ChunkValidationPolicy, (ValidationPolicy{ProducerStructuralFailure: ProducerStructuralFailureRejectOutput, SemanticRejection: SemanticRejectionRejectOutput, ValidatorFailure: ValidatorFailureWarnContinue}); got != want {
|
if resolved.ChunkControls != (ProducerControls{ModePermissive, 0, CacheBypass}) {
|
||||||
t.Fatalf("chunk validation policy = %#v, want %#v", got, want)
|
t.Fatalf("chunk controls = %#v", resolved.ChunkControls)
|
||||||
}
|
}
|
||||||
resolvedLane := resolved.Steps[0].ArtifactLanes[0]
|
for _, step := range resolved.Steps {
|
||||||
if got, want := resolvedLane.ExtractValidationPolicy, (ValidationPolicy{ProducerStructuralFailure: ProducerStructuralFailureRejectOutput, SemanticRejection: SemanticRejectionFailRun, ValidatorFailure: ValidatorFailureFailRun}); got != want {
|
for _, lane := range step.ArtifactLanes {
|
||||||
t.Fatalf("extract validation policy = %#v, want %#v", got, want)
|
for _, got := range []ProducerControls{lane.ExtractControls, lane.MergeControls, lane.NormalizeControls} {
|
||||||
}
|
if got != (ProducerControls{ModePermissive, 2, CacheBypass}) {
|
||||||
if got, want := resolvedLane.MergeValidationPolicy, (ValidationPolicy{ProducerStructuralFailure: ProducerStructuralFailureRejectOutput, SemanticRejection: SemanticRejectionRejectOutput, ValidatorFailure: ValidatorFailureWarnContinue}); got != want {
|
t.Fatalf("lane controls = %#v", got)
|
||||||
t.Fatalf("merge validation policy = %#v, want %#v", got, want)
|
}
|
||||||
}
|
}
|
||||||
if got, want := resolvedLane.NormalizeValidationPolicy, (ValidationPolicy{ProducerStructuralFailure: ProducerStructuralFailureRejectOutput, SemanticRejection: SemanticRejectionRejectOutput, ValidatorFailure: ValidatorFailureFailRun}); got != want {
|
}
|
||||||
t.Fatalf("normalize validation policy = %#v, want %#v", got, want)
|
|
||||||
}
|
|
||||||
|
|
||||||
*profile.ValidationPolicy.SemanticRejection = SemanticRejectionFailRun
|
|
||||||
if got := resolved.ConfiguredValidationPolicy.SemanticRejection; got == nil || *got != SemanticRejectionRejectOutput {
|
|
||||||
t.Fatalf("resolved configured policy aliases profile: %#v", resolved.ConfiguredValidationPolicy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolvePipelineRejectsStructuralPolicyOverrideOnDeterministicProducer(t *testing.T) {
|
|
||||||
profile := baselineProfile()
|
|
||||||
profile.Chunk.ValidationPolicy = validationPolicyOverride(ProducerStructuralFailureRejectOutput, "", "")
|
|
||||||
_, err := ResolvePipeline(profile, ResolveOptions{}, newProfileCatalog(t))
|
|
||||||
if err == nil || !strings.Contains(err.Error(), "producer_structural_failure") || !strings.Contains(err.Error(), "deterministic") {
|
|
||||||
t.Fatalf("ResolvePipeline() error = %v, want deterministic structural-policy rejection", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidationPolicyChangesResolvedDigestAndRoundTripsBindings(t *testing.T) {
|
|
||||||
left := baselineProfile()
|
|
||||||
right := baselineProfile()
|
|
||||||
right.ValidationPolicy = validationPolicyOverride("", SemanticRejectionRejectOutput, "")
|
|
||||||
|
|
||||||
leftResolved, err := ResolvePipeline(left, ResolveOptions{}, newProfileCatalog(t))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("ResolvePipeline(left) error = %v", err)
|
|
||||||
}
|
|
||||||
rightResolved, err := ResolvePipeline(right, ResolveOptions{}, newProfileCatalog(t))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("ResolvePipeline(right) error = %v", err)
|
|
||||||
}
|
|
||||||
if leftResolved.Digest == rightResolved.Digest {
|
|
||||||
t.Fatal("validation policy change did not change resolved digest")
|
|
||||||
}
|
|
||||||
|
|
||||||
binding := ModuleBinding{Module: "producer", ValidationPolicy: validationPolicyOverride(ProducerStructuralFailureRejectOutput, SemanticRejectionRejectOutput, ValidatorFailureFailRun)}
|
|
||||||
encoded, err := json.Marshal(binding)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("marshal binding: %v", err)
|
|
||||||
}
|
|
||||||
var decoded ModuleBinding
|
|
||||||
if err := json.Unmarshal(encoded, &decoded); err != nil {
|
|
||||||
t.Fatalf("unmarshal binding: %v", err)
|
|
||||||
}
|
|
||||||
if decoded.ValidationPolicy == nil || *decoded.ValidationPolicy.ProducerStructuralFailure != ProducerStructuralFailureRejectOutput || *decoded.ValidationPolicy.SemanticRejection != SemanticRejectionRejectOutput || *decoded.ValidationPolicy.ValidatorFailure != ValidatorFailureFailRun {
|
|
||||||
t.Fatalf("round-tripped validation policy = %#v", decoded.ValidationPolicy)
|
|
||||||
}
|
|
||||||
cloned := cloneModuleBinding(binding)
|
|
||||||
*binding.ValidationPolicy.ValidatorFailure = ValidatorFailureWarnContinue
|
|
||||||
if got := *cloned.ValidationPolicy.ValidatorFailure; got != ValidatorFailureFailRun {
|
|
||||||
t.Fatalf("cloned validation policy aliases binding: %q", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func validationPolicyOverride(structural ProducerStructuralFailureAction, semantic SemanticRejectionAction, validator ValidatorFailureAction) *ValidationPolicyOverride {
|
|
||||||
policy := &ValidationPolicyOverride{}
|
|
||||||
if structural != "" {
|
|
||||||
policy.ProducerStructuralFailure = &structural
|
|
||||||
}
|
|
||||||
if semantic != "" {
|
|
||||||
policy.SemanticRejection = &semantic
|
|
||||||
}
|
|
||||||
if validator != "" {
|
|
||||||
policy.ValidatorFailure = &validator
|
|
||||||
}
|
|
||||||
return policy
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -94,8 +94,9 @@ func cloneModuleBindings(bindings []ModuleBinding) []ModuleBinding {
|
|||||||
func cloneModuleBinding(binding ModuleBinding) ModuleBinding {
|
func cloneModuleBinding(binding ModuleBinding) ModuleBinding {
|
||||||
binding.Module = strings.TrimSpace(binding.Module)
|
binding.Module = strings.TrimSpace(binding.Module)
|
||||||
binding.LLMProfile = strings.TrimSpace(binding.LLMProfile)
|
binding.LLMProfile = strings.TrimSpace(binding.LLMProfile)
|
||||||
binding.StructuredOutputRepairAttempts = cloneStructuredOutputRepairAttempts(binding.StructuredOutputRepairAttempts)
|
binding.Mode = cloneControl(binding.Mode)
|
||||||
binding.ValidationPolicy = cloneValidationPolicyOverride(binding.ValidationPolicy)
|
binding.MaxAdditionalTurns = cloneControl(binding.MaxAdditionalTurns)
|
||||||
|
binding.Cache = cloneControl(binding.Cache)
|
||||||
binding.Options = cloneOptions(binding.Options)
|
binding.Options = cloneOptions(binding.Options)
|
||||||
if len(binding.References) > 0 {
|
if len(binding.References) > 0 {
|
||||||
references := make(map[string]ReferenceSource, len(binding.References))
|
references := make(map[string]ReferenceSource, len(binding.References))
|
||||||
@@ -108,14 +109,6 @@ func cloneModuleBinding(binding ModuleBinding) ModuleBinding {
|
|||||||
return binding
|
return binding
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneStructuredOutputRepairAttempts(attempts *int) *int {
|
|
||||||
if attempts == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
value := *attempts
|
|
||||||
return &value
|
|
||||||
}
|
|
||||||
|
|
||||||
func cloneReferenceSource(source ReferenceSource) ReferenceSource {
|
func cloneReferenceSource(source ReferenceSource) ReferenceSource {
|
||||||
out := source
|
out := source
|
||||||
if source.Artifact != nil {
|
if source.Artifact != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user