#![cfg_attr(coverage_nightly, coverage(off))]
use std::fs;
#[test]
fn binary_size_regression() {
let binary_path = if std::path::Path::new("../target/release/pmat").exists() {
"../target/release/pmat"
} else if std::path::Path::new("target/release/pmat").exists() {
"target/release/pmat"
} else if std::path::Path::new("../target/debug/pmat").exists()
|| std::path::Path::new("target/debug/pmat").exists()
{
println!("⚠️ Skipping binary size regression test - release binary not found");
println!(" Run 'cargo build --release' to enable this test");
return;
} else {
println!("⚠️ Skipping binary size regression test - no binary found");
println!(" Run 'cargo build' or 'cargo build --release' to enable this test");
return;
};
let metadata = fs::metadata(binary_path)
.unwrap_or_else(|e| panic!("Failed to read binary metadata for {binary_path}: {e}"));
let size_bytes = metadata.len();
let size_mb = size_bytes as f64 / (1024.0 * 1024.0);
println!(
"Kaizen Quality Check - Binary size: {size_bytes} bytes ({size_mb:.2} MB) at {binary_path}"
);
const MAX_SIZE_BYTES: u64 = 50 * 1024 * 1024; const EXPECTED_SIZE_BYTES: u64 = 37 * 1024 * 1024;
assert!(
size_bytes < MAX_SIZE_BYTES,
"Kaizen Quality Gate Failed: Binary size {size_bytes} bytes exceeds maximum limit of {MAX_SIZE_BYTES} bytes (50MB). \
Consider applying Muda elimination to reduce binary size."
);
if size_bytes > EXPECTED_SIZE_BYTES {
println!(
"⚠️ Kaizen Warning: Binary size {size_bytes} bytes is larger than expected {EXPECTED_SIZE_BYTES} bytes. \
This may indicate a regression in size optimizations."
);
} else {
println!("✅ Kaizen Success: Binary size within expected limits");
}
}
#[test]
fn feature_size_impact() {
let feature_sizes = vec![
("all-languages", 16_900_000, 17_500_000), ("rust-only", 14_000_000, 16_000_000), ];
for (feature_name, min_size, max_size) in feature_sizes {
println!("Expected size for '{feature_name}' features: {min_size} - {max_size} bytes");
}
println!("Run `make size-compare` to measure actual feature impact");
}
#[test]
fn template_compression_works() {
let compressed_content = include_str!(concat!(env!("OUT_DIR"), "/compressed_templates.rs"));
let compressed_size = compressed_content.len();
assert!(
compressed_size > 100,
"Template compression appears to have failed: size was {compressed_size} bytes"
);
assert!(compressed_content.contains("COMPRESSED_TEMPLATES"));
assert!(
compressed_content.contains("hex_decode_templates")
|| compressed_content.contains("stub test data")
);
println!("Compressed templates file size: {compressed_size} bytes");
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod benchmarks {
#[test]
fn startup_time_regression() {
use std::process::Command;
use std::time::Instant;
let binary_path = if std::path::Path::new("target/release/pmat").exists() {
"target/release/pmat"
} else if std::path::Path::new("../target/release/pmat").exists() {
"../target/release/pmat"
} else if std::path::Path::new("target/debug/pmat").exists() {
"target/debug/pmat"
} else if std::path::Path::new("../target/debug/pmat").exists() {
"../target/debug/pmat"
} else {
"server/target/debug/pmat"
};
if !std::path::Path::new(binary_path).exists() {
println!(
"⚠️ Skipping startup time regression test - binary not found at {binary_path}"
);
println!(" Run 'cargo build --release' to enable this test");
return;
}
let start = Instant::now();
let output = Command::new(binary_path)
.arg("--version")
.output()
.unwrap_or_else(|e| panic!("Failed to execute binary at {binary_path}: {e}"));
let duration = start.elapsed();
assert!(output.status.success(), "Binary failed to execute");
let startup_ms = duration.as_millis();
println!("Kaizen Quality Check - Cold startup time: {startup_ms}ms using {binary_path}");
let startup_threshold_ms = 100;
if startup_ms > startup_threshold_ms {
println!("⚠️ Kaizen Warning: Startup time {startup_ms}ms exceeds {startup_threshold_ms}ms threshold");
println!(" Consider applying Muda elimination to reduce startup overhead");
} else {
println!("✅ Kaizen Success: Startup time meets quality standard");
}
let max_startup_ms = if std::env::var("CI").is_ok() {
200
} else {
100
};
assert!(
startup_ms <= max_startup_ms,
"Kaizen Quality Gate Failed: Startup time {startup_ms}ms exceeds maximum {max_startup_ms}ms"
);
assert!(
startup_ms < 1000,
"Startup time {startup_ms}ms exceeds maximum limit of 1000ms"
);
}
#[test]
fn memory_usage_baseline() {
println!("Memory usage baseline test");
println!("Run with: valgrind --tool=massif ./target/release/pmat --version");
println!("Expected peak memory: <50MB for CLI operations");
}
}