diff --git a/CHANGELOG.md b/CHANGELOG.md index 98415cbf..4d47cb37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 times configurations times iterations. A benchmark over four cases with `--iteration 5` previously reported only `Would run 4 case(s)` for 40 executions. A negative `--iteration` is now rejected in a dry run as well. +- Reject a negative `constraints.timeout_seconds` or `constraints.max_turns` + in a case. Both silently fell back to the eval defaults. + `cases.defaults.timeout_seconds: -1` still disables the case deadline. - Warn when a selected case has no judge rule, no `expect` check and no turn `post_condition`. Such a case can pass without anything checking the agent's output, and its report read the same as a case that passed its diff --git a/internal/config/validator.go b/internal/config/validator.go index 27317ae6..75e49e77 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -173,6 +173,7 @@ func (v *Validator) ValidateCaseConfig(cfg *CaseConfig) error { errs = append(errs, validateExpect("expect", cfg.Expect)...) errs = append(errs, validateCaseMCP(cfg.MCP)...) + errs = append(errs, validateConstraintLimits(cfg.Constraints)...) if len(errs) > 0 { return fmt.Errorf("validation errors:\n - %s", strings.Join(errs, "\n - ")) @@ -558,6 +559,20 @@ func validateCollectArtifacts(field string, patterns []string) []string { return errs } +// validateConstraintLimits rejects negative per-case limits, which would +// otherwise fall back to the defaults silently. Only cases.defaults accepts a +// negative timeout, as the opt-out from the case deadline. +func validateConstraintLimits(c Constraints) []string { + var errs []string + if c.MaxTurns < 0 { + errs = append(errs, "constraints.max_turns must be non-negative; 0 uses cases.defaults.max_turns") + } + if c.TimeoutSeconds < 0 { + errs = append(errs, "constraints.timeout_seconds must be non-negative; 0 uses cases.defaults.timeout_seconds, and cases.defaults.timeout_seconds: -1 disables the deadline") + } + return errs +} + func validatePassThreshold(threshold *float64) []string { if threshold == nil { return nil diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index 3029beec..ed96e9b1 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -5,6 +5,26 @@ import ( "testing" ) +func TestNegativeCaseExecutionLimits(t *testing.T) { + t.Parallel() + for _, value := range []int{-1, 0, 1} { + cfg := DefaultEvalConfig() + cfg.Cases.Files = []string{"case.yaml"} + cfg.Cases.Defaults.MaxTurns, cfg.Cases.Defaults.TimeoutSeconds = value, value + if err := NewValidator().ValidateEvalConfig(cfg); err != nil { + t.Errorf("cases.defaults limit %d rejected; -1 must stay the opt-out: %v", value, err) + } + c := &CaseConfig{Input: Input{Prompt: "read"}, Constraints: Constraints{MaxTurns: value, TimeoutSeconds: value}} + err := NewValidator().ValidateCaseConfig(c) + switch { + case value >= 0 && err != nil: + t.Errorf("constraints limit %d rejected: %v", value, err) + case value < 0 && (err == nil || !strings.Contains(err.Error(), "constraints.max_turns") || !strings.Contains(err.Error(), "constraints.timeout_seconds")): + t.Errorf("negative constraints accepted or field missing: %v", err) + } + } +} + func TestEnvironmentAgentHome(t *testing.T) { for _, kind := range []string{runtimeTypeNone, runtimeTypeDocker, runtimeTypeOpenSandbox} { for _, mode := range []string{"", "inherited", "temporary", "unknown"} {