Skip to content

Commit 0ab1330

Browse files
committed
fix: validate compact log retention range
1 parent 7954d02 commit 0ab1330

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/cortex-cli/src/compact_cmd.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ pub struct CompactConfigArgs {
119119
#[arg(long)]
120120
pub interval_hours: Option<u64>,
121121

122-
/// Set log retention period in days
123-
#[arg(long)]
122+
/// Set log retention period in days (1-3650)
123+
#[arg(long, value_parser = clap::value_parser!(u32).range(1..=3650))]
124124
pub log_retention_days: Option<u32>,
125125

126126
/// Output current config as JSON
@@ -1066,4 +1066,25 @@ mod tests {
10661066
"default session_days should be 0 (keep all)"
10671067
);
10681068
}
1069+
1070+
#[test]
1071+
fn test_compact_config_log_retention_accepts_documented_range() {
1072+
let cli = CompactCli::try_parse_from(["compact", "config", "--log-retention-days", "3650"])
1073+
.expect("3650 days is the documented upper bound");
1074+
1075+
match cli.subcommand {
1076+
Some(CompactSubcommand::Config(args)) => {
1077+
assert_eq!(args.log_retention_days, Some(3650));
1078+
}
1079+
_ => panic!("expected compact config subcommand"),
1080+
}
1081+
}
1082+
1083+
#[test]
1084+
fn test_compact_config_log_retention_rejects_zero() {
1085+
let err = CompactCli::try_parse_from(["compact", "config", "--log-retention-days", "0"])
1086+
.expect_err("zero days is outside the documented 1-3650 range");
1087+
1088+
assert_eq!(err.kind(), clap::error::ErrorKind::ValueValidation);
1089+
}
10691090
}

0 commit comments

Comments
 (0)