Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/cli_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::path::PathBuf;

// The `run` subcommand previously had a description "Run agent locally" when
// it was an internal developer tool. It now queues ADO builds ("Queue a build
// for every ADO definition…"). This test guards against that old description
// being reinstated.
#[test]
fn test_run_subcommand_not_present() {
fn test_run_agent_locally_description_absent() {
let binary_path = PathBuf::from(env!("CARGO_BIN_EXE_ado-aw"));
let output = std::process::Command::new(&binary_path)
.arg("--help")
Expand All @@ -12,6 +16,7 @@ fn test_run_subcommand_not_present() {
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("Run agent locally"),
"Help output should not include a run subcommand, got:\n{stdout}"
"Help output should not contain the old 'Run agent locally' description; \
the run subcommand now queues ADO builds. Got:\n{stdout}"
);
}
44 changes: 19 additions & 25 deletions tests/init_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,31 @@ fn test_init_overwrites_by_default() {
);
}

/// Test that `init --force` also overwrites an existing agent file
/// Test that `--force` is advertised in `init --help` and describes its
/// actual purpose: bypassing the GitHub-remote guard so maintainers can run
/// `ado-aw init` inside a GitHub-hosted fork of `ado-aw` itself.
///
/// NOTE: `--force` has nothing to do with overwriting (init always overwrites).
/// It skips `ensure_non_github_remote_for_ado_aw`. We cannot trigger that
/// guard from within a `cargo test` run because `CARGO_BIN_EXE_ado-aw` being
/// set already bypasses it, so the meaningful check is the CLI surface test.
#[test]
fn test_init_force_overwrites() {
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");

// First run
fn test_init_force_flag_is_advertised_in_help() {
let output = ado_aw_bin()
.args(["init", "--path", temp_dir.path().to_str().unwrap()])
.args(["init", "--help"])
.output()
.expect("Failed to run ado-aw init");
assert!(output.status.success(), "First init should succeed");
.expect("Failed to run ado-aw init --help");
assert!(output.status.success(), "init --help should exit 0");

let agent_path = temp_dir.path().join(".github/agents/ado-aw.agent.md");

// Tamper with the file
fs::write(&agent_path, "tampered content").expect("Should write tampered content");

// Re-run with --force should succeed and restore the template
let output = ado_aw_bin()
.args(["init", "--path", temp_dir.path().to_str().unwrap(), "--force"])
.output()
.expect("Failed to run ado-aw init --force");
assert!(output.status.success(), "Init with --force should succeed");

let content = fs::read_to_string(&agent_path).expect("Should read agent file");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
content.contains("ADO Agentic Pipelines Agent"),
"Force should restore the template content"
stdout.contains("--force"),
"init --help should document the --force flag, got:\n{stdout}"
);
// The help text must explain the flag's purpose (GitHub-remote guard bypass),
// not merely say it exists.
assert!(
!content.contains("tampered"),
"Tampered content should be overwritten"
stdout.contains("GitHub") || stdout.contains("bypass"),
"init --help should explain that --force bypasses the GitHub-remote guard, got:\n{stdout}"
);
}