| 417 | Ok(report) |
| 418 | } |
| 419 | fn main() -> Result<()> { |
| 420 | let mut args = std::env::args().skip(1); |
| 421 | let mut binary = std::env::var_os("ATOMIC_BIN").map(PathBuf::from); |
| 422 | let mut output = None; |
| 423 | while let Some(arg) = args.next() { |
| 424 | match arg.as_str() { |
| 425 | "--atomic-bin" => binary = Some(PathBuf::from(args.next().ok_or("missing binary")?)), |
| 426 | "--out" => output = Some(PathBuf::from(args.next().ok_or("missing output path")?)), |
| 427 | _ => return Err(format!("unknown argument {arg}").into()), |
| 428 | } |
| 429 | } |
| 430 | let binary = binary |
| 431 | .unwrap_or_else(|| PathBuf::from("target/debug/atomic")) |
| 432 | .canonicalize()?; |
| 433 | let root = if let Some(root) = output { |
| 434 | if root.exists() { |
| 435 | return Err("output directory must not already exist".into()); |
| 436 | } |
| 437 | fs::create_dir_all(&root)?; |
| 438 | root.canonicalize()? |
| 439 | } else { |
| 440 | tempfile::Builder::new() |
| 441 | .prefix("atomic-replication-acceptance-") |
| 442 | .tempdir()? |
| 443 | .keep() |
| 444 | }; |
| 445 | match run(&binary, &root) { |
| 446 | Ok(report) => { |
| 447 | let path = root.join("report.json"); |
| 448 | fs::write(&path, serde_json::to_vec_pretty(&report)?)?; |
| 449 | println!("Acceptance observations: {}", path.display()); |
| 450 | for check in report["checks"].as_array().unwrap() { |
| 451 | println!( |
| 452 | "{}: {}", |
| 453 | check["status"].as_str().unwrap(), |
| 454 | check["name"].as_str().unwrap() |
| 455 | ); |
| 456 | } |
| 457 | println!("Production-server validation remains BLOCKED."); |
| 458 | if report["acceptance"]["failed_checks"].as_u64().unwrap_or(0) > 0 { |
| 459 | // Exit nonzero for unmet acceptance, not a green observational run. |
| 460 | std::process::exit(2); |
| 461 | } |
| 462 | Ok(()) |
| 463 | } |
| 464 | Err(e) => { |
| 465 | fs::write(root.join("failure.txt"), e.to_string())?; |
| 466 | eprintln!("Fixture retained at {}", root.display()); |
| 467 | Err(e) |
| 468 | } |
| 469 | } |
| 470 | } |