ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **THE ORIGIN TIER'S FIVE LINES**, read off the entry's tokens.
//!
//! What the tier DOES — a source mounted as a head, its give landing at its consumer, an infinite
//! one told to stop before its consumer is left to drain — is asserted where the emission can be
//! run, in `ingraph`'s own `tests/origin_tier.rs`. What is here is what a token stream can be read
//! for: which door each line names, where in the walk it sits, and the two shapes the tier does NOT
//! take.

use crate::graph::{GraphModel, OriginMount};

use super::tests::{app, compact, rendered};

/// The same root with one origin field beside its three nodes.
fn watched() -> GraphModel {
  GraphModel {
    origins: vec![OriginMount {
      mount: syn::parse_quote!(watch),
      ty: syn::parse_quote!(app::Watch),
    }],
    ..app()
  }
}

/// **AN ORIGIN IS ON THE BAG**, because it is BUILT from its own section exactly as a node is — one
/// slot, one taker, one create line. Construction is where the two tiers are the same SHAPE; the
/// door is where they differ, and `Creation::origin` is the origin's.
#[test]
fn an_origin_takes_a_slot_in_the_node_bag_and_a_taker_of_its_own() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("pub(crate)watch:::core::option::Option<app::Watch>"),
    "{}",
    rendered(&watched())
  );
  assert!(
    emitted.contains("fntake_watch(&mutself)->::core::option::Option<app::Watch>"),
    "{}",
    rendered(&watched())
  );
  assert!(
    emitted.contains("drive::Creation::origin::<app::Watch,>"),
    "{}",
    rendered(&watched())
  );
}

/// **THE ORIGIN'S CREATE LINE NAMES THE ORIGIN'S OWN DOOR AND THE ORIGIN'S OWN PROBE**, and it never
/// names the resident's. The tier read `Creation::node` and `bare_options!` until `Source::build`'s
/// window became `&Resources`: the walk could not reach the face's own construction, so it went
/// through `AsyncConstructor` and the origin carried a second options seat that nothing filled.
#[test]
fn the_origins_create_line_takes_the_origin_tiers_door_and_never_the_residents() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("drive::bare_origin_options!(app::Watch)"),
    "{}",
    rendered(&watched())
  );
  assert!(
    !emitted.contains("drive::Creation::node::<app::Watch,>"),
    "an origin is not built through the resident door: {}",
    rendered(&watched())
  );
  assert!(
    !emitted.contains("drive::bare_options!(app::Watch)"),
    "nor probed through the resident projection: {}",
    rendered(&watched())
  );
}

/// **DECLARED THROUGH ITS OWN DOOR, AND WITH NO CELL IN FRONT OF IT.** A node's line is addressed to
/// `Worn<Pair, Mode>` because the pair word lives on the node's own declaration; an origin has no
/// pair axis at all, and the mode axis it does have is already collapsed inside `Lived<M>`.
#[test]
fn an_origin_is_declared_as_a_head_through_blueprint_origin() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("drive::Blueprint::origin::<app::Watch,>(&mut__ingraph_blueprint,\"watch\")"),
    "{}",
    rendered(&watched())
  );
  assert!(
    !emitted.contains("Worn<<app::Watchas"),
    "no cell on this tier: {}",
    rendered(&watched())
  );
}

/// **THE BRIDGE IS OPENED FROM THE PRODUCER'S END**, under the origin's own `Produced` projection —
/// which is the whole of why the emission never names the consumer: the pairing is in that
/// consumer's declaration and joined into the plan, and this expansion cannot see it.
#[test]
fn the_out_edge_is_opened_by_the_wiring_walk_under_the_produced_projection() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains(
      "drive::Wiring::bridge::<::ingraph::__private::drive::Produced<app::Watch>,>(&mut__ingraph_wiring,__ingraph_at_watch)"
    ),
    "{}",
    rendered(&watched())
  );
}

/// **THE ENROLMENT IS MINTED WITH THE EDGE AND SPENT AT THE IGNITION**, and the value is taken out
/// of the bag only once all three parts exist: an enrolment made for an origin whose value or edge
/// turned out to be absent would be a party the shutdown waits on and nothing ever settles.
#[test]
fn the_value_the_edge_and_the_party_are_taken_together_or_not_at_all() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("drive::Wiring::enrol(&mut__ingraph_wiring,\"watch\",)"),
    "{}",
    rendered(&watched())
  );
  // The take sits INSIDE the arm the bridge opened, which is what makes the three one decision.
  let bridge = emitted
    .find("drive::Wiring::bridge::<")
    .expect("the bridge line is emitted");
  let take = emitted
    .find("AppNodes::take_watch")
    .expect("the origin's value is taken");
  assert!(take > bridge, "{}", rendered(&watched()));
}

/// **THE HANDLE IS KEPT**, and that is what lets the origin run at all: a `Bridged` owns a `Stopper`
/// and a stopper says the stop as it goes, so an expansion that dropped one would wind down the
/// origin it had just started.
#[test]
fn the_ignition_keeps_the_handle_rather_than_being_handed_one() {
  let emitted = compact(&watched());

  assert!(
    emitted.contains("drive::Ignition::origin_kept::<app::Watch,>"),
    "{}",
    rendered(&watched())
  );
  assert!(
    !emitted.contains("Ignition::origin_bridged"),
    "the emitted road never takes the door that hands a handle back: {}",
    rendered(&watched())
  );
}

/// **THE COMMAND LINE'S DEPTH IS THE FRAMEWORK'S SHIPPED DOOR CAPACITY**, and it governs that line
/// alone — a bridged feed is bounded by the EDGE, resolved like every other edge's.
#[test]
fn the_command_line_is_opened_at_the_shipped_door_capacity() {
  assert!(
    compact(&watched()).contains("drive::Wiring::DOOR_CAPACITY"),
    "{}",
    rendered(&watched())
  );
}

/// **ORIGINS IGNITE LAST**, after every node this deployment runs has its engine — the same *last
/// on, first off* the whole stage is arranged around.
#[test]
fn the_origins_are_ignited_after_every_node() {
  let emitted = compact(&watched());
  let last_node = emitted
    .rfind("Mount<TranscriptText,>>::ignite")
    .expect("the last node's ignite line is emitted");
  let origin = emitted
    .find("drive::Ignition::origin_kept::<app::Watch,>")
    .expect("the origin's ignite line is emitted");

  assert!(origin > last_node, "{}", rendered(&watched()));
}

/// **WHAT AN ORIGIN OWES**, discharged at the call site: the record its source declaration emits,
/// the FACE that declaration's own word selected, and the three messages named through the
/// projections the origin layer already publishes.
#[test]
fn the_predicates_name_the_record_the_face_and_the_three_messages() {
  let emitted = compact(&watched());

  for owed in [
    "app::Watch:::ingraph::__private::source::DeclaredOrigin",
    "drive::Lived<<app::Watchas::ingraph::__private::source::DeclaredOrigin>::Mode,>",
    "drive::Produced<app::Watch>:::core::marker::Send",
    "drive::Ordered<app::Watch>:::core::marker::Send",
    "drive::Died<app::Watch,>:::core::error::Error",
  ] {
    assert!(
      emitted.contains(owed),
      "{owed} is owed: {}",
      rendered(&watched())
    );
  }

  // AND NO SECOND CONSTRUCTION TRAIT. `Lived<Mode>` carries the opening as well as the life, so the
  // row already named for the drive is the whole of what a construction needs — and `Died` is the
  // one error predicate, because a refused opening and a death are one currency on this face.
  assert!(
    !emitted.contains("app::Watchas::ingraph::__private::drive::AsyncConstructor"),
    "an origin owes the resident construction door nothing: {}",
    rendered(&watched())
  );
}

/// **AN ORIGIN IS NEVER STAGED.** `Staging::declared` is written over `Declared`, whose `TEARDOWN`
/// word and `goodbye` an origin has neither of — `#[ingraph::source]` emits no teardown seat — so an
/// origin's whole wind-down is its own `Drop`, which is the shipped posture for every value that
/// enrols in no other.
#[test]
fn an_origin_has_no_goodbye_to_stage() {
  assert!(
    !compact(&watched()).contains("Staging::declared::<app::Watch"),
    "{}",
    rendered(&watched())
  );
}

/// **A ROOT WITH NO ORIGIN EMITS NO LINE OF THIS TIER**, which is what keeps the word free: every
/// one of these emissions disappears rather than looping over no members.
#[test]
fn a_root_that_mounts_no_origin_carries_none_of_it() {
  let emitted = compact(&app());

  for absent in [
    "Blueprint::origin",
    "Wiring::bridge",
    "Ignition::origin_kept",
    "Wiring::enrol",
  ] {
    assert!(!emitted.contains(absent), "{absent}: {}", rendered(&app()));
  }
}

/// **THE HAND-WIRED DOOR BUILDS IT AND LEAVES THE ARRANGEMENT ALONE.** `launch_wired` states no
/// blueprint — the caller hands over a plan and holds the wiring walk — so what it owes the origin
/// tier is the construction, and the closure that already names the operators' types is the party
/// that spells the bridge over it.
#[test]
fn the_hand_wired_door_builds_the_origin_and_declares_nothing() {
  let emitted = compact(&watched());
  let wired = emitted
    .find("asyncfnlaunch_wired")
    .expect("the hand-wired door is emitted");
  let converged = emitted
    .find("asyncfnlaunch(")
    .expect("the converged door is emitted");
  let hand = &emitted[wired..converged];

  assert!(
    hand.contains("drive::Creation::origin::<app::Watch,>"),
    "{}",
    rendered(&watched())
  );
  assert!(
    !hand.contains("Blueprint::origin"),
    "{}",
    rendered(&watched())
  );
  assert!(
    !hand.contains("Ignition::origin_kept"),
    "{}",
    rendered(&watched())
  );
}