ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! WHERE the wildcard sits, which is the half of Vixie's union rule the seam could not see.
//!
//! `10,*` and `*,10` are one set of days written two ways — every day of the month, either way — and
//! they land on OPPOSITE SIDES of the rule that combines the two day fields: the dialect counts a
//! LEADING star as the wildcard that turns the union's *or* into an *and*. So `0 3 *,10 * MON` is
//! Mondays and `0 3 10,* * MON` is every day, from two spellings of one day set.
//!
//! The seam used to answer this itself, from a pair of restricted-flags that carry the same value
//! for both spellings; the dialect decides it now, and these are the assertions that say so. They
//! are the migration's own pin rather than a general test of cron: the suite beside this module
//! covers what the seam DOES, and this covers the one answer the swap CHANGED.

use jiff::Timestamp;

use super::Calendar;

/// The dates of the next `count` occurrences after `from`.
///
/// The DAY is the whole question here, so the clock is dropped from the rendering rather than
/// asserted alongside it — every expression below fires at 03:00 and none of them is about that.
fn days(calendar: &Calendar, from: &str, count: usize) -> Vec<String> {
  let mut at: Timestamp = from.parse().expect("an instant");
  let mut fired = Vec::with_capacity(count);
  for _ in 0..count {
    let Some(next) = calendar.next_after(at) else {
      break;
    };
    fired.push(next.strftime("%Y-%m-%d").to_string());
    at = next.timestamp();
  }
  fired
}

/// Read an expression in a zone with no transitions, so a day is a day.
fn read(expression: &str) -> Calendar {
  Calendar::parse_in(expression, "Etc/UTC").expect("a legal expression")
}

/// NEITHER day field carries a wildcard, so the union is an OR — the baseline the other two move
/// away from.
///
/// `0 3 10 * MON` fires on the tenth AND on every Monday. March 2026 opens on a Sunday, so its
/// Mondays are the 2nd, 9th, 16th, 23rd and 30th, and the 10th is a Tuesday that only the
/// day-of-month field reaches.
#[test]
fn two_restricted_day_fields_are_an_or() {
  assert_eq!(
    days(&read("0 3 10 * MON"), "2026-03-01T00:00:00Z", 6),
    [
      "2026-03-02",
      "2026-03-09",
      // The Tuesday no weekday field named — which an AND reading would never reach.
      "2026-03-10",
      "2026-03-16",
      "2026-03-23",
      "2026-03-30",
    ]
  );
}

/// A TRAILING star leaves the union an OR, and a day-of-month field that admits every day makes that
/// OR fire every day.
///
/// `10,*` names every day of the month and does not lead with the star, so the rule stays an *or*
/// and the left side of it is already true — every day fires, Monday or not.
#[test]
fn a_trailing_star_keeps_the_or_and_fires_every_day() {
  assert_eq!(
    days(&read("0 3 10,* * MON"), "2026-03-01T00:00:00Z", 4),
    ["2026-03-01", "2026-03-02", "2026-03-03", "2026-03-04"]
  );
}

/// A LEADING star turns the union into an AND, so the same day set becomes Mondays only.
///
/// This is the pair's whole point: `*,10` admits exactly the days `10,*` admits, and answers
/// differently — the thing a restricted-flag shared between the two spellings cannot express.
#[test]
fn a_leading_star_turns_the_union_into_an_and() {
  assert_eq!(
    days(&read("0 3 *,10 * MON"), "2026-03-01T00:00:00Z", 4),
    ["2026-03-02", "2026-03-09", "2026-03-16", "2026-03-23"]
  );
}

/// And the leading-star spelling is the BARE star's equal, which is what says the *and* is the
/// wildcard's doing rather than the list's.
///
/// `0 3 *,10 * MON` and `0 3 * * MON` denote one schedule; a reading that treated a two-item list as
/// a restriction would separate them.
#[test]
fn a_leading_star_walks_as_the_bare_star_does() {
  let from = "2026-03-01T00:00:00Z";
  let listed = days(&read("0 3 *,10 * MON"), from, 8);
  // Asserted NON-VACUOUSLY, because two schedules that both fire *never* also walk alike and that
  // would say nothing about the rule. Caught by mutation: a probe at an hour the expression refuses
  // empties both walks, and every other test here failed while this one passed.
  assert_eq!(listed.len(), 8, "{listed:?}");
  assert_eq!(listed, days(&read("0 3 * * MON"), from, 8));
}