mod analysis;
mod io;
mod messages;
mod scoring;
pub mod types;
pub use types::{AnalysisSummary, CompareConfig, DebtmapJsonInput, GapDetail, ValidationResult};
use analysis::{create_summary, identify_all_changes};
use anyhow::Result;
use io::{load_both_debtmaps, print_summary, read_automation_mode, write_validation_result};
use messages::{build_all_gaps, build_all_improvement_messages, build_all_issue_messages};
use scoring::{calculate_improvement_score, determine_status};
use types::DebtmapJsonInput as Input;
pub fn compare_debtmaps(config: CompareConfig) -> Result<()> {
let is_automation = read_automation_mode();
if !is_automation {
println!("Loading debtmap data from before and after states...");
}
let (before, after) = load_both_debtmaps(&config)?;
let result = perform_validation(&before, &after)?;
write_validation_result(&config.output_path, &result)?;
if !is_automation {
print_summary(&result);
}
Ok(())
}
fn perform_validation(before: &Input, after: &Input) -> Result<ValidationResult> {
let before_summary = create_summary(before);
let after_summary = create_summary(after);
let changes = identify_all_changes(before, after);
let improvements = build_all_improvement_messages(&changes.resolved, &changes.improved);
let remaining_issues =
build_all_issue_messages(&changes.unchanged_critical, &changes.new_items);
let gaps = build_all_gaps(&changes.unchanged_critical, &changes.new_items);
let completion = calculate_improvement_score(
&changes.resolved,
&changes.improved,
&changes.new_items,
&changes.unchanged_critical,
&before_summary,
&after_summary,
);
let status = determine_status(
completion,
&changes.new_items,
&before_summary,
&after_summary,
);
Ok(ValidationResult {
completion_percentage: completion,
status,
improvements,
remaining_issues,
gaps,
before_summary,
after_summary,
})
}
#[cfg(test)]
mod tests;