#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::needless_raw_string_hashes,
clippy::duration_suboptimal_units,
clippy::branches_sharing_code,
clippy::used_underscore_binding,
clippy::single_char_pattern,
clippy::ignore_without_reason,
clippy::cloned_ref_to_slice_refs,
clippy::doc_overindented_list_items,
clippy::match_wildcard_for_single_variants,
clippy::ignored_unit_patterns,
clippy::needless_collect,
clippy::unnecessary_map_or,
clippy::manual_flatten,
clippy::manual_strip,
clippy::future_not_send,
clippy::unnested_or_patterns,
clippy::no_effect_underscore_binding,
clippy::literal_string_with_formatting_args
)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
fn ggen() -> Command {
Command::cargo_bin("ggen").expect("Failed to find ggen binary")
}
fn create_test_workflow(temp_dir: &TempDir) -> std::path::PathBuf {
let workflow_file = temp_dir.path().join("workflow.json");
let workflow_content = r#"{
"workflow_name": "test-workflow",
"events": [
{
"case_id": "case-1",
"activity": "Start",
"timestamp": "2024-01-01T00:00:00Z"
},
{
"case_id": "case-1",
"activity": "Process",
"timestamp": "2024-01-01T01:00:00Z"
}
]
}"#;
fs::write(&workflow_file, workflow_content).expect("Failed to write workflow file");
workflow_file
}
#[test]
#[ignore]
fn test_workflow_init_creates_workflow() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("workflow")
.arg("init")
.arg("--name")
.arg("test-workflow")
.current_dir(&temp_dir)
.assert()
.success();
let workflow_path = temp_dir.path().join(".workflows/test-workflow.json");
assert!(workflow_path.exists(), "Workflow file should be created");
}
#[test]
#[ignore]
fn test_workflow_init_with_type() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("workflow")
.arg("init")
.arg("--name")
.arg("research-workflow")
.arg("--type")
.arg("research")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_init_with_output_dir() {
let temp_dir = TempDir::new().unwrap();
let output_dir = temp_dir.path().join("custom-workflows");
ggen()
.arg("workflow")
.arg("init")
.arg("--name")
.arg("custom-workflow")
.arg("--output-dir")
.arg(output_dir.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
assert!(
output_dir.exists(),
"Custom output directory should be created"
);
}
#[test]
#[ignore]
fn test_workflow_analyze() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("analyze")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("cases")
.or(predicate::str::contains("events"))
.or(predicate::str::contains("workflow")),
);
}
#[test]
#[ignore]
fn test_workflow_analyze_summary() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("analyze")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--summary")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_discover() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("discover")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("graph")
.or(predicate::str::contains("edges"))
.or(predicate::str::contains("path")),
);
}
#[test]
#[ignore]
fn test_workflow_discover_pareto() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("discover")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--pareto")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_discover_export_mermaid() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("discover")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--export")
.arg("mermaid")
.current_dir(&temp_dir)
.assert()
.success()
.stdout(predicate::str::contains("graph").or(predicate::str::contains("mermaid")));
}
#[test]
#[ignore]
fn test_workflow_event() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("event")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--case-id")
.arg("case-2")
.arg("--activity")
.arg("Complete")
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("Event recorded").or(predicate::str::contains("timestamp")),
);
}
#[test]
#[ignore]
fn test_workflow_event_with_resource() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("event")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--case-id")
.arg("case-3")
.arg("--activity")
.arg("Review")
.arg("--resource")
.arg("reviewer-1")
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_report() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
ggen()
.arg("workflow")
.arg("report")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success()
.stdout(
predicate::str::contains("Report generated").or(predicate::str::contains("status")),
);
}
#[test]
#[ignore]
fn test_workflow_report_html_format() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
let output_file = temp_dir.path().join("report.html");
ggen()
.arg("workflow")
.arg("report")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--format")
.arg("html")
.arg("--output")
.arg(output_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_report_json_format() {
let temp_dir = TempDir::new().unwrap();
let workflow_file = create_test_workflow(&temp_dir);
let output_file = temp_dir.path().join("report.json");
ggen()
.arg("workflow")
.arg("report")
.arg("--workflow-file")
.arg(workflow_file.to_str().unwrap())
.arg("--format")
.arg("json")
.arg("--output")
.arg(output_file.to_str().unwrap())
.current_dir(&temp_dir)
.assert()
.success();
}
#[test]
#[ignore]
fn test_workflow_help_shows_verbs() {
ggen()
.arg("workflow")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("init"))
.stdout(predicate::str::contains("analyze"))
.stdout(predicate::str::contains("discover"))
.stdout(predicate::str::contains("event"))
.stdout(predicate::str::contains("report"));
}
#[test]
#[ignore]
fn test_workflow_invalid_verb() {
ggen()
.arg("workflow")
.arg("invalid-verb")
.assert()
.failure()
.stderr(predicate::str::contains("error").or(predicate::str::contains("invalid")));
}
#[test]
#[ignore]
fn test_workflow_analyze_missing_file() {
let temp_dir = TempDir::new().unwrap();
ggen()
.arg("workflow")
.arg("analyze")
.arg("--workflow-file")
.arg("/nonexistent/workflow.json")
.current_dir(&temp_dir)
.assert()
.failure()
.stderr(predicate::str::contains("not found").or(predicate::str::contains("error")));
}