use crate::config::OrchestratorConfig;
use crate::error::Result;
use crate::worktree_ops::ObservationRequest;
use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
pub fn should_trigger_worktree_command(config: &OrchestratorConfig, is_git_repo: bool) -> bool {
config.get_worktree_command().is_some() && is_git_repo
}
pub fn build_worktree_path(base_dir: &Path) -> PathBuf {
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|_| Duration::from_secs(0))
.as_millis();
base_dir.join(format!("proposal-{}", timestamp))
}
pub async fn load_worktrees_with_conflict_check(
repo_root: &Path,
) -> Result<Vec<super::types::WorktreeInfo>> {
crate::worktree_ops::get_worktrees(repo_root, ObservationRequest::Periodic).await
}
#[cfg(test)]
mod tests {
use super::*;
use crate::config::OrchestratorConfig;
#[test]
fn test_should_trigger_worktree_command_missing_config() {
let config = OrchestratorConfig::default();
assert!(!should_trigger_worktree_command(&config, true));
}
#[test]
fn test_should_trigger_worktree_command_not_git_repo() {
let config = OrchestratorConfig {
worktree_command: Some("cmd {workspace_dir}".to_string()),
..Default::default()
};
assert!(!should_trigger_worktree_command(&config, false));
}
#[test]
fn test_should_trigger_worktree_command_enabled() {
let config = OrchestratorConfig {
worktree_command: Some("cmd {repo_root}".to_string()),
..Default::default()
};
assert!(should_trigger_worktree_command(&config, true));
}
}