pmat 3.15.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
    #[test]
    fn test_roadmap_command_parsing() {
        // Test CLI parsing for RoadmapCommand
        let cmd = RoadmapCommand::try_parse_from([
            "roadmap",
            "init",
            "--version",
            "v1.0.0",
            "--title",
            "Test Sprint",
            "--duration-days",
            "7",
            "--priority",
            "P0",
        ]);

        assert!(cmd.is_ok());
        if let Ok(parsed) = cmd {
            match parsed.command {
                RoadmapSubcommand::Init {
                    version,
                    title,
                    duration_days,
                    priority,
                } => {
                    assert_eq!(version, "v1.0.0");
                    assert_eq!(title, "Test Sprint");
                    assert_eq!(duration_days, 7);
                    assert_eq!(priority, "P0");
                }
                _ => panic!("Expected Init subcommand"),
            }
        }
    }

    #[test]
    fn test_handle_init_command() {
        let temp_dir = TempDir::new().unwrap();
        let roadmap_path = temp_dir.path().join("roadmap.md");

        let result = handle_init(
            "v2.0.0".to_string(),
            "Test Initiative".to_string(),
            14,
            "P1".to_string(),
            roadmap_path.clone(),
        );

        assert!(result.is_ok());
        assert!(roadmap_path.exists());

        let content = fs::read_to_string(&roadmap_path).unwrap();
        assert!(content.contains("v2.0.0"));
        assert!(content.contains("Test Initiative"));
        assert!(content.contains("P1"));
    }

    #[test]
    fn test_handle_init_invalid_priority() {
        let temp_dir = TempDir::new().unwrap();
        let roadmap_path = temp_dir.path().join("roadmap.md");

        let result = handle_init(
            "v1.0.0".to_string(),
            "Test".to_string(),
            14,
            "INVALID_PRIORITY".to_string(),
            roadmap_path,
        );

        assert!(result.is_err());
    }

    #[test]
    fn test_todos_subcommand_parsing() {
        let cmd = RoadmapCommand::try_parse_from([
            "roadmap",
            "todos",
            "--sprint",
            "v1.0.0",
            "--output",
            "custom_todos.md",
            "--include-quality-gates",
        ]);

        assert!(cmd.is_ok());
        if let Ok(parsed) = cmd {
            match parsed.command {
                RoadmapSubcommand::Todos {
                    sprint,
                    output,
                    include_quality_gates,
                } => {
                    assert_eq!(sprint, Some("v1.0.0".to_string()));
                    assert_eq!(output, PathBuf::from("custom_todos.md"));
                    assert!(include_quality_gates);
                }
                _ => panic!("Expected Todos subcommand"),
            }
        }
    }

    #[test]
    fn test_start_subcommand_parsing() {
        let cmd =
            RoadmapCommand::try_parse_from(["roadmap", "start", "PMAT-1001", "--create-branch"]);

        assert!(cmd.is_ok());
        if let Ok(parsed) = cmd {
            match parsed.command {
                RoadmapSubcommand::Start {
                    task_id,
                    create_branch,
                } => {
                    assert_eq!(task_id, "PMAT-1001");
                    assert!(create_branch);
                }
                _ => panic!("Expected Start subcommand"),
            }
        }
    }

    #[test]
    fn test_complete_subcommand_parsing() {
        let cmd = RoadmapCommand::try_parse_from([
            "roadmap",
            "complete",
            "PMAT-1001",
            "--skip-quality-check",
        ]);

        assert!(cmd.is_ok());
        if let Ok(parsed) = cmd {
            match parsed.command {
                RoadmapSubcommand::Complete {
                    task_id,
                    skip_quality_check,
                } => {
                    assert_eq!(task_id, "PMAT-1001");
                    assert!(skip_quality_check);
                }
                _ => panic!("Expected Complete subcommand"),
            }
        }
    }

    #[test]
    fn test_priority_from_str() {
        assert_eq!(Priority::from_str("P0").unwrap(), Priority::P0);
        assert_eq!(Priority::from_str("P1").unwrap(), Priority::P1);
        assert_eq!(Priority::from_str("P2").unwrap(), Priority::P2);
        assert!(Priority::from_str("INVALID").is_err());
    }

    #[test]
    fn test_handle_start_task() {
        let result = handle_start("PMAT-1001".to_string(), false);

        // Should complete without error for valid task ID format
        assert!(result.is_ok());
    }

    #[test]
    fn test_handle_start_task_with_branch() {
        let result = handle_start("PMAT-2001".to_string(), true);

        // Should attempt to create branch (may fail in test environment)
        // This tests the branch creation code path
        assert!(result.is_ok() || result.is_err()); // Either outcome acceptable in test
    }