diff --git a/pkgs/fleet/crates/fleet-config/src/lib.rs b/pkgs/fleet/crates/fleet-config/src/lib.rs index b90472dd44..621e4d420b 100644 --- a/pkgs/fleet/crates/fleet-config/src/lib.rs +++ b/pkgs/fleet/crates/fleet-config/src/lib.rs @@ -397,8 +397,11 @@ impl Config { /// value. Port 0 cannot be dialled, and `idle_exit_secs = 0` would /// make the broker exit at its first idle tick — the opposite of /// the "never idle-exit" an operator would mean by it. Reject all - /// three at load, naming the field; omitting the field keeps the + /// these at load, naming the field; omitting the field keeps the /// documented default. There is no zero spelling for "disabled". + /// The `[dispatch-test] threshold` (#6603) joined the rule when it + /// landed: `active < 0` can never hold, so 0 is never a capacity + /// bound either. fn validate(&self, path: &std::path::Path) -> Result<(), ConfigError> { let reject = |field: &str, default: u64| ConfigError::Parse { path: path.to_path_buf(), @@ -416,6 +419,16 @@ impl Config { if self.proxy.idle_exit_secs == Some(0) { return Err(reject("[proxy] idle_exit_secs", DEFAULT_IDLE_EXIT_SECS)); } + // #6603: the [dispatch-test] threshold landed later (#6580) + // and is the same misspelling class — `active < 0` is false + // for every count, so 0 makes every execution home + // permanently ineligible instead of meaning "no limit". + if self.dispatch_test.threshold == Some(0) { + return Err(reject( + "[dispatch-test] threshold", + DEFAULT_DISPATCH_TEST_THRESHOLD, + )); + } Ok(()) } @@ -967,6 +980,10 @@ mod tests { ("[proxy]\negress_proxy_port = 0\n", "egress_proxy_port"), ("[dispatch]\nport = 0\n", "[dispatch] port"), ("[proxy]\nidle_exit_secs = 0\n", "idle_exit_secs"), + ( + "[dispatch-test]\nthreshold = 0\n", + "[dispatch-test] threshold", + ), ] { let (_dir, path) = write_temp(contents); match Config::load_from(&path) { @@ -986,6 +1003,16 @@ mod tests { assert_eq!(cfg.egress_proxy_port(), 3131); assert_eq!(cfg.idle_exit_secs(), 60); assert_eq!(cfg.dispatch_port(), 4880); + // #6603: an omitted dispatch-test threshold keeps the + // documented default (40) and a positive value passes + // unchanged. + assert_eq!( + cfg.dispatch_test_threshold(), + DEFAULT_DISPATCH_TEST_THRESHOLD + ); + let (_dir3, path3) = write_temp("[dispatch-test]\nthreshold = 7\n"); + let cfg = Config::load_from(&path3).unwrap(); + assert_eq!(cfg.dispatch_test_threshold(), 7); } } diff --git a/pkgs/fleet/crates/fleet-dispatch-test/src/lib.rs b/pkgs/fleet/crates/fleet-dispatch-test/src/lib.rs index 67fadcb2b4..3ec35a3fc6 100644 --- a/pkgs/fleet/crates/fleet-dispatch-test/src/lib.rs +++ b/pkgs/fleet/crates/fleet-dispatch-test/src/lib.rs @@ -254,11 +254,22 @@ impl Args { fn parse_threshold(raw: Option<&str>, config: &Config) -> Result { match raw { None => Ok(config.dispatch_test_threshold()), - Some(v) => v.parse::().map_err(|_| { - usage(format!( - "--threshold must be a non-negative integer, got {v:?}" - )) - }), + Some(v) => { + let parsed = v.parse::().map_err(|_| { + usage(format!( + "--threshold must be a positive integer, got {v:?}" + )) + })?; + // #6603: 0 is the #6412 misspelling class on the CLI path + // too — `active < 0` is false for every count, so no + // execution home could ever be eligible. + if parsed == 0 { + return Err(usage( + "--threshold must not be 0; omit --threshold for the configured threshold", + )); + } + Ok(parsed) + } } } @@ -1152,6 +1163,20 @@ mod tests { assert!(!workflow_present(&json!({"workflows": []}))); } + #[test] + fn threshold_zero_is_a_usage_error() { + // #6603: --threshold 0 can never be satisfied (active < 0 is + // always false), so it is a usage error (exit 2), not a scan + // against a dead threshold. Positive values and the omitted + // flag (config default 40) pass unchanged. + let config = Config::default(); + let err = parse_threshold(Some("0"), &config).unwrap_err(); + assert_eq!(err.exit_code(), 2); + assert!(err.message().contains("must not be 0"), "{}", err.message()); + assert_eq!(parse_threshold(Some("7"), &config).unwrap(), 7); + assert_eq!(parse_threshold(None, &config).unwrap(), 40); + } + #[test] fn eligibility_is_threshold_and_workflow() { assert!(eligible(39, 40, true));