use super::{PipelineBuilder, stage::PureStage, stages::*};
use crate::core::Language;
use crate::pipeline::data::PipelineData;
use std::path::{Path, PathBuf};
pub fn example_pipeline() -> super::BuiltPipeline<String> {
PipelineBuilder::new()
.stage(PureStage::new("Initialize", |()| {
vec!["analysis", "started"]
}))
.stage(PureStage::new("Process", |words: Vec<&str>| {
words
.into_iter()
.map(|w| w.to_uppercase())
.collect::<Vec<_>>()
}))
.stage(PureStage::new("Finalize", |words: Vec<String>| {
words.join(" ")
}))
.with_progress()
.build()
}
#[deprecated(
note = "incomplete and fails closed; use `debtmap analyze` or the canonical unified analysis API"
)]
#[allow(deprecated)]
pub fn standard_pipeline(
project_path: &Path,
languages: &[Language],
coverage_file: Option<&PathBuf>,
enable_context: bool,
) -> super::BuiltPipeline<PipelineData> {
let mut builder = PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(TraitResolutionStage::new(project_path));
if let Some(coverage_path) = coverage_file {
builder = builder.stage(CoverageLoadingStage::new(coverage_path));
}
builder = builder.stage(PurityAnalysisStage::new());
if enable_context {
builder = builder.stage(ContextLoadingStage::new(project_path));
}
builder
.stage(DebtDetectionStage::new())
.stage(ScoringStage::new())
.with_progress()
.build()
}
#[deprecated(
note = "incomplete and fails closed; use `debtmap analyze` or the canonical unified analysis API"
)]
#[allow(deprecated)]
pub fn fast_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(PurityAnalysisStage::new())
.stage(DebtDetectionStage::new())
.stage(ScoringStage::new())
.with_progress()
.build()
}
#[deprecated(
note = "incomplete and fails closed; use `debtmap analyze` or the canonical unified analysis API"
)]
#[allow(deprecated)]
pub fn complexity_only_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(DebtDetectionStage::new())
.with_progress()
.build()
}
#[deprecated(
note = "incomplete and fails closed; use `debtmap analyze` or the canonical unified analysis API"
)]
#[allow(deprecated)]
pub fn call_graph_pipeline(
project_path: &Path,
languages: &[Language],
) -> super::BuiltPipeline<PipelineData> {
PipelineBuilder::new()
.stage(FileDiscoveryStage::new(project_path, languages))
.stage(ParsingStage::new())
.stage(CallGraphStage::new())
.stage(TraitResolutionStage::new(project_path))
.stage(PurityAnalysisStage::new())
.with_progress()
.build()
}
#[cfg(test)]
mod tests {
#![allow(deprecated)]
use super::*;
use std::fs;
use tempfile::TempDir;
#[test]
fn test_example_pipeline() {
let pipeline = example_pipeline();
let result = pipeline.execute().unwrap();
assert_eq!(result, "ANALYSIS STARTED");
}
#[test]
fn test_example_pipeline_with_timing() {
let pipeline = example_pipeline();
let (result, timings) = pipeline.execute_with_timing().unwrap();
assert_eq!(result, "ANALYSIS STARTED");
assert_eq!(timings.len(), 3);
assert_eq!(timings[0].name, "Initialize");
assert_eq!(timings[1].name, "Process");
assert_eq!(timings[2].name, "Finalize");
}
#[test]
fn test_standard_pipeline_builds() {
let pipeline = standard_pipeline(Path::new("."), &[Language::Rust], None, false);
assert!(pipeline.stage_count() >= 6);
}
#[test]
fn test_fast_pipeline_builds() {
let pipeline = fast_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 6);
}
#[test]
fn test_complexity_only_pipeline_builds() {
let pipeline = complexity_only_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 3);
}
#[test]
fn test_call_graph_pipeline_builds() {
let pipeline = call_graph_pipeline(Path::new("."), &[Language::Rust]);
assert_eq!(pipeline.stage_count(), 5);
}
#[test]
#[allow(deprecated)]
fn analysis_presets_fail_closed_at_parsing() {
let fixture = TempDir::new().unwrap();
fs::write(fixture.path().join("hotspot.rs"), "fn hotspot() {}").unwrap();
let pipelines = vec![
standard_pipeline(fixture.path(), &[Language::Rust], None, false),
fast_pipeline(fixture.path(), &[Language::Rust]),
complexity_only_pipeline(fixture.path(), &[Language::Rust]),
call_graph_pipeline(fixture.path(), &[Language::Rust]),
];
for pipeline in pipelines {
let error = pipeline.execute().unwrap_err().to_string();
assert!(error.contains("Failed in stage 'Parsing'"), "{error}");
assert!(error.contains("debtmap analyze"), "{error}");
}
}
}