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
//! What the WIRE PROJECTIONS say: every [`RootState`] tag survives the crossing to
//! [`RegistryState`], every [`RetireOrigin`] survives the crossing to [`RegistryOrigin`], a duration
//! round-trips through humantime text, and the two width helpers clamp rather than wrap.
//!
//! The end-to-end shape — a live schema, executed — is `ingraph/tests/registry_graphql.rs`'s: this
//! file is the pure projections underneath it, which need no schema to exercise.

use core::time::Duration;

use super::{
  RegistryOrigin, RegistryState, format_duration, parse_duration, recent_limit, wire_count,
};
use crate::drive::{RetireOrigin, RootState};

/// **EVERY TAG SURVIVES**, with its payload dropped — [`RootState`]'s five variants, each landing on
/// its own [`RegistryState`].
#[test]
fn every_root_state_tag_survives_the_crossing() {
  assert_eq!(RegistryState::from(RootState::Idle), RegistryState::Idle);
  assert_eq!(
    RegistryState::from(RootState::Analyzing {
      inflight: 3,
      since: std::time::Instant::now(),
    }),
    RegistryState::Analyzing
  );
  assert_eq!(
    RegistryState::from(RootState::Retiring {
      inflight: 1,
      since: std::time::Instant::now(),
    }),
    RegistryState::Retiring
  );
  assert_eq!(
    RegistryState::from(RootState::Retired {
      at: crate::Stamp::now().wall(),
      origin: RetireOrigin::User,
      late_tails: false,
    }),
    RegistryState::Retired
  );
  assert_eq!(
    RegistryState::from(RootState::Restoring),
    RegistryState::Restoring
  );
}

/// **BOTH ORIGINS SURVIVE THE CROSSING**, and the direction is INTO [`RetireOrigin`] — the mutation
/// reads a client's word and the framework's action takes it.
#[test]
fn both_origins_cross_into_retire_origin() {
  assert_eq!(
    RetireOrigin::from(RegistryOrigin::Vanished),
    RetireOrigin::Vanished
  );
  assert_eq!(RetireOrigin::from(RegistryOrigin::User), RetireOrigin::User);
}

/// **A DURATION ROUND-TRIPS THROUGH HUMANTIME TEXT** — [`RegistryOptions`](crate::RegistryOptions)'s
/// own grammar, both ways.
#[test]
fn a_duration_round_trips_through_humantime_text() {
  let text = format_duration(Duration::from_secs(90));
  assert_eq!(text, "1m 30s");
  assert_eq!(
    parse_duration("debounce", &text).expect("humantime's own text parses back"),
    Duration::from_secs(90)
  );
}

/// **A BARE NUMBER IS REFUSED** — humantime's grammar, not a request-tier one; see
/// [`crate::RegistryOptions`]'s own module note.
#[test]
fn a_bare_number_is_not_a_duration() {
  assert!(parse_duration("debounce", "300").is_err());
}

/// **`recent_limit` CLAMPS RATHER THAN WRAPS**: a negative `n` asks for none, an absent `n` asks for
/// the default, and a positive `n` is taken whole.
#[test]
fn recent_limit_clamps_a_negative_ask_to_zero() {
  assert_eq!(recent_limit(Some(-5)), 0);
  assert_eq!(recent_limit(Some(7)), 7);
  assert!(
    recent_limit(None) > 0,
    "an absent ask still answers something"
  );
}

/// **`wire_count` SATURATES RATHER THAN WRAPS**: a count past [`u32::MAX`] answers the honest
/// ceiling instead of a number that lies about having wrapped around zero.
#[test]
fn wire_count_saturates_at_u32_max() {
  assert_eq!(wire_count(5), 5);
  assert_eq!(wire_count(usize::MAX), u32::MAX);
}