ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! THE NOTIFY RECEIPT in the emission: what a `notify` entry's variant carries, and the fence that
//! makes a product with no key refuse.
//!
//! Read off the TOKENS, for [`channel`](super::super::channel)'s reason — what a reader of the
//! emission sees is what a token assertion sees. What the receipt DOES at runtime is asserted where
//! the emission can be run: `drive::notify`'s own tests walk one commit into two receipts.

use crate::{
  model::{RecordModel, Subscription, Upstream},
  tests::model,
};

/// One entry, as the front end would have settled it.
fn upstream(node: &str, notify: bool) -> Upstream {
  let node: syn::Path = syn::parse_str(node).expect("a path");
  let variant = node
    .segments
    .last()
    .expect("a path has a last segment")
    .ident
    .clone();
  Upstream {
    node,
    keyed: false,
    out: None,
    variant,
    channel: None,
    changes: None,
    notify,
  }
}

/// A node drawing from two upstreams: one message receipt, one notify receipt — the shape the
/// ruling's *one store legally feeds both* sentence is about.
fn mixed() -> RecordModel {
  let mut model = model("Summaries", &["media_id"], "id");
  model.subscriptions = Some(Subscription {
    upstreams: vec![
      upstream("asr::Segment", true),
      upstream("media::Ocr", false),
    ],
  });
  model
}

/// The emission with every space taken out.
fn compact(model: &RecordModel) -> String {
  model.emit().to_string().split_whitespace().collect()
}

/// THE PAYLOAD: a notify entry's variant carries the product's KEY, projected through the product's
/// own answer about what its key is — and the entry beside it still carries the product.
#[test]
fn a_notify_entry_carries_the_key_and_its_neighbour_carries_the_message() {
  let emitted = compact(&mixed());
  assert!(
    emitted.contains(
      "Segment(<<asr::Segmentas::ingraph::__private::operator::Emits>::Outas::ingraph::__private::\
       transform::Transformer>::Key)"
    ),
    "{emitted}"
  );
  assert!(
    emitted.contains("Ocr(<media::Ocras::ingraph::__private::operator::Emits>::Out)"),
    "{emitted}"
  );
}

/// THE FENCE: the claim *this product has a key* is emitted for rustc, so a product with none is
/// `E0277` — at the node path the author wrote, rather than inside the enum they cannot edit.
#[test]
fn a_notify_entry_emits_the_audit_that_fences_it() {
  let emitted = compact(&mixed());
  assert!(
    emitted.contains(
      "fn__ig_is_notifiable<__INGRAPH_LANDED__:::ingraph::__private::transform::Transformer>(){}"
    ),
    "{emitted}"
  );
  assert!(
    emitted.contains(
      "const_:fn()=__ig_is_notifiable::<<asr::Segmentas::ingraph::__private::operator::Emits>::Out>;"
    ),
    "{emitted}"
  );
}

/// A container with NO notify entry emits no audit at all — the fence costs a graph that did not
/// ask for a receipt nothing.
#[test]
fn a_container_with_no_receipt_emits_no_fence() {
  let mut model = model("Summaries", &["media_id"], "id");
  model.subscriptions = Some(Subscription {
    upstreams: vec![
      upstream("asr::Segment", false),
      upstream("media::Ocr", false),
    ],
  });
  let emitted = compact(&model);
  assert!(!emitted.contains("__ig_is_notifiable"), "{emitted}");
  assert!(
    !emitted.contains("::ingraph::__private::transform::Transformer>::Key)"),
    "{emitted}"
  );
}

/// The receipt rides the PRODUCT selector too: an entry that named one product of several takes
/// that product's key rather than the node's sole one.
#[test]
fn a_selected_product_is_notified_by_its_own_key() {
  let mut model = model("Summaries", &["media_id"], "id");
  let mut selected = upstream("vision::Detector", true);
  selected.out = Some(syn::parse_str("Boxes").expect("an ident"));
  selected.variant = syn::parse_str("Boxes").expect("an ident");
  model.subscriptions = Some(Subscription {
    upstreams: vec![selected, upstream("media::Ocr", false)],
  });
  let emitted = compact(&model);
  assert!(
    emitted.contains(
      "Boxes(<<vision::Detectoras::ingraph::__private::operator::Emits<{vision::DetectorOutKind::\
       Boxesasusize}>>::Outas::ingraph::__private::transform::Transformer>::Key)"
    ),
    "{emitted}"
  );
}