pub fn validate_refactor(diff: &GraphDiffResult) -> RefactorValidationExpand description
Validates whether a graph diff represents a safe refactor.
Applies validation heuristics to determine if a code change is safe:
- No nodes removed: Nodes removed means breaking changes (existing code may reference them)
- Similarity threshold: Score >= 0.5 (moderate), >= 0.8 (very similar)
- Isomorphism check: Identical structure = safe
- Edge changes: Warnings for removed edges (may affect control flow)
§Validation Rules
§Breaking Changes (is_safe = false)
- Nodes removed - always breaking (breaks existing references)
- Similarity < 0.5 - significant structural changes
§Warnings (not breaking)
- Similarity < 0.8 - moderate changes, review recommended
- Edges removed - may break control flow or dependencies
- Isomorphic - informational (structure preserved)
§Arguments
diff- GraphDiffResult fromgraph_diff()orgraph_diff_with_progress()
§Returns
RefactorValidation with:
is_safe: True if no breaking changes detectedbreaking_changes: List of breaking change descriptionswarnings: List of warnings (not breaking but noteworthy)
§Example
ⓘ
use sqlitegraph::{algo::graph_diff, algo::validate_refactor, SqliteGraph};
let graph_v1 = SqliteGraph::open_in_memory()?;
let graph_v2 = SqliteGraph::open_in_memory()?;
// ... build graphs ...
let diff = graph_diff(&graph_v1, &graph_v2)?;
let validation = validate_refactor(&diff);
if validation.is_safe {
println!("✓ Refactor validated successfully");
if !validation.warnings.is_empty() {
println!("Warnings:");
for warning in &validation.warnings {
println!(" - {}", warning);
}
}
} else {
println!("✗ Refactor validation failed:");
for change in &validation.breaking_changes {
println!(" - {}", change);
}
println!("\nConsider reviewing these changes before deploying.");
}§Use Cases
- Pre-commit validation: Check if refactor is safe before committing
- CI/CD gates: Automated validation in continuous integration
- Code review assist: Highlight potential issues for reviewers
- Refactor confidence: Verify optimizer equivalence