weavatrix-refactor-plan 0.1.0

Evidence metadata, validation profiles, and canonical fingerprints for Weavatrix refactor plans
Documentation
use crate::{BorrowedFileEdit, PlanError, PlanLimits, RefactorPlanLimits, validate_file_edits};

pub(super) fn validate_edits(
    operation: &str,
    files: &[BorrowedFileEdit<'_>],
    operation_indices: &[usize],
    limits: RefactorPlanLimits,
) -> Result<(usize, usize), PlanError> {
    if files.is_empty() {
        return Ok((0, 0));
    }
    let checked = validate_file_edits(
        operation,
        files,
        PlanLimits {
            max_files: limits.max_operations,
            max_edits_per_file: limits.max_edits_per_file,
            max_total_edits: limits.max_total_edits,
            max_path_bytes: limits.max_path_bytes,
            max_total_text_bytes: limits.max_total_text_bytes,
        },
    )
    .map_err(|error| {
        let mut plan_error = PlanError::from_edit(&error);
        if let Some(file_index) = error.file_index()
            && let (Some(operation_index), Some(file)) =
                (operation_indices.get(file_index), files.get(file_index))
        {
            plan_error = plan_error.at_operation(*operation_index).at_path(file.path);
        }
        plan_error
    })?;
    Ok((checked.total_edits(), checked.total_text_bytes()))
}