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
//! The assembly row is HAND-WRITABLE, its gate DEFAULTS to nothing, and the refusal names every gap.
//!
//! What the macro emits is asserted off its tokens in `ingraph-codegen` and put through a real
//! compile by `ingraph/tests/tower_assembly.rs`. What is here is the half neither of those can
//! state: that a tower nobody generated runs, and what the gate's own sentences say.

use crate::{Lane, LaneIdent, RouterMissing};

use super::{AssembledTower, SeatsUnfilled, UnfilledSeat};
use crate::retrieve::{DeclaredTower, SearchTower};

/// A tower written by hand — no macro, no walk, and a `run` that is the whole of its road.
struct Shout;

/// Where its steps live, named separately from the tower for the steps seat's own reason.
#[derive(Default)]
struct ShoutSteps {
  spoken: usize,
}

impl SearchTower for Shout {
  type Question = String;
  type Answer = String;
  type Steps = ShoutSteps;
}

impl DeclaredTower for Shout {
  type StepOptions = ();
  type SearchOptions = ();
}

impl AssembledTower for Shout {
  type Refusal = core::convert::Infallible;

  async fn run(
    steps: &mut Self::Steps,
    question: Self::Question,
    _options: Option<&Self::StepOptions>,
    _asked: Option<Self::SearchOptions>,
  ) -> Result<Self::Answer, Self::Refusal> {
    steps.spoken += 1;
    Ok(question.to_uppercase())
  }
}

/// A tower nobody generated runs under the uniform call, and the steps it was handed are the steps
/// it spent.
#[tokio::test]
async fn a_hand_written_tower_runs_at_the_uniform_arity() {
  let mut steps = ShoutSteps::default();

  let answered = Shout::run(&mut steps, "beijing".to_owned(), None, None)
    .await
    .expect("this road refuses nothing");

  assert_eq!(answered, "BEIJING");
  assert_eq!(steps.spoken, 1, "the run reached the steps it was handed");
}

/// **ABSENCE-IDENTITY AT THE GATE**: a tower that declared no word inherits a check that reads
/// nothing and refuses nothing.
#[test]
fn a_tower_with_no_declared_word_passes_a_gate_it_never_wrote() {
  let steps = ShoutSteps::default();

  Shout::check(&steps).expect("nothing was declared, so nothing can be missing");
}

/// The gate's ONE authority: an empty roster is not a refusal, and anything else is.
#[test]
fn nothing_unfilled_is_not_a_refusal() {
  SeatsUnfilled::checked("Road", Vec::new()).expect("an assembly that answered every word");

  let refused = SeatsUnfilled::checked("Road", vec![UnfilledSeat::widening("widen", "Synonyms")])
    .expect_err("a word with no instance");

  assert_eq!(refused.tower(), "Road");
  assert_eq!(refused.unfilled().len(), 1);
}

/// **EVERY GAP, NEVER THE FIRST** — a two-gap assembly is two sentences in one refusal, and each
/// names its own step and word.
#[test]
fn the_refusal_names_every_declared_word_that_found_no_instance() {
  static CORPUS: &[Lane] = &[
    Lane::of(LaneIdent::new("en")),
    Lane::of(LaneIdent::new("ja")),
  ];

  let refused = SeatsUnfilled::checked(
    "Road",
    vec![
      UnfilledSeat::widening("widen", "Synonyms"),
      UnfilledSeat::crossing("fan", RouterMissing::new(CORPUS)),
    ],
  )
  .expect_err("two words, two empty seats");

  assert_eq!(refused.unfilled()[0].step(), "widen");
  assert_eq!(refused.unfilled()[0].word(), "expand");
  assert_eq!(refused.unfilled()[1].step(), "fan");
  assert_eq!(refused.unfilled()[1].word(), "route");

  let said = refused.to_string();
  assert!(said.contains("`Road` declares 2 stage seats"), "{said}");
  assert!(said.contains("`widen`"), "{said}");
  assert!(said.contains("Synonyms"), "{said}");
  assert!(said.contains("`fan`"), "{said}");
  // THE ROUTER'S OWN SENTENCE, carried whole rather than restated — the roster and both escapes.
  assert!(said.contains("ScriptWeightedFan"), "{said}");
  assert!(said.contains("FanAll"), "{said}");
}

/// One gap reads in the singular, which is the sentence a deployment usually meets.
#[test]
fn one_gap_is_one_seat() {
  let refused = SeatsUnfilled::checked("Road", vec![UnfilledSeat::widening("widen", "Synonyms")])
    .expect_err("one word, one empty seat");

  let said = refused.to_string();
  assert!(said.contains("1 stage seat its assembly"), "{said}");
  assert!(
    said.contains("Expansion::new().with_expander"),
    "the road out is named: {said}"
  );
}