ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **THE ADDRESS'S TWO FACES, NAMED OUTRIGHT** — what `key(output(rename = "…"))` and
//! `key(input(rename = "…"))` publish, and the order they settle against the base.
//!
//! ```text
//!   member        key(output(rename = "AddressM"))  →  AddressM      / AddressInput
//!   base-derived  key(rename = "Address"))          →  Address       / AddressInput
//!   default       (nothing written)                 →  VideoTrackKey / VideoTrackKeyInput
//! ```
//!
//! Beside [`key_rename_tests`](super::key_rename_tests) rather than inside it, and the split is the
//! ruling: that file's subject is the BASE — one word re-basing both halves, and the `Input` suffix
//! that is the one blessed composition in this grammar. This one's subject is what the 2026-08-16
//! ruling added on top of it, which is a different claim about the same pair.
//!
//! # The claim that could not be made before, and is made here
//!
//! A base can re-base a pair but can never NAME either half of it. So the assertion that matters is
//! the ASYMMETRIC one: a declaration moves the reading half and the sending half stays where the
//! base put it. A resolution that moved both would pass every test in the neighbouring file.
//!
//! # And the one that keeps the composition honest
//!
//! `output(rename = "AddressM")` must NOT produce `AddressMInput`. A declared word is VERBATIM, and
//! the suffix is blessed for the BASE alone — an author's chosen name is not a stem this framework
//! may suffix, which is exactly why two seats were minted instead of one.

use super::key_rename_tests::published;
use crate::{model::RecordModel, name::RustSafeName};

fn word(spelled: &str) -> String {
  spelled.to_owned()
}

/// [`crate::tests::wired`] wearing whatever the three address seats were given.
///
/// `wired`'s key is COMPOUND, which is what puts the argument object in the emission at all — a
/// root's address crosses inward as its id and mints no type, so a root fixture could not carry any
/// of these claims.
fn addressed(base: Option<&str>, object: Option<&str>, argument: Option<&str>) -> RecordModel {
  let mut model = crate::tests::wired();
  let record = model.record.clone();
  let block = model
    .graphql
    .as_mut()
    .expect("`wired` declares a wire face");
  block.key_output = match base {
    Some(base) => RustSafeName::new(base, proc_macro2::Span::call_site()),
    None => RustSafeName::from_ident(&crate::model::default_key_output_name(&record)),
  };
  block.key_object = object.map(word);
  block.key_argument = argument.map(word);
  assert!(
    model.key.compound(),
    "`{record}` is the compound fixture this reading needs",
  );
  model
}

/// **THE READING HALF MOVES ALONE** — the asymmetry a base could not express, which is the whole
/// reason the seat exists.
#[test]
fn the_object_seat_moves_the_reading_half_and_leaves_the_sending_one() {
  assert_eq!(
    published(&addressed(None, Some("AddressM"), None)),
    ("AddressM".to_owned(), "VideoTrackKeyInput".to_owned(),),
  );
}

/// **AND THE SENDING HALF MOVES ALONE**, by the same reading at the other seat.
#[test]
fn the_argument_seat_moves_the_sending_half_and_leaves_the_reading_one() {
  assert_eq!(
    published(&addressed(None, None, Some("AddressIn"))),
    ("VideoTrackKey".to_owned(), "AddressIn".to_owned()),
  );
}

/// **A DECLARED WORD DOES NOT COMPOSE ONTO ITS SIBLING** — the verbatim law, at the one grammar in
/// this workspace that has a blessed composition and must not spread it.
///
/// The wrong answer this rules out is `AddressMInput`, which is what a resolution that suffixed
/// whatever the object had settled on would produce. The suffix belongs to the BASE: an author who
/// chose `AddressM` said nothing about the argument, and the argument therefore keeps the answer the
/// base gives it.
#[test]
fn a_named_object_leaves_the_argument_on_the_bases_own_composition() {
  assert_eq!(
    published(&addressed(Some("Address"), Some("AddressM"), None)),
    ("AddressM".to_owned(), "AddressInput".to_owned()),
  );
}

/// **MEMBER, THEN BASE-DERIVED, THEN DEFAULT**, with all three answers live in one declaration.
///
/// One model rather than three, because the claim is about PRECEDENCE: separate declarations would
/// prove each answer reachable and nothing about which of them wins.
#[test]
fn each_face_resolves_member_then_base_then_default() {
  assert_eq!(
    published(&addressed(
      Some("Address"),
      Some("AddressM"),
      Some("AddressIn"),
    )),
    ("AddressM".to_owned(), "AddressIn".to_owned()),
    "a member lost to the base it sits under",
  );
  assert_eq!(
    published(&addressed(Some("Address"), None, None)),
    ("Address".to_owned(), "AddressInput".to_owned()),
    "the base stopped answering where no member was written",
  );
  assert_eq!(
    published(&addressed(None, None, None)),
    ("VideoTrackKey".to_owned(), "VideoTrackKeyInput".to_owned()),
    "the silence stopped publishing what it always published",
  );
}

/// **A MEMBER IS STANDALONE-LEGAL** — read here as a resolution fact rather than a grammar one: the
/// member arm is answered without the base being consulted, so a face named with no base above it
/// publishes its own word beside a default.
///
/// The measurement is the OTHER half: it is on the record's own stem, which is what a declaration
/// that wrote no base at all publishes. A resolution that required a base would have to invent one.
#[test]
fn a_member_with_no_base_publishes_its_word_beside_the_default() {
  let (object, argument) = published(&addressed(None, Some("AddressM"), None));
  assert_eq!(object, "AddressM");
  assert_eq!(argument, "VideoTrackKeyInput");
}

/// **A MEMBER MOVES NO RUST NAME**, which is the axis law the whole rename system rides inside.
///
/// Asserted on the DECLARED items rather than on a roster, so what is read is the set of types an
/// author's own scope receives.
#[test]
fn a_named_face_lands_no_type_in_the_declaring_scope() {
  let file: syn::File = syn::parse2(addressed(None, Some("AddressM"), Some("AddressIn")).emit())
    .expect("the emission parses");
  let landed: Vec<String> = file
    .items
    .iter()
    .filter_map(|item| match item {
      syn::Item::Struct(declared) => Some(declared.ident.to_string()),
      _ => None,
    })
    .collect();
  assert!(
    landed.contains(&"VideoTrackKeyOutput".to_owned())
      && landed.contains(&"VideoTrackKeyInput".to_owned()),
    "a schema word moved a Rust name: {landed:?}",
  );
  assert!(
    !landed
      .iter()
      .any(|name| name == "AddressM" || name == "AddressIn"),
    "a schema word minted a Rust name: {landed:?}",
  );
}