Files
codex/codex-rs/tui/src/chatwidget/slash_command_args_tests.rs
T
Felipe Coury 141bf7680d Add session-only arguments to /title and /statusline (#54387)
## What changed

Allow inline item selection, such as `/title model reasoning` and `/statusline current-dir --no-colors`, without changing saved defaults. Support `--clear` for both commands and `--colors` or `--no-colors` for `/statusline`, including color-only updates that preserve the current items.

Carry overrides with per-thread input state across navigation and reconnects, and allow these local commands in parent-owned subagent threads. Reject invalid or conflicting arguments before applying changes. Saved editor selections supersede the corresponding overrides.

## Testing

Add coverage for argument parsing, atomic updates, rate-limit item aliases and ambiguity, thread-state restoration, saved-setting interactions, and local command submission in parent-owned threads.

GitOrigin-RevId: 909cc2ede026fbf5c7f9cd52c8cf2ae835084f14
2026-10-15 19:11:32 +00:00

74 lines
2.2 KiB
Rust

use super::*;
use pretty_assertions::assert_eq;
#[test]
fn parses_positional_values_switches_and_quoted_arguments() {
let parsed = parse(
"'team review' item --reviewer user --speed=fast --clear --no-colors -- --literal",
&["--reviewer", "--speed"],
&["--clear"],
&["colors"],
)
.expect("valid command arguments");
assert_eq!(
parsed,
ParsedCommandArgs {
positionals: vec!["team review".into(), "item".into(), "--literal".into()],
named: vec![
NamedArgument {
name: "--reviewer".into(),
value: NamedArgumentValue::Value("user".into()),
},
NamedArgument {
name: "--speed".into(),
value: NamedArgumentValue::Value("fast".into()),
},
NamedArgument {
name: "--clear".into(),
value: NamedArgumentValue::Switch,
},
NamedArgument {
name: "--colors".into(),
value: NamedArgumentValue::Boolean { value: false },
},
],
}
);
assert_eq!(parsed.value("--reviewer"), Some("user"));
assert!(parsed.has_switch("--clear"));
assert_eq!(parsed.boolean("colors"), Some(false));
}
#[test]
fn rejects_invalid_named_arguments() {
for (args, expected) in [
(
"--reviewer",
"Command setting `--reviewer` requires a value.",
),
(
"--clear=yes",
"Command setting `--clear` does not take a value.",
),
(
"--clear --clear",
"Command setting `--clear` was provided more than once.",
),
(
"--colors --no-colors",
"Specify only one of --colors or --no-colors.",
),
("--unknown", "Unknown command setting `--unknown`."),
(
"'unfinished",
"Invalid command arguments. Check the quoting.",
),
] {
assert_eq!(
parse(args, &["--reviewer"], &["--clear"], &["colors"]),
Err(expected.to_string())
);
}
}