artifactize-core 0.27.0

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
use super::*;
use crate::test_os;

#[test]
fn relative_program_paths_are_kept_inside_the_scope() {
    assert_eq!(folder_relative(Path::new("tool")).unwrap(), None);
    assert_eq!(
        folder_relative(Path::new("./bin/tool")).unwrap().as_deref(),
        Some("bin/tool")
    );
    assert!(folder_relative(Path::new("../bin/tool")).is_err());
}

// Windows alone recognizes native backslash separators and drive-relative paths.
#[cfg(windows)]
#[test]
fn windows_relative_program_paths_cannot_bypass_scope_validation() {
    assert_eq!(
        folder_relative(Path::new(r".\bin\tool"))
            .unwrap()
            .as_deref(),
        Some("bin/tool")
    );
    assert!(folder_relative(Path::new(r"..\bin\tool")).is_err());
    assert!(folder_relative(Path::new(r"C:bin\tool")).is_err());
    assert!(folder_relative(Path::new(r"\bin\tool")).is_err());
}

#[test]
fn a_directory_does_not_hide_a_program_one_directory_up() {
    sibling_fallback(|_, immediate| std::fs::create_dir(immediate).unwrap());
}

// Only Unix gives regular files execute permission bits.
#[cfg(unix)]
#[test]
fn a_non_executable_file_does_not_hide_a_program_one_directory_up() {
    sibling_fallback(|candidate, immediate| {
        std::fs::copy(candidate, immediate).unwrap();
        test_os::deny_execution(immediate);
    });
}

fn sibling_fallback(place_unusable_sibling: impl FnOnce(&Path, &Path)) {
    let root = test_os::tempdir();
    let deps = root.path().join("deps");
    std::fs::create_dir(&deps).unwrap();
    let candidate = test_os::working_directory_program(root.path(), "worker");
    let name = candidate.file_name().unwrap();
    place_unusable_sibling(&candidate, &deps.join(name));
    assert_eq!(
        resolve_sibling(name, &deps.join("current")),
        Some(candidate)
    );
}

#[test]
fn link_check_distinguishes_missing_paths_from_uninspectable_paths() {
    let root = test_os::tempdir();
    let file = root.path().join("file");
    reject_link_ancestors(&file.join("child")).unwrap();
    std::fs::write(&file, "not a directory").unwrap();
    assert_eq!(
        reject_link_ancestors(&file.join("child"))
            .unwrap_err()
            .kind(),
        io::ErrorKind::NotADirectory,
    );
}