From 4c94c644c4dc9b7c3faec68065ea2c47ce68bccd Mon Sep 17 00:00:00 2001 From: ddidderr Date: Sat, 18 Jul 2026 18:07:48 +0200 Subject: [PATCH] fix(cli): keep normal help levels below ultra The library reports an absolute maximum compression level of 22, but the CLI advertises levels 1 through 19 unless `--ultra` is selected. The Rust frontend used the absolute maximum for both help lines, diverging from the original C contract and failing the help golden test. Separate the normal help ceiling from the ultra ceiling and add a focused regression assertion. Test Plan: - `cargo fmt --manifest-path rust/cli/Cargo.toml -- --check` -- passed - `cargo clippy --manifest-path rust/cli/Cargo.toml --lib -- -D warnings` -- passed - CLI Rust tests -- 162 passed - `make -C tests -j2 test-cli-tests` -- all 41 passed - `git diff --check` -- passed --- rust/src/zstd_cli.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/rust/src/zstd_cli.rs b/rust/src/zstd_cli.rs index 047203683..5af604de9 100644 --- a/rust/src/zstd_cli.rs +++ b/rust/src/zstd_cli.rs @@ -680,7 +680,7 @@ fn program_basename(value: &OsStr) -> String { #[cfg(feature = "compression")] fn max_c_level_for_help() -> i32 { - unsafe { ZSTD_maxCLevel() } + DEFAULT_MAX_CLEVEL } #[cfg(not(feature = "compression"))] @@ -688,6 +688,16 @@ const fn max_c_level_for_help() -> i32 { 19 } +#[cfg(feature = "compression")] +fn max_c_level_for_ultra() -> i32 { + unsafe { ZSTD_maxCLevel() } +} + +#[cfg(not(feature = "compression"))] +const fn max_c_level_for_ultra() -> i32 { + 19 +} + fn write_basic_usage(out: &mut W, program_name: &str) { let max_level = max_c_level_for_help(); let _ = writeln!( @@ -830,7 +840,7 @@ fn write_advanced_usage(out: &mut W, program_name: &str) { let _ = writeln!( out, " --ultra Enable levels beyond 19, up to {}; requires more memory.", - max_c_level_for_help() + max_c_level_for_ultra() ); let _ = writeln!( out, @@ -2926,6 +2936,11 @@ mod tests { assert_eq!(cli.compression_format, CompressionFormat::Zstd); } + #[test] + fn normal_help_ceiling_excludes_ultra_levels() { + assert_eq!(max_c_level_for_help(), 19); + } + #[test] fn format_option_selects_frame_type_and_suffix() { let cli = parse(&["zstd", "--format=gzip", "input"]);