use std::sync::Arc;
use anyhow::{Context, Result, anyhow};
use camino::Utf8PathBuf;
use cap_std::{ambient_authority, fs_utf8::Dir};
use tempfile::tempdir;
use super::{CommandConfig, CommandConfigInit};
use crate::stdlib::{DEFAULT_COMMAND_MAX_OUTPUT_BYTES, DEFAULT_COMMAND_MAX_STREAM_BYTES};
pub(super) fn test_command_config() -> Result<(tempfile::TempDir, CommandConfig)> {
let temp = tempdir().context("create command temp workspace")?;
let path = Utf8PathBuf::from_path_buf(temp.path().to_path_buf())
.map_err(|path| anyhow!("temp workspace should be valid UTF-8: {path:?}"))?;
let dir =
Dir::open_ambient_dir(&path, ambient_authority()).context("open temp workspace dir")?;
let config = CommandConfig::new(CommandConfigInit {
max_capture_bytes: DEFAULT_COMMAND_MAX_OUTPUT_BYTES,
max_stream_bytes: DEFAULT_COMMAND_MAX_STREAM_BYTES,
workspace_root: Arc::new(dir),
workspace_root_path: Some(Arc::new(path)),
command_path_override: None,
});
Ok((temp, config))
}