From de64f5f0077d67eae73da1809549c5c967736553 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 18 Sep 2025 16:07:38 -0700 Subject: [PATCH] fix: update try_parse_word_only_commands_sequence() to return commands in order (#3881) Incidentally, we had a test for this in `accepts_multiple_commands_with_allowed_operators()`, but it was verifying the bad behavior. Oops! --- codex-rs/core/src/bash.rs | 9 ++++++--- codex-rs/core/src/parse_command.rs | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/bash.rs b/codex-rs/core/src/bash.rs index 5b94daf2..4bed3a9c 100644 --- a/codex-rs/core/src/bash.rs +++ b/codex-rs/core/src/bash.rs @@ -73,6 +73,9 @@ pub fn try_parse_word_only_commands_sequence(tree: &Tree, src: &str) -> Option> = vec![ - vec!["wc".to_string(), "-l".to_string()], - vec!["echo".to_string(), "hi there".to_string()], - vec!["pwd".to_string()], vec!["ls".to_string()], + vec!["pwd".to_string()], + vec!["echo".to_string(), "hi there".to_string()], + vec!["wc".to_string(), "-l".to_string()], ]; assert_eq!(cmds, expected); } diff --git a/codex-rs/core/src/parse_command.rs b/codex-rs/core/src/parse_command.rs index ea886d61..1d2948a4 100644 --- a/codex-rs/core/src/parse_command.rs +++ b/codex-rs/core/src/parse_command.rs @@ -1156,10 +1156,8 @@ fn parse_bash_lc_commands(original: &[String]) -> Option> { // bias toward the primary command when pipelines are present. // First, drop obvious small formatting helpers (e.g., wc/awk/etc). let had_multiple_commands = all_commands.len() > 1; - // The bash AST walker yields commands in right-to-left order for - // connector/pipeline sequences. Reverse to reflect actual execution order. - let mut filtered_commands = drop_small_formatting_commands(all_commands); - filtered_commands.reverse(); + // Commands arrive in source order; drop formatting helpers while preserving it. + let filtered_commands = drop_small_formatting_commands(all_commands); if filtered_commands.is_empty() { return Some(vec![ParsedCommand::Unknown { cmd: script.clone(),