task-mcp 0.5.0

MCP server for task runner integration — Agent-safe harness for defined tasks
Documentation
#![allow(dead_code)]

use std::io::Write as _;
use std::path::{Path, PathBuf};

use tempfile::TempDir;

/// Shared test harness for integration and E2E tests.
///
/// `TempProject` owns temporary directories for the project and (optionally)
/// the global justfile.  Both directories are cleaned up when the struct is
/// dropped.
pub struct TempProject {
    pub project_dir: TempDir,
    pub global_dir: Option<TempDir>,
}

impl TempProject {
    /// Create a TempProject with a project directory only (no global justfile).
    pub fn new() -> Self {
        let project_dir = tempfile::tempdir().expect("create temp project dir");
        Self {
            project_dir,
            global_dir: None,
        }
    }

    /// Create a TempProject with both a project directory and a global justfile
    /// pre-populated with `content`.
    pub fn with_global_recipes(content: &str) -> Self {
        let project_dir = tempfile::tempdir().expect("create temp project dir");
        let global_dir = tempfile::tempdir().expect("create temp global dir");

        let global_justfile = global_dir.path().join("justfile");
        let mut f = std::fs::File::create(&global_justfile).expect("create global justfile");
        f.write_all(content.as_bytes())
            .expect("write global justfile content");

        Self {
            project_dir,
            global_dir: Some(global_dir),
        }
    }

    /// Write content to `{project_dir}/justfile`.
    pub fn write_project_justfile(&self, content: &str) {
        let path = self.project_justfile();
        let mut f = std::fs::File::create(&path).expect("create project justfile");
        f.write_all(content.as_bytes())
            .expect("write project justfile content");
    }

    /// Return the path to the project directory.
    pub fn project_path(&self) -> &Path {
        self.project_dir.path()
    }

    /// Return the path to `{project_dir}/justfile`.
    pub fn project_justfile(&self) -> PathBuf {
        self.project_dir.path().join("justfile")
    }

    /// Return the path to the global justfile, if one was created.
    pub fn global_justfile(&self) -> Option<PathBuf> {
        self.global_dir.as_ref().map(|d| d.path().join("justfile"))
    }
}