Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Regression Prevention

Regressions are defects that were previously fixed but reappear. During migration, they can be introduced by transpilation errors, optimization passes, or incorrect type mappings.

Snapshot Testing

Capture known-good output and compare on every test run:

#![allow(unused)]
fn main() {
use insta::assert_snapshot;

#[test]
fn pipeline_report_format() {
    let report = generate_analysis_report("./fixtures/sample_project");
    assert_snapshot!(report);
}
}

Review and accept intentional changes with cargo insta review.

Use CaseSnapshot Type
CLI output formatString snapshot
JSON/TOML generationString snapshot
Numeric resultsRounded string snapshot
Error messagesString snapshot

Benchmark Regression Detection

Use Criterion to detect performance regressions:

# Save baseline before migration
cargo bench -- --save-baseline before

# Compare after migration
cargo bench -- --baseline before

Criterion reports statistical significance: +2.3% (p = 0.04) means a real regression.

CI Quality Gates

batuta stack gate
CheckThresholdAction on Failure
Test coverage>= 90%Block merge
Clippy warnings0Block merge
Cyclomatic complexity<= 30Block merge
Cognitive complexity<= 25Block merge
Mutation score>= 80%Warn

Regression Test Workflow

When a bug is found:

  1. Write a failing test that reproduces the bug
  2. Fix the bug
  3. Tag the test with the issue number
#![allow(unused)]
fn main() {
#[test]
fn regression_cb042_negative_stride() {
    // CB-042: Negative stride caused index overflow
    let result = transpose_with_stride(&data, -1);
    assert!(result.is_ok());
}
}

Navigate: Table of Contents