ryo-executor 0.1.0

[experimental] Mutation execution engine for RYO - parallel execution, conflict detection, workspace management
Documentation
//! ExecutionContext: 実行時コンテキスト

use std::path::PathBuf;
use std::time::Duration;

/// 実行コンテキスト
#[derive(Debug, Clone)]
pub struct ExecutionContext {
    /// 作業ディレクトリ
    pub working_dir: PathBuf,

    /// タイムアウト
    pub timeout: Duration,

    /// 出力の最大行数
    pub max_output_lines: usize,

    /// ripgrep パス
    pub rg_path: String,

    /// fd パス
    pub fd_path: String,
}

impl ExecutionContext {
    /// 新しいコンテキストを作成
    pub fn new(working_dir: PathBuf) -> Self {
        Self {
            working_dir,
            timeout: Duration::from_secs(30),
            max_output_lines: 500,
            rg_path: "rg".to_string(),
            fd_path: "fd".to_string(),
        }
    }

    /// タイムアウトを設定
    pub fn with_timeout(mut self, timeout: Duration) -> Self {
        self.timeout = timeout;
        self
    }

    /// 最大出力行数を設定
    pub fn with_max_lines(mut self, max_lines: usize) -> Self {
        self.max_output_lines = max_lines;
        self
    }

    /// ripgrep パスを設定
    pub fn with_rg_path(mut self, path: impl Into<String>) -> Self {
        self.rg_path = path.into();
        self
    }

    /// fd パスを設定
    pub fn with_fd_path(mut self, path: impl Into<String>) -> Self {
        self.fd_path = path.into();
        self
    }

    /// パスを解決(相対パスを絶対パスに)
    pub fn resolve_path(&self, path: &str) -> PathBuf {
        let p = PathBuf::from(path);
        if p.is_absolute() {
            p
        } else {
            self.working_dir.join(p)
        }
    }
}

impl Default for ExecutionContext {
    fn default() -> Self {
        Self::new(PathBuf::from("."))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_context_creation() {
        let ctx = ExecutionContext::new(PathBuf::from("/tmp"))
            .with_timeout(Duration::from_secs(60))
            .with_max_lines(1000);

        assert_eq!(ctx.working_dir, PathBuf::from("/tmp"));
        assert_eq!(ctx.timeout, Duration::from_secs(60));
        assert_eq!(ctx.max_output_lines, 1000);
    }

    #[test]
    fn test_resolve_path() {
        let ctx = ExecutionContext::new(PathBuf::from("/home/user/project"));

        // 相対パス
        assert_eq!(
            ctx.resolve_path("src/lib.rs"),
            PathBuf::from("/home/user/project/src/lib.rs")
        );

        // 絶対パス
        assert_eq!(ctx.resolve_path("/etc/hosts"), PathBuf::from("/etc/hosts"));
    }
}