Resolve producer modes turn allowances cache controls and shared workers

This commit is contained in:
2026-11-21 22:49:41 +00:00
parent cc14a7a5cc
commit 40fbcc61b1
26 changed files with 655 additions and 1405 deletions

View File

@@ -8,142 +8,31 @@ import (
)
func TestValidateConcurrencyRules(t *testing.T) {
tests := []struct {
name string
setup func(*Config)
want string
}{
{
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)
}
})
for _, workers := range []int{0, -1, 1, 64, 1000000} {
cfg := Default()
cfg.Concurrency.Workers = workers
err := cfg.Validate()
if (err != nil) != (workers <= 0) {
t.Fatalf("workers %d: %v", workers, err)
}
}
}
func TestValidateStateSurfaceRules(t *testing.T) {
tests := []struct {
for _, test := range []struct {
name string
setup func(*Config)
want string
}{
{
name: "blank output root",
setup: func(cfg *Config) {
cfg.Output.Directory = " "
},
want: "output.directory must not be empty",
},
{
name: "blank debug root",
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)
{"output", func(c *Config) { c.Output.Directory = "" }},
{"cache", func(c *Config) { c.CacheDirectory = "\\x00" }},
{"debug", func(c *Config) { c.Debug.Directory = "\\x00" }},
} {
t.Run(test.name, func(t *testing.T) {
c := Default()
test.setup(&c)
if c.Validate() == nil {
t.Fatal("accepted invalid path")
}
})
}
}
@@ -214,20 +103,21 @@ func TestValidateIdentifiersAfterTrimming(t *testing.T) {
}
}
func TestValidateBindingRetriesAndProfiles(t *testing.T) {
func TestValidateBindingControlsAndProfiles(t *testing.T) {
tests := []struct {
name string
setup func(*Config)
want string
}{
{
name: "negative retries",
name: "negative turns",
setup: func(cfg *Config) {
profile := validationProfile()
profile.Input.Retries = -1
value := -1
profile.Input.MaxAdditionalTurns = &value
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",
@@ -302,12 +192,12 @@ func TestValidateValidatorBindingRules(t *testing.T) {
profile.Chunk.Validators = pipeline.ValidatorOverride{
Set: true,
Validators: []pipeline.ModuleBinding{{
Module: "validator",
Retries: -1,
Module: "validator",
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",