Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
case-sensitive names.
- Count primary cases consistently in Markdown and CLI summaries for benchmark
runs, without counting baseline rows as extra cases or discarding their details.
- Validate `cases.parallelism` and `cases.retry_policy.retry_on`.
`parallelism` outside the documented range of 1 to 256 passed `validate`,
and so did a misspelled retry reason such as `timeouts`, which never
matched. `run --parallelism` still replaces an out-of-range file value.
- Reject malformed `--include-case-name` and `--exclude-case-name` glob patterns
before loading cases, including in auto mode, instead of silently ignoring them.

Expand Down
8 changes: 5 additions & 3 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
)

const (
maxParallelismOverride = 256
runtimeKwargFlagName = "runtime-kwarg"
runtimeKwargAlias = "rk"
runtimeFlagName = "runtime"
Expand Down Expand Up @@ -550,12 +549,15 @@ func applyRunConfigOverrides(evalCfg *config.EvalConfig, cmd *cobra.Command) err
if parallelism < 1 {
return fmt.Errorf("invalid --parallelism %d: must be >= 1", parallelism)
}
if parallelism > maxParallelismOverride {
return fmt.Errorf("invalid --parallelism %d: must be <= %d", parallelism, maxParallelismOverride)
if parallelism > config.MaxCasesParallelism {
return fmt.Errorf("invalid --parallelism %d: must be <= %d", parallelism, config.MaxCasesParallelism)
}

evalCfg.Cases.Parallelism = parallelism
}
if err := config.ValidateCasesParallelism(evalCfg.Cases.Parallelism); err != nil {
return fmt.Errorf("validation failed: %w", err)
}
return validateWorkspaceOverride(evalCfg, cmd)
}

Expand Down
100 changes: 100 additions & 0 deletions internal/cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,106 @@ func TestApplyRunConfigOverrides_Workspace(t *testing.T) {
}
}

// run checks the parallelism it will use: a valid --parallelism replaces an
// out-of-range file value, and without one the file value is rejected.
func TestApplyRunConfigOverrides_ChecksEffectiveParallelism(t *testing.T) {
t.Parallel()

for _, tt := range []struct {
name string
flag string
wantError string
}{
{name: "override replaces the file value", flag: "4"},
{name: "file value without override", wantError: "cases.parallelism must be between 1 and 256, got 257"},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
cmd := &cobra.Command{}
cmd.SetContext(context.Background())
cmd.Flags().Int("parallelism", 0, "")
if tt.flag != "" {
if err := cmd.Flags().Set("parallelism", tt.flag); err != nil {
t.Fatal(err)
}
}
cfg := config.DefaultEvalConfig()
cfg.Cases.Parallelism = 257

err := applyRunConfigOverrides(cfg, cmd)
if tt.wantError == "" {
if err != nil || cfg.Cases.Parallelism != 4 {
t.Fatalf("applyRunConfigOverrides: err=%v parallelism=%d", err, cfg.Cases.Parallelism)
}
return
}
if err == nil || !strings.Contains(err.Error(), tt.wantError) {
t.Fatalf("error = %v, want substring %q", err, tt.wantError)
}
})
}
}

// One eval file with cases.parallelism 257 through the real commands: validate
// checks the file value, and run checks the value left after --parallelism.
func TestCommandsCheckParallelismFromOutOfRangeFile(t *testing.T) {
root := t.TempDir()
writeAutoModeSkill(t, root)
casesDir := filepath.Join(root, "evals", "cases")
if err := os.MkdirAll(casesDir, 0o755); err != nil {
t.Fatal(err)
}
evalPath := filepath.Join(root, "evals", "eval.yaml")
evalYAML := "schema_version: v1alpha1\nenvironment: {type: none}\nengine: {name: claude_code}\ncases:\n parallelism: 257\n files: [evals/cases/basic.yaml]\n"
if err := os.WriteFile(evalPath, []byte(evalYAML), 0o600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(casesDir, "basic.yaml"), []byte("id: basic\ninput:\n prompt: hello\n"), 0o600); err != nil {
t.Fatal(err)
}
origUIOutput := ui.Output
ui.Output = io.Discard
t.Cleanup(func() { ui.Output = origUIOutput })

const rangeError = "cases.parallelism must be between 1 and 256, got 257"
for _, tc := range []struct {
name string
run func(*cobra.Command) error
parallelism string
wantErr string
}{
{name: "validate", run: func(cmd *cobra.Command) error { return validateCmd.RunE(cmd, []string{evalPath}) }, wantErr: rangeError},
{name: "run without override", run: func(cmd *cobra.Command) error { return runEval(cmd, []string{root}) }, wantErr: rangeError},
{name: "run with override", run: func(cmd *cobra.Command) error { return runEval(cmd, []string{root}) }, parallelism: "4"},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := newRunPhaseTestCommand(t)
// --dry-run stops run after config preparation, before any agent is built.
if err := cmd.Flags().Set("dry-run", testFlagBoolTrue); err != nil {
t.Fatal(err)
}
if tc.parallelism != "" {
if err := cmd.Flags().Set("parallelism", tc.parallelism); err != nil {
t.Fatal(err)
}
}
stdout, err := captureStdout(t, func() error { return tc.run(cmd) })
if tc.wantErr != "" {
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
t.Fatalf("error = %v, want %q", err, tc.wantErr)
}
return
}
if err != nil {
t.Fatalf("error = %v, want config preparation to pass", err)
}
if !strings.Contains(stdout, "Would run 1 case(s)") {
t.Fatalf("stdout = %q, want the dry-run plan", stdout)
}
})
}
}

func TestEvaluateOptionsFromFlags_RejectsNegativeIteration(t *testing.T) {
t.Parallel()

Expand Down
45 changes: 42 additions & 3 deletions internal/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ func (v *Validator) ValidateEvalConfig(cfg *EvalConfig) error {
if len(cfg.Cases.Files) == 0 {
errs = append(errs, "cases.files must contain at least one case file")
}
if cfg.Cases.RetryPolicy.MaxRetries > maxRetryPolicyRetries {
errs = append(errs, fmt.Sprintf("cases.retry_policy.max_retries must be <= %d", maxRetryPolicyRetries))
}
errs = append(errs, validateCasesExecution(cfg.Cases)...)

errs = append(errs, validateCollectArtifacts("cases.defaults.collect_artifacts", cfg.Cases.Defaults.CollectArtifacts)...)
errs = append(errs, validateExpect("cases.defaults.expect", cfg.Cases.Defaults.Expect)...)
Expand Down Expand Up @@ -234,6 +232,44 @@ func validateExpect(prefix string, expect Expect) []string {
return errs
}

// validateCasesExecution checks the retry policy of a suite.
func validateCasesExecution(cases CasesConfig) []string {
var errs []string
if cases.RetryPolicy.MaxRetries > maxRetryPolicyRetries {
errs = append(errs, fmt.Sprintf("cases.retry_policy.max_retries must be <= %d", maxRetryPolicyRetries))
}
errs = append(errs, validateRetryOn(cases.RetryPolicy.RetryOn)...)
return errs
}

// MaxCasesParallelism is the highest cases.parallelism and run --parallelism
// value.
const MaxCasesParallelism = 256

// ValidateCasesParallelism checks the parallelism a run will use. It is not
// part of ValidateEvalConfig because run --parallelism replaces the file
// value: run checks the effective value after its overrides, and validate
// checks the file value. 0 means unset; the loader fills in the default.
func ValidateCasesParallelism(parallelism int) error {
if parallelism < 0 || parallelism > MaxCasesParallelism {
return fmt.Errorf("cases.parallelism must be between 1 and %d, got %d", MaxCasesParallelism, parallelism)
}
return nil
}

// validateRetryOn rejects retry reasons the evaluator never produces. It
// matches reasons without case, so a misspelled entry ("timeouts") never
// matches anything.
func validateRetryOn(reasons []string) []string {
var errs []string
for i, reason := range reasons {
if !strings.EqualFold(reason, "timeout") && !strings.EqualFold(reason, "error") {
errs = append(errs, fmt.Sprintf("cases.retry_policy.retry_on[%d] %q must be one of: timeout, error", i, reason))
}
}
return errs
}

// validateCaseMCP validates case-level MCP overrides. The MVP restricts
// case-level servers to mocked fixture variation: every server needs a name,
// must use mode: mocked, must be unique within the case, and must not declare
Expand Down Expand Up @@ -642,6 +678,9 @@ func (v *Validator) ValidateAll(result *EvalResult) error {
if err := v.ValidateEvalConfig(result.Eval); err != nil {
return err
}
if err := ValidateCasesParallelism(result.Eval.Cases.Parallelism); err != nil {
return err
}
return v.ValidateCasesWithEvalDefaults(result.Eval, result.Cases)
}

Expand Down
66 changes: 66 additions & 0 deletions internal/config/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2618,3 +2618,69 @@ func TestValidatorReservedVariant(t *testing.T) {
})
}
}

func TestValidateRetryOn(t *testing.T) {
t.Parallel()

base := func() *EvalConfig {
return &EvalConfig{
SchemaVersion: "v1alpha1",
Environment: Environment{Type: "none"},
Engine: EngineConfig{Name: "claude_code"},
Cases: CasesConfig{Files: []string{"evals/cases/test.yaml"}},
}
}
for _, tc := range []struct {
name string
edit func(*EvalConfig)
wantErr string
}{
{name: "defaults", edit: func(*EvalConfig) {}},
{name: "known retry reasons in any case", edit: func(c *EvalConfig) {
c.Cases.RetryPolicy = RetryPolicy{MaxRetries: 1, RetryOn: []string{"timeout", "ERROR"}}
}},
{name: "misspelled retry reason", edit: func(c *EvalConfig) {
c.Cases.RetryPolicy = RetryPolicy{MaxRetries: 1, RetryOn: []string{"timeout", "timeouts"}}
}, wantErr: `cases.retry_policy.retry_on[1] "timeouts" must be one of: timeout, error`},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
cfg := base()
tc.edit(cfg)
err := NewValidator().ValidateEvalConfig(cfg)
if tc.wantErr == "" {
if err != nil {
t.Fatalf("ValidateEvalConfig() error = %v", err)
}
return
}
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
t.Fatalf("ValidateEvalConfig() error = %v, want %q", err, tc.wantErr)
}
})
}
}

func TestValidateCasesParallelism(t *testing.T) {
t.Parallel()

for _, tc := range []struct {
parallelism int
wantErr bool
}{{0, false}, {1, false}, {256, false}, {257, true}, {-3, true}} {
err := ValidateCasesParallelism(tc.parallelism)
if (err != nil) != tc.wantErr {
t.Errorf("ValidateCasesParallelism(%d) error = %v, wantErr %t", tc.parallelism, err, tc.wantErr)
}
}
// validate checks the file value through ValidateAll.
result := &EvalResult{Eval: &EvalConfig{
SchemaVersion: "v1alpha1",
Environment: Environment{Type: "none"},
Engine: EngineConfig{Name: "claude_code"},
Cases: CasesConfig{Files: []string{"evals/cases/test.yaml"}, Parallelism: 5000},
}}
if err := NewValidator().ValidateAll(result); err == nil || !strings.Contains(err.Error(), "cases.parallelism must be between 1 and 256, got 5000") {
t.Fatalf("ValidateAll() error = %v, want a parallelism error", err)
}
}
Loading