use release_tool::command::{CommandRequest, CommandResult, CommandRunner, SystemCommandRunner};
#[test]
fn command_debug_output_redacts_environment_values() {
let mut request = CommandRequest::new("mvn", ["deploy"], ".");
request
.environment
.insert("GITHUB_TOKEN".to_owned(), "super-secret-token".to_owned());
request
.environment
.insert("GITHUB_ACTOR".to_owned(), "release-bot".to_owned());
let debug = format!("{request:?}");
assert!(!debug.contains("super-secret-token"));
assert!(!debug.contains("release-bot"));
assert!(debug.contains("GITHUB_TOKEN"));
assert!(debug.contains("[REDACTED]"));
}
#[test]
fn command_failure_can_be_redacted_before_rendering() {
let result = CommandResult {
status: 1,
stdout: "token-value".to_owned(),
stderr: "authorization failed for token-value".to_owned(),
};
let error = result
.redact(["token-value"])
.require_success("authenticated command")
.unwrap_err();
assert!(!error.to_string().contains("token-value"));
assert!(error.to_string().contains("[REDACTED]"));
}
#[test]
fn argv_is_executed_without_shell_reinterpretation() {
let root = tempfile::tempdir().unwrap();
let marker = root.path().join("must-not-exist");
let literal = format!("$(touch {})", marker.display());
let request = CommandRequest::new(
"/usr/bin/printf",
["%s".to_owned(), literal.clone()],
root.path(),
);
let result = SystemCommandRunner.execute(&request).unwrap();
assert_eq!(result.status, 0);
assert_eq!(result.stdout, literal);
assert!(!marker.exists());
}