ai-dispatch 10.47.0

Multi-AI CLI team orchestrator
// Batch regression cases relocated to keep test modules bounded.
// Deps: shared fixtures and imports from the parent test module.
use super::*;

#[test]
fn task_to_run_args_defaults_dry_run_to_false() {
    let _guard = isolated_home();
    let store = Arc::new(Store::open_memory().unwrap());
    let run_args = task_to_run_args(
        &batch::BatchTask {
            id: None,
            name: None,
            agent: "codex".to_string(),
            team: None,
            prompt: "test".to_string(),
            prompt_file: None,
            dir: None,
            output: None,
            result_file: None,
            model: None,
            worktree: None,
            group: None,
            container: None, remote_build: None,
            verify: None,
            setup: None,
            judge: None,
            peer_review: None,
            max_duration_mins: None,
            max_wait_mins: None,
            retry: None,
            iterate: None,
            eval: None,
            eval_feedback_template: None,
            idle_timeout: None,
            best_of: None,
            metric: None,
            context: None,
            checklist: None,
            skills: None,
            on_done: None,
            hooks: None,
            depends_on: None,
            parent: None,
            context_from: None,
            fallback: None,
            scope: None,
            read_only: false,
            sandbox: false,
            no_skill: false,
            difficulty: None, budget: None, urgency: None, rigor: None, egress: None, kind: None,
            audit: None,
            env: None,
            env_forward: None,
            worktree_link_deps: None,
            on_success: None,
            on_fail: None,
            conditional: false,
        },
        &[],
        false,
        &store,
        None,
    );

    assert!(!run_args.dry_run);
}

#[test]
fn task_to_run_args_includes_sibling_metadata() {
    let _guard = isolated_home();
    let store = Arc::new(Store::open_memory().unwrap());
    let current = batch::BatchTask {
        id: Some("task-current".to_string()),
        name: Some("current".to_string()),
        agent: "codex".to_string(),
        team: None,
        prompt: "implement the feature".to_string(),
        prompt_file: None,
        dir: None,
        output: None,
        result_file: None,
        model: None,
        worktree: None,
        group: None,
        container: None, remote_build: None,
        verify: None,
        setup: None,
        judge: None,
        peer_review: None,
        max_duration_mins: None,
        max_wait_mins: None,
        retry: None,
        iterate: None,
        eval: None,
        eval_feedback_template: None,
        idle_timeout: None,
        best_of: None,
        metric: None,
        context: None,
        checklist: None,
        skills: None,
        on_done: None,
        hooks: None,
        depends_on: None,
        parent: None,
        context_from: None,
        fallback: None,
        scope: None,
        read_only: false,
        sandbox: false,
        no_skill: false,
            difficulty: None, budget: None, urgency: None, rigor: None, egress: None, kind: None,
        audit: None,
        env: None,
        env_forward: None,
        worktree_link_deps: None,
        on_success: None,
        on_fail: None,
        conditional: false,
    };
    let sibling = batch::BatchTask {
        id: Some("task-sibling".to_string()),
        name: Some("sibling".to_string()),
        agent: "gemini".to_string(),
        team: None,
        prompt: "review the implementation".to_string(),
        prompt_file: None,
        dir: None,
        output: None,
        result_file: None,
        model: None,
        worktree: None,
        group: None,
        container: None, remote_build: None,
        verify: None,
        setup: None,
        judge: None,
        peer_review: None,
        max_duration_mins: None,
        max_wait_mins: None,
        retry: None,
        iterate: None,
        eval: None,
        eval_feedback_template: None,
        idle_timeout: None,
        best_of: None,
        metric: None,
        context: None,
        checklist: None,
        skills: None,
        on_done: None,
        hooks: None,
        depends_on: None,
        parent: None,
        context_from: None,
        fallback: None,
        scope: None,
        read_only: false,
        sandbox: false,
        no_skill: false,
            difficulty: None, budget: None, urgency: None, rigor: None, egress: None, kind: None,
        audit: None,
        env: None,
        env_forward: None,
        worktree_link_deps: None,
        on_success: None,
        on_fail: None,
        conditional: false,
    };

    let run_args = task_to_run_args(&current, &[&sibling], true, &store, None);

    assert_eq!(
        run_args.batch_siblings,
        vec![(
            "sibling".to_string(),
            "gemini".to_string(),
            "review the implementation".to_string(),
        )]
    );
}

#[test]
fn task_to_run_args_applies_forwarded_env_after_explicit_env() {
    let _guard = isolated_home();
    let store = Arc::new(Store::open_memory().unwrap());
    let forwarded_path = std::env::var("PATH").unwrap();
    let run_args = task_to_run_args(
        &batch::BatchTask {
            id: None,
            name: None,
            agent: "codex".to_string(),
            team: None,
            prompt: "test".to_string(),
            prompt_file: None,
            dir: None,
            output: None,
            result_file: None,
            model: None,
            worktree: None,
            group: None,
            container: None, remote_build: None,
            verify: None,
            setup: None,
            judge: None,
            peer_review: None,
            max_duration_mins: None,
            max_wait_mins: None,
            retry: None,
            iterate: None,
            eval: None,
            eval_feedback_template: None,
            idle_timeout: None,
            best_of: None,
            metric: None,
            context: None,
            checklist: None,
            skills: None,
            on_done: None,
            hooks: None,
            depends_on: None,
            parent: None,
            context_from: None,
            fallback: None,
            scope: None,
            read_only: false,
            sandbox: false,
            no_skill: false,
            difficulty: None, budget: None, urgency: None, rigor: None, egress: None, kind: None,
            audit: None,
            env: Some([("PATH".to_string(), "explicit".to_string())].into_iter().collect()),
            env_forward: Some(vec!["PATH".to_string()]),
            worktree_link_deps: None,
            on_success: None,
            on_fail: None,
            conditional: false,
        },
        &[],
        true,
        &store,
        None,
    );

    assert_eq!(
        run_args.env.as_ref().and_then(|env| env.get("PATH")).map(String::as_str),
        Some(forwarded_path.as_str())
    );
    assert_eq!(run_args.env_forward, Some(vec!["PATH".to_string()]));
}