vpf-runner 0.4.1

The reference runner of the Verifiable Plan Format (VPF): runs a plan step by step and proves each step.
Documentation
//! When runs start: on a schedule, every so many minutes, or when files change.

use std::fs;

use jiff::Zoned;
use vpf::Day;
use vpf_runner::start::{Snapshot, next_schedule};

fn at(text: &str) -> Zoned {
    text.parse().expect("a time")
}

#[test]
fn a_schedule_starts_on_its_next_day_and_time() {
    // 2026-11-30 is a Monday.
    let now = at("2026-11-30T10:00:00+00:00[UTC]");
    let days = [Day::Mon, Day::Wed];

    assert_eq!(
        next_schedule(&days, &[], "11:00", &now),
        at("2026-11-30T11:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&days, &[], "09:00", &now),
        at("2026-12-02T09:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&days, &[], "10:00", &now),
        at("2026-12-02T10:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&[Day::Mon], &[], "09:30", &now),
        at("2026-12-07T09:30:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&[Day::Sun], &[], "23:59", &now),
        at("2026-12-06T23:59:00+00:00[UTC]")
    );
}

#[test]
fn a_schedule_by_dates_starts_on_the_last_day_of_a_short_month_once() {
    // April has 30 days: 30 and 31 both fall on April 30, which runs once.
    let now = at("2027-04-10T10:00:00+00:00[UTC]");
    assert_eq!(
        next_schedule(&[], &[31], "09:00", &now),
        at("2027-04-30T09:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(
            &[],
            &[30, 31],
            "09:00",
            &at("2027-04-30T10:00:00+00:00[UTC]")
        ),
        at("2027-05-30T09:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&[], &[5], "08:00", &at("2027-12-20T10:00:00+00:00[UTC]")),
        at("2028-01-05T08:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&[], &[29], "08:00", &at("2027-02-01T10:00:00+00:00[UTC]")),
        at("2027-02-28T08:00:00+00:00[UTC]")
    );
}

#[test]
fn a_schedule_by_days_and_dates_starts_on_either() {
    // 2027-04-10 is a Saturday.
    let now = at("2027-04-10T10:00:00+00:00[UTC]");
    assert_eq!(
        next_schedule(&[Day::Mon], &[11], "09:00", &now),
        at("2027-04-11T09:00:00+00:00[UTC]")
    );
    assert_eq!(
        next_schedule(&[Day::Sun], &[20], "09:00", &now),
        at("2027-04-11T09:00:00+00:00[UTC]")
    );
}

#[test]
fn a_change_to_a_matching_file_is_seen() {
    let folder = tempfile::tempdir().expect("a folder");
    let folder = folder.path();
    fs::create_dir(folder.join("inbox")).expect("a folder");
    let paths = vec!["inbox/*.csv".to_owned()];
    let before = Snapshot::take(folder, &paths);

    fs::write(folder.join("inbox/notes.txt"), "x").expect("a file");
    assert_eq!(Snapshot::take(folder, &paths), before);

    fs::write(folder.join("inbox/sales.csv"), "1").expect("a file");
    let added = Snapshot::take(folder, &paths);
    assert_ne!(added, before);

    fs::write(folder.join("inbox/sales.csv"), "1,2").expect("a file");
    assert_ne!(Snapshot::take(folder, &paths), added);
}