diff --git a/tests/cli_tests.rs b/tests/cli_tests.rs index ac24387f..49af7df9 100644 --- a/tests/cli_tests.rs +++ b/tests/cli_tests.rs @@ -20,3 +20,44 @@ fn test_run_agent_locally_description_absent() { the run subcommand now queues ADO builds. Got:\n{stdout}" ); } + +/// Guard that lifecycle subcommands (`list`, `disable`, `remove`, `status`) each +/// appear as a named entry in the top-level Commands section of `ado-aw --help`. +/// +/// Checking only within the Commands section (between "Commands:" and "Options:") +/// prevents false-positives from description prose that incidentally contains +/// one of these common words. +/// +/// This replaces four per-file one-word `stdout.contains()` tests that +/// unnecessarily spawned `ado-aw --help` four times and made no attempt to +/// isolate the Commands section. +#[test] +fn test_lifecycle_subcommands_appear_in_top_level_help_commands_section() { + let binary_path = PathBuf::from(env!("CARGO_BIN_EXE_ado-aw")); + let output = std::process::Command::new(&binary_path) + .arg("--help") + .output() + .expect("Failed to run ado-aw --help"); + + assert!(output.status.success(), "--help should succeed"); + let stdout = String::from_utf8_lossy(&output.stdout); + let lower = stdout.to_lowercase(); + + let commands_start = lower + .find("commands:") + .expect("top-level --help should contain a 'Commands:' section"); + let options_start = lower + .find("options:") + .expect("top-level --help should contain an 'Options:' section"); + let commands_block = &lower[commands_start..options_start]; + + for cmd in ["list", "disable", "remove", "status"] { + // Each lifecycle subcommand must appear as a command-line entry + // (indented two spaces before the name) in the Commands section. + assert!( + commands_block.contains(&format!(" {cmd}")), + "Expected '{cmd}' to be listed in the Commands section of `ado-aw --help`; \ + commands block was:\n{commands_block}" + ); + } +} diff --git a/tests/disable_integration.rs b/tests/disable_integration.rs index 46b89e8e..1a8b6431 100644 --- a/tests/disable_integration.rs +++ b/tests/disable_integration.rs @@ -31,17 +31,3 @@ fn disable_help_describes_command() { ); } } - -#[test] -fn disable_is_listed_in_top_level_help() { - let output = std::process::Command::new(binary()) - .arg("--help") - .output() - .expect("Failed to run ado-aw --help"); - assert!(output.status.success(), "--help should exit 0"); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!( - stdout.contains("disable"), - "Top-level --help should mention the disable subcommand, got:\n{stdout}" - ); -} diff --git a/tests/list_integration.rs b/tests/list_integration.rs index 90275da8..3b053e70 100644 --- a/tests/list_integration.rs +++ b/tests/list_integration.rs @@ -25,17 +25,3 @@ fn list_help_describes_command() { ); } } - -#[test] -fn list_is_in_top_level_help() { - let output = std::process::Command::new(binary()) - .arg("--help") - .output() - .expect("Failed to run ado-aw --help"); - assert!(output.status.success(), "--help should exit 0"); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!( - stdout.contains("list"), - "Top-level --help should mention the list subcommand, got:\n{stdout}" - ); -} diff --git a/tests/remove_integration.rs b/tests/remove_integration.rs index 3fff6e5c..3fa2ccfb 100644 --- a/tests/remove_integration.rs +++ b/tests/remove_integration.rs @@ -25,17 +25,3 @@ fn remove_help_describes_command() { ); } } - -#[test] -fn remove_is_listed_in_top_level_help() { - let output = std::process::Command::new(binary()) - .arg("--help") - .output() - .expect("Failed to run ado-aw --help"); - assert!(output.status.success(), "--help should exit 0"); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!( - stdout.contains("remove"), - "Top-level --help should mention the remove subcommand, got:\n{stdout}" - ); -} diff --git a/tests/status_integration.rs b/tests/status_integration.rs index 2a362bbf..5dd94947 100644 --- a/tests/status_integration.rs +++ b/tests/status_integration.rs @@ -25,17 +25,3 @@ fn status_help_describes_command() { ); } } - -#[test] -fn status_is_in_top_level_help() { - let output = std::process::Command::new(binary()) - .arg("--help") - .output() - .expect("Failed to run ado-aw --help"); - assert!(output.status.success(), "--help should exit 0"); - let stdout = String::from_utf8_lossy(&output.stdout); - assert!( - stdout.contains("status"), - "Top-level --help should mention the status subcommand, got:\n{stdout}" - ); -}