|
13 | 13 | use eb_stack::{ |
14 | 14 | check_recipe_deps, packaging_gate, parse_easyconfig_trees, resolve_easyconfig_file, |
15 | 15 | }; |
16 | | -use std::path::PathBuf; |
| 16 | +use std::os::unix::fs::PermissionsExt; |
| 17 | +use std::path::{Path, PathBuf}; |
| 18 | +use std::process::Command; |
17 | 19 |
|
18 | 20 | mod common; |
19 | 21 |
|
@@ -344,3 +346,119 @@ fn eon_core_recipe_copies_do_not_drift() { |
344 | 346 | assert_eq!(canonical, copy, "{copy_rel} drifted from {canonical_rel}"); |
345 | 347 | } |
346 | 348 | } |
| 349 | + |
| 350 | +const SMOKE_STEP: &str = "recipe packaging gate on eOn core fixture"; |
| 351 | + |
| 352 | +/// The `run: |` script of the ci_test.yml step named `name`, dedented. |
| 353 | +fn ci_step(name: &str) -> String { |
| 354 | + let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 355 | + let ci = std::fs::read_to_string(manifest.join(".github/workflows/ci_test.yml")) |
| 356 | + .expect("read ci_test.yml"); |
| 357 | + let header = format!("- name: {name}"); |
| 358 | + let mut lines = ci |
| 359 | + .lines() |
| 360 | + .skip_while(|line| line.trim() != header) |
| 361 | + .skip(1) |
| 362 | + .peekable(); |
| 363 | + assert_eq!( |
| 364 | + lines.next().map(str::trim), |
| 365 | + Some("run: |"), |
| 366 | + "ci_test.yml has no step {name:?} with a run block" |
| 367 | + ); |
| 368 | + let indent = lines |
| 369 | + .peek() |
| 370 | + .map(|line| line.len() - line.trim_start().len()) |
| 371 | + .expect("the run block has a body"); |
| 372 | + lines |
| 373 | + .take_while(|line| line.trim().is_empty() || line.len() - line.trim_start().len() >= indent) |
| 374 | + .map(|line| format!("{}\n", line.get(indent..).unwrap_or(""))) |
| 375 | + .collect() |
| 376 | +} |
| 377 | + |
| 378 | +/// Run a CI step's script as the runner's bash does, with `BIN` set to `bin` |
| 379 | +/// instead of the release build. |
| 380 | +fn run_step(script: &str, bin: &Path) -> std::process::Output { |
| 381 | + let release = "BIN=./target/release/eb-stack\n"; |
| 382 | + assert!(script.contains(release), "the step sets {release:?}"); |
| 383 | + let quoted = bin.display().to_string().replace('\'', r"'\''"); |
| 384 | + Command::new("bash") |
| 385 | + .arg("-ec") |
| 386 | + .arg(script.replace(release, &format!("BIN='{quoted}'\n"))) |
| 387 | + .current_dir(env!("CARGO_MANIFEST_DIR")) |
| 388 | + .output() |
| 389 | + .expect("run bash") |
| 390 | +} |
| 391 | + |
| 392 | +/// A smoke step that expects `recipe check` to fail passes on any error, so a |
| 393 | +/// recipe renamed under it leaves it passing on "No such file or directory". |
| 394 | +#[test] |
| 395 | +fn ci_smoke_step_names_paths_that_exist() { |
| 396 | + let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 397 | + let step = ci_step(SMOKE_STEP); |
| 398 | + let named: Vec<_> = step |
| 399 | + .split_whitespace() |
| 400 | + .filter(|word| word.starts_with("fixtures/")) |
| 401 | + .collect(); |
| 402 | + assert!(!named.is_empty(), "the step names no fixture:\n{step}"); |
| 403 | + for path in named { |
| 404 | + assert!( |
| 405 | + manifest.join(path).exists(), |
| 406 | + "{SMOKE_STEP:?} names {path}, which does not exist" |
| 407 | + ); |
| 408 | + } |
| 409 | +} |
| 410 | + |
| 411 | +/// The step expects `recipe check` to fail only because the drafts leave the |
| 412 | +/// stack's own dependencies unresolved. Run as CI runs it, it passes with |
| 413 | +/// eb-stack and fails when the check fails for any other reason. |
| 414 | +#[test] |
| 415 | +fn ci_smoke_step_accepts_only_the_unresolved_stack_dependencies() { |
| 416 | + let step = ci_step(SMOKE_STEP); |
| 417 | + let real = run_step(&step, Path::new(env!("CARGO_BIN_EXE_eb-stack"))); |
| 418 | + assert!( |
| 419 | + real.status.success(), |
| 420 | + "the step fails with eb-stack:\n{}{}", |
| 421 | + String::from_utf8_lossy(&real.stdout), |
| 422 | + String::from_utf8_lossy(&real.stderr) |
| 423 | + ); |
| 424 | + |
| 425 | + let impostors = [ |
| 426 | + ( |
| 427 | + "a recipe that does not exist", |
| 428 | + "", |
| 429 | + "error: --recipe fixtures/eon_core_rgpot/easyconfigs/e/eOn/eOn-2.17.2-foss-2026.1.eb: No such file or directory (os error 2)", |
| 430 | + ), |
| 431 | + ( |
| 432 | + "a failed packaging gate", |
| 433 | + "", |
| 434 | + "error: packaging gate failed: configopts lack -Dwith_rgpot=true", |
| 435 | + ), |
| 436 | + ( |
| 437 | + "drafts that do not resolve", |
| 438 | + r#" "found": []"#, |
| 439 | + "error: recipe has 14 unresolved dependencies", |
| 440 | + ), |
| 441 | + ]; |
| 442 | + let dir = tempfile::tempdir().expect("tempdir"); |
| 443 | + let stubs: Vec<_> = impostors |
| 444 | + .iter() |
| 445 | + .enumerate() |
| 446 | + .map(|(i, (_, stdout, stderr))| { |
| 447 | + let stub = dir.path().join(format!("eb-stack-{i}")); |
| 448 | + std::fs::write( |
| 449 | + &stub, |
| 450 | + format!("#!/bin/sh\necho '{stdout}'\necho '{stderr}' >&2\nexit 1\n"), |
| 451 | + ) |
| 452 | + .expect("write stub"); |
| 453 | + std::fs::set_permissions(&stub, std::fs::Permissions::from_mode(0o755)) |
| 454 | + .expect("chmod stub"); |
| 455 | + stub |
| 456 | + }) |
| 457 | + .collect(); |
| 458 | + for ((why, _, _), stub) in impostors.iter().zip(&stubs) { |
| 459 | + assert!( |
| 460 | + !run_step(&step, stub).status.success(), |
| 461 | + "the step passes when recipe check fails on {why}" |
| 462 | + ); |
| 463 | + } |
| 464 | +} |
0 commit comments