use anyhow::Result;
use std::path::Path;
use crate::config::Config;
use crate::shell::shell_escape;
pub fn wrap_for_lima(
command: &str,
_config: &Config,
_vm_name: &str,
working_dir: &Path,
) -> Result<String> {
let command = command.strip_prefix(' ').unwrap_or(command);
Ok(format!(
" workmux sandbox run '{}' -- '{}'",
shell_escape(&working_dir.to_string_lossy()),
shell_escape(command)
))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::sandbox::lima::LimaInstanceInfo;
#[test]
fn test_check_vm_state_running() {
let info = LimaInstanceInfo {
name: "test-vm".to_string(),
status: "Running".to_string(),
dir: None,
};
assert!(info.is_running());
}
#[test]
fn test_check_vm_state_stopped() {
let info = LimaInstanceInfo {
name: "test-vm".to_string(),
status: "Stopped".to_string(),
dir: None,
};
assert!(!info.is_running());
}
#[test]
fn test_wrap_generates_supervisor_command() {
let config = Config::default();
let result = wrap_for_lima(
"claude",
&config,
"wm-abc12345",
Path::new("/Users/test/project"),
)
.unwrap();
assert!(result.starts_with(" workmux sandbox run"));
assert!(result.contains("/Users/test/project"));
assert!(result.contains("-- 'claude'"));
}
#[test]
fn test_wrap_strips_leading_space() {
let config = Config::default();
let result = wrap_for_lima(
" claude -- \"$(cat PROMPT.md)\"",
&config,
"wm-abc12345",
Path::new("/tmp/wt"),
)
.unwrap();
assert!(result.contains("-- 'claude -- \"$(cat PROMPT.md)\"'"));
}
#[test]
fn test_wrap_with_spaces_in_path() {
let config = Config::default();
let result = wrap_for_lima(
"claude",
&config,
"wm-abc12345",
Path::new("/Users/test user/my project"),
)
.unwrap();
assert!(result.contains("test user/my project"));
assert!(result.contains("'/Users/test user/my project'"));
}
#[test]
fn test_wrap_with_complex_command() {
let config = Config::default();
let result = wrap_for_lima(
"claude --dangerously-skip-permissions -- \"$(cat .workmux/prompts/PROMPT.md)\"",
&config,
"wm-abc",
Path::new("/tmp/wt"),
)
.unwrap();
assert!(!result.contains("sh -lc"));
assert!(result.contains("claude"));
assert!(result.contains("dangerously-skip-permissions"));
}
#[test]
fn test_wrap_escapes_single_quotes_in_command() {
let config = Config::default();
let result = wrap_for_lima(
"echo 'hello world'",
&config,
"wm-abc",
Path::new("/tmp/wt"),
)
.unwrap();
assert!(result.contains("echo '\\''hello world'\\''"));
}
#[test]
fn test_env_passthrough_escaping() {
let env_var = "MY_VAR";
let val = "hello'world";
let flag = format!(" --setenv {}='{}'", env_var, shell_escape(&val));
assert_eq!(flag, " --setenv MY_VAR='hello'\\''world'");
}
}