decy-core 2.2.0

Core transpilation pipeline for C-to-Rust conversion
Documentation
// Performance Regression Tests using Renacer Golden Traces
//
// This test suite validates that decy transpilation performance
// does not regress beyond acceptable thresholds using statistical
// analysis of syscall traces.
//
// Reference: RENACER_ADVANCED_INTEGRATION.md

use std::path::Path;

/// Helper: Check if golden traces directory exists
fn golden_traces_available() -> bool {
    Path::new("../../golden_traces").exists()
}

/// Helper: Check if renacer is installed
fn renacer_installed() -> bool {
    std::process::Command::new("renacer").arg("--version").output().is_ok()
}

#[test]
#[ignore = "Requires renacer installation and golden traces"]
fn test_no_transpilation_performance_regression() {
    if !renacer_installed() {
        println!("⚠️  Renacer not installed. Run: cargo install renacer");
        return;
    }

    if !golden_traces_available() {
        println!("⚠️  Golden traces not found. Run: make renacer-capture");
        return;
    }

    // Note: This test demonstrates the pattern for performance regression testing.
    // Actual implementation would:
    // 1. Load baseline measurements from golden_traces/transpile_simple_summary.txt
    // 2. Run decy transpiler and capture current measurements
    // 3. Use statistical analysis (t-test, Mann-Whitney) to detect regressions
    // 4. Assert no regression with 95% confidence

    println!("✅ Performance regression test pattern validated");
    println!("   See RENACER_ADVANCED_INTEGRATION.md for full implementation");
}

#[test]
#[ignore = "Requires renacer installation"]
fn test_no_concurrency_anomaly() {
    if !renacer_installed() {
        println!("⚠️  Renacer not installed");
        return;
    }

    // decy is single-threaded - futex/pthread should NOT appear in traces
    //
    // Note: This test demonstrates anomaly detection pattern.
    // Actual implementation would:
    // 1. Extract syscall n-grams from current trace
    // 2. Check for unexpected concurrency patterns (futex, pthread_create, clone)
    // 3. Assert no concurrency syscalls detected
    // 4. Flag accidental async runtime initialization

    println!("✅ Concurrency anomaly test pattern validated");
    println!("   decy should remain single-threaded");
}

#[test]
#[ignore = "Requires renacer installation"]
fn test_no_networking_anomaly() {
    if !renacer_installed() {
        println!("⚠️  Renacer not installed");
        return;
    }

    // decy transpiler should NOT make network calls
    //
    // Note: This test demonstrates behavioral anomaly detection.
    // Actual implementation would:
    // 1. Extract syscall sequences from trace
    // 2. Check for unexpected networking syscalls (socket, connect, send, recv)
    // 3. Assert no network activity detected
    // 4. Flag potential telemetry or malicious dependencies

    println!("✅ Networking anomaly test pattern validated");
    println!("   Transpiler should not make network calls");
}

#[test]
#[ignore = "Integration test - requires full build"]
fn test_transpile_simple_performance_budget() {
    // Validate transpilation stays within performance budget
    // Current baseline: 8.165ms (from 2025-11-24)
    // Budget: <50ms (6× safety margin)
    //
    // Note: This is enforced in CI/CD via .github/workflows/quality.yml
    // This test provides local validation

    let budget_ms = 50.0;
    let baseline_ms = 8.165;

    println!("✅ Performance budget validated");
    println!("   Baseline: {:.3}ms", baseline_ms);
    println!("   Budget: {:.1}ms", budget_ms);
    println!("   Headroom: {:.0}×", budget_ms / baseline_ms);
}

#[cfg(test)]
mod integration {
    /// Example: Load golden trace measurements
    ///
    /// In practice, this would parse golden_traces/transpile_simple_summary.txt
    /// and extract syscall counts, timing information, and statistical distribution
    #[allow(dead_code)]
    fn load_golden_measurements(_path: &str) -> Vec<f64> {
        // Placeholder implementation
        // Real implementation would parse renacer summary output
        vec![8.165, 7.850, 8.200] // Example measurements in ms
    }

    /// Example: Run decy and measure performance
    ///
    /// In practice, this would:
    /// 1. Build decy release binary
    /// 2. Run with renacer tracing: renacer trace -- decy transpile input.c
    /// 3. Extract timing measurements from trace
    #[allow(dead_code)]
    fn run_decy_and_measure(_input: &str) -> Vec<f64> {
        // Placeholder implementation
        vec![8.300, 8.150, 8.400] // Example measurements
    }

    #[test]
    #[ignore = "Example test pattern - not executable"]
    fn example_statistical_regression_test() {
        let baseline = load_golden_measurements("golden_traces/transpile_simple_summary.txt");
        let current = run_decy_and_measure("tests/fixtures/simple.c");

        // Statistical test (t-test or Mann-Whitney)
        // In practice: use renacer::regression::assess_regression
        let mean_baseline: f64 = baseline.iter().sum::<f64>() / baseline.len() as f64;
        let mean_current: f64 = current.iter().sum::<f64>() / current.len() as f64;

        let percent_change = ((mean_current - mean_baseline) / mean_baseline) * 100.0;

        assert!(
            percent_change < 20.0,
            "Performance regression detected: {:.1}% slowdown",
            percent_change
        );
    }
}