use std::path::PathBuf;
use std::process::Command;
use std::sync::atomic::{AtomicU64, Ordering};
use pounce_cli::solve_report::SolveReport;
use pounce_nlp::return_codes::ApplicationReturnStatus;
fn pounce_exe() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_pounce"))
}
fn fixture(name: &str) -> PathBuf {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("tests");
p.push("fixtures");
p.push(name);
p
}
fn tmp_path(suffix: &str) -> PathBuf {
static COUNTER: AtomicU64 = AtomicU64::new(0);
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
let mut p = std::env::temp_dir();
p.push(format!(
"pounce_issue540_{}_{}_{suffix}",
std::process::id(),
n
));
p
}
fn solve(extra: &[&str]) -> SolveReport {
let json_path = tmp_path("eigena2.json");
let sol_path = tmp_path("eigena2.sol");
let mut cmd = Command::new(pounce_exe());
cmd.arg(fixture("eigena2.nl"))
.arg(&sol_path)
.arg("--json-output")
.arg(&json_path);
for o in extra {
cmd.arg(o);
}
let _ = cmd.status().expect("spawn pounce");
let text = std::fs::read_to_string(&json_path).expect("read json report");
let _ = std::fs::remove_file(&json_path);
let _ = std::fs::remove_file(&sol_path);
serde_json::from_str(&text).expect("deserialize SolveReport")
}
const NO_TRIGGER: [&str; 1] = ["feral_inertia_pivot_floor=0"];
#[test]
fn eigena2_converges_to_optimal() {
let r = solve(&[]);
assert_eq!(
r.solution.status,
ApplicationReturnStatus::SolveSucceeded,
"eigena2 did not reach a strict certificate (status {:?}, dual inf {:e})",
r.solution.status,
r.statistics.final_dual_inf,
);
}
#[test]
fn eigena2_dual_infeasibility_clears_the_strict_tolerance() {
let dual = solve(&[]).statistics.final_dual_inf;
assert!(
dual < 1e-8,
"dual infeasibility {dual:e} did not clear tol = 1e-8",
);
}
#[test]
fn disabling_the_trigger_reproduces_the_reported_failure() {
let r = solve(&NO_TRIGGER);
assert_eq!(
r.solution.status,
ApplicationReturnStatus::SolvedToAcceptableLevel,
"the pre-#540 route no longer reproduces the issue, so the tests \
above are no longer pinning the fix they describe",
);
let dual = r.statistics.final_dual_inf;
assert!(
dual > 1e-7,
"expected the stuck ~3.3e-7 dual residual from the issue, got {dual:e}",
);
}