pub fn run_command_required_kind() -> &'static str {
"run_command_required"
}
pub fn run_command_required_summary() -> &'static str {
"Usage: heddle run --thread <name> -- <cmd...>"
}
pub fn run_command_required_hint() -> &'static str {
"Pass a command after `--` so Heddle knows what to execute in the thread checkout."
}
pub fn run_command_required_example() -> &'static str {
"heddle run --thread <name> -- <cmd...>"
}
pub fn plan_run_command_empty(command_empty: bool) -> bool {
command_empty
}
pub fn run_failure_message(program: &str, thread_id: &str, status_code: Option<i32>) -> String {
let status = status_code
.map(|code| code.to_string())
.unwrap_or_else(|| "signal".to_string());
format!("Command '{program}' failed in thread '{thread_id}' with status {status}")
}
pub fn transport_token(kind: &str) -> &str {
match kind {
"spool" | "direct" | "end" => kind,
other => other,
}
}
pub fn transcript_token(kind: &str) -> &str {
match kind {
"off" | "summary" | "full" => kind,
other => other,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_command_gate_and_tokens() {
assert!(plan_run_command_empty(true));
assert!(!plan_run_command_empty(false));
assert_eq!(run_command_required_kind(), "run_command_required");
assert!(run_command_required_summary().contains("heddle run"));
assert!(!run_command_required_hint().is_empty());
assert_eq!(
run_command_required_example(),
"heddle run --thread <name> -- <cmd...>"
);
}
#[test]
fn failure_message() {
assert_eq!(
run_failure_message("cargo", "agent-1", Some(1)),
"Command 'cargo' failed in thread 'agent-1' with status 1"
);
assert_eq!(
run_failure_message("sh", "t", None),
"Command 'sh' failed in thread 't' with status signal"
);
}
#[test]
fn transport_and_transcript_tokens() {
assert_eq!(transport_token("spool"), "spool");
assert_eq!(transport_token("direct"), "direct");
assert_eq!(transport_token("end"), "end");
assert_eq!(transport_token("custom"), "custom");
assert_eq!(transcript_token("off"), "off");
assert_eq!(transcript_token("summary"), "summary");
assert_eq!(transcript_token("full"), "full");
}
}