artifactize-core 0.27.2

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

#[test]
fn a_held_directory_stays_and_an_ended_one_is_removed() {
    let root = crate::test_os::tempdir();
    let held = Scratch::create(root.path()).unwrap();
    fs::write(held.path().join("output"), "in use").unwrap();
    // What a killed process leaves: a directory and its lock, nobody holding it.
    let ended_directory = root.path().join("fingerprint-killed");
    let ended_lock = root.path().join("fingerprint-killed.lock");
    fs::create_dir_all(ended_directory.join("runtime-x/tmp")).unwrap();
    fs::write(&ended_lock, "").unwrap();
    sweep(root.path(), SystemTime::UNIX_EPOCH, |_| {
        panic!("only directories without a lock need a modification time")
    })
    .unwrap();
    assert!(held.path().join("output").exists());
    assert!(!ended_directory.exists());
    assert!(!ended_lock.exists());
    let lock = held.lock.clone();
    held.close().unwrap();
    assert!(!lock.exists(), "the lock goes with its directory");
    assert_eq!(fs::read_dir(root.path()).unwrap().count(), 0);
}

#[test]
fn a_directory_without_a_lock_is_removed_once_untouched_for_a_day() {
    let root = crate::test_os::tempdir();
    let unlocked = root.path().join("fingerprint-before");
    fs::create_dir(&unlocked).unwrap();
    let other = root.path().join("runtime-other");
    fs::create_dir(&other).unwrap();
    let modified = SystemTime::UNIX_EPOCH;
    let modified_at = |_: &File| Ok(modified);
    sweep(
        root.path(),
        modified + UNLOCKED_AGE - Duration::from_secs(1),
        modified_at,
    )
    .unwrap();
    assert!(
        unlocked.exists(),
        "it may belong to an older build still running"
    );
    sweep(root.path(), modified + UNLOCKED_AGE, modified_at).unwrap();
    assert!(!unlocked.exists());
    assert!(other.exists(), "only fingerprint directories are swept");
}