ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **WHAT THE RENAME SEATS DO TO AN EMISSION** — the resolution order, the five roads, the two
//! per-election types, and the framework vocabulary none of them moves.
//!
//! ```text
//!   member       keys(rename = "clipNeighbours")   →  clipNeighbours
//!   base-derived rename = "ShotSearch"             →  shotSearchByClipKeys
//!   default      (nothing written)                 →  shotsByClipKeys
//! ```
//!
//! Beside [`answers`](super::answers) rather than inside it, on this directory's one-file-per-thing
//! precedent: that file proves WHICH FIELDS an election publishes and this one proves WHAT THEY ARE
//! CALLED. It borrows that file's two fixtures and its field walk, so the two readings cannot drift
//! apart about what a plain road or a fanned one even is.
//!
//! # What is asserted here and what is asserted elsewhere
//!
//! Here: the RESOLVED NAME, read off the token stream. The GRAMMAR — which spellings parse and what
//! a refusal says — is `ingraph-derive`'s `index/rename_seats.rs`. The head skin's own three faces
//! and its base are [`super::super::fuse::skins`], which this file deliberately does not re-assert.
//!
//! # The floor is asserted as a PRESENCE, which is the only shape that claim can take
//!
//! Law 3 says the framework's vocabulary never moves. A test can only show that by writing every
//! seat this grammar has and then finding every argument and every row still spelled as the
//! framework spells them — an absence of a rename is not observable any other way, and a grammar
//! that grew a seat for one of them would show up here as a missing word.

use super::{
  ElectionBackend, ElectionLabel, Field, FieldNumbers, IndexBackend, IndexGraphql, IndexModel,
  IndexRename, Numbers,
  answers::{fanned, fields, plain},
};
use crate::{model::GraphqlKind, prefix::EmissionPrefix};

fn ident(name: &str) -> syn::Ident {
  syn::Ident::new(name, proc_macro2::Span::call_site())
}

fn word(spelled: &str) -> syn::LitStr {
  syn::LitStr::new(spelled, proc_macro2::Span::call_site())
}

/// The whole expansion with the spaces taken out — what a claim about a name is read off.
fn tight(model: &IndexModel) -> String {
  model.emit().to_string().split_whitespace().collect()
}

/// `model` with the `clip` election wearing `skin`.
fn dressed(model: IndexModel, skin: ElectionBackend) -> IndexModel {
  IndexModel {
    prefix: EmissionPrefix::default(),
    field_numbers: vec![FieldNumbers {
      field: ident("clip"),
      numbers: Numbers::default(),
      skins: vec![skin],
    }],
    ..model
  }
}

/// An election block with ONE road named and nothing else.
fn road(which: Field, spelled: &str) -> ElectionBackend {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  let seat = match which {
    Field::Keys => &mut skin.keys,
    Field::Hydrated => &mut skin.hydrated,
    Field::Fused => &mut skin.fused,
    Field::Similar => &mut skin.similar,
    Field::SimilarHydrated => &mut skin.similar_hydrated,
  };
  *seat = Some(word(spelled));
  skin
}

/// **EVERY ROAD SEAT REACHES ITS OWN QUERY FIELD**, on the shape that publishes that road.
///
/// The five-for-five claim the 2026-08-16 ruling closed: the two HYDRATED roads had no seat before
/// it and took the derived name whatever a declaration wrote, so the two rows that matter most here
/// are the ones that used to be unreachable.
///
/// Asserted as a MEMBERSHIP plus an ABSENCE rather than as an equality over the whole list, because
/// the equality is [`super::answers`]'s claim and repeating it here would make this test fail for
/// that file's reason.
#[test]
fn every_road_seat_reaches_the_field_it_names() {
  for (which, base) in [
    (Field::Keys, "shotsByClipKeys"),
    (Field::Hydrated, "shotsByClip"),
    (Field::Similar, "shotsSimilarByClipKeys"),
    (Field::SimilarHydrated, "shotsSimilarByClip"),
  ] {
    let published = fields(&dressed(plain(), road(which, "aWord")));
    assert!(
      published.contains(&"aWord".to_owned()),
      "`{}` did not reach a field: {published:?}",
      which.as_str(),
    );
    assert!(
      !published.contains(&base.to_owned()),
      "`{}` left its derived name behind as well: {published:?}",
      which.as_str(),
    );
  }

  // The FUSED road lives on the other shape, which publishes it alone.
  assert_eq!(
    fields(&dressed(fanned(), road(Field::Fused, "clipEverywhere"))),
    vec!["clipEverywhere".to_owned()],
  );
}

/// **MEMBER, THEN BASE-DERIVED, THEN DEFAULT** — the ruling's resolution order, read at one field
/// with all three answers live in one declaration.
///
/// One model rather than three, because the claim is about PRECEDENCE: three separate declarations
/// would prove each answer reachable and nothing about which of them wins.
#[test]
fn a_road_resolves_member_then_base_then_default() {
  let renamed = IndexModel {
    prefix: EmissionPrefix::default(),
    rename: Some(IndexRename::Base(ident("ShotSearch"))),
    ..dressed(plain(), road(Field::Keys, "clipNeighbours"))
  };
  let published = fields(&renamed);
  assert!(
    published.contains(&"clipNeighbours".to_owned()),
    "the MEMBER lost to the base: {published:?}",
  );
  assert!(
    published.contains(&"shotSearchByClip".to_owned()),
    "the BASE did not reach the roads it was left to: {published:?}",
  );
  assert!(
    !published.contains(&"shotsByClip".to_owned()),
    "a road kept the DEFAULT although a base was written: {published:?}",
  );
}

/// **A DECLARED WORD DOES NOT COMPOSE ONTO ITS NEIGHBOUR** — the verbatim law, at the pair the
/// hydrated seats were minted for.
///
/// The alternative this rules out is the one that looked cheapest before the ruling: deriving the
/// hydrated field's name from the keys field's. `clipNeighbours` → `clipNeighboursHydrated` is a
/// name its author could not have predicted from what they typed, so the tier below keeps the
/// derived name until its own seat is written.
#[test]
fn a_declared_road_leaves_its_tier_below_on_the_derived_name() {
  let published = fields(&dressed(plain(), road(Field::Keys, "clipNeighbours")));
  assert!(published.contains(&"clipNeighbours".to_owned()));
  assert!(
    published.contains(&"shotsByClip".to_owned()),
    "the keys word composed its way onto the hydrated twin: {published:?}",
  );
}

/// **THE PER-ELECTION QUESTION TYPE IS NAMEABLE**, and the word moves the SCHEMA name alone.
///
/// The axis law this family already lives under, at the seat the ruling added: a Rust name a
/// declaring scope holds cannot depend on which backends happen to be compiled in.
#[test]
fn the_election_question_seat_moves_the_schema_name_and_no_rust_one() {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.question = Some(word("ClipAsk"));
  let model = dressed(plain(), skin);
  let emitted = tight(&model);
  assert!(
    emitted.contains(r#"Cow::Borrowed("ClipAsk")"#),
    "the seat did not reach the published name: {emitted}",
  );
  assert!(
    emitted.contains("enumShotsClipQuestion{"),
    "the schema word moved the Rust declaration: {emitted}",
  );
}

/// **AND SO IS THE PER-ELECTION ENGINES PRODUCT**, on the shape that mints one.
#[test]
fn the_election_engines_seat_moves_the_schema_name_of_the_product() {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.engines = Some(word("ClipLegs"));
  let emitted = tight(&dressed(fanned(), skin));
  assert!(
    emitted.contains(r#""ClipLegs""#),
    "the seat did not reach the published name: {emitted}",
  );
  assert!(
    emitted.contains("structShotsClipEngines"),
    "the schema word moved the Rust declaration: {emitted}",
  );
}

/// **A MEMBER BLOCK IS STANDALONE-LEGAL** — one override with no base above it is a complete
/// declaration rather than half of a pair.
///
/// The measurement is the OTHER names: with a member and no base, everything the member did not name
/// stays on the Rust name, which is what a declaration that wrote no skin base has always published.
/// A resolution that read the base first would answer nothing at all here.
#[test]
fn a_member_with_no_base_above_it_moves_its_own_face_and_nothing_else() {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.question = Some(word("ClipAsk"));
  let emitted = tight(&dressed(plain(), skin));
  assert!(emitted.contains(r#"Cow::Borrowed("ClipAsk")"#), "{emitted}");
  assert!(
    fields(&dressed(plain(), {
      let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
      skin.question = Some(word("ClipAsk"));
      skin
    }))
    .contains(&"shotsByClipKeys".to_owned()),
    "a type seat with no base moved a field name as well",
  );
}

/// **THE MEMBER WINS OVER THE SKIN'S BASE**, which is the same order the roads take, read at the
/// type axis where the base is the SKIN's rather than the bones'.
#[test]
fn a_type_seat_wins_over_the_skin_base_and_the_base_takes_the_rest() {
  let mut head = IndexBackend::of(GraphqlKind::AsyncGraphql);
  head.prefix = Some(word("Reels"));
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.question = Some(word("ClipAsk"));
  let model = IndexModel {
    prefix: EmissionPrefix::default(),
    graphql: Some(IndexGraphql {
      backends: vec![head],
    }),
    ..dressed(plain(), skin)
  };
  let emitted = tight(&model);
  assert!(
    emitted.contains(r#"Cow::Borrowed("ClipAsk")"#),
    "the base displaced the member: {emitted}",
  );
  assert!(
    !emitted.contains(r#"Cow::Borrowed("ReelsClipQuestion")"#),
    "both answers were published: {emitted}",
  );
}

/// **LAW 3: THE FRAMEWORK'S VOCABULARY IS UNMOVED BY EVERY SEAT AT ONCE.**
///
/// Every seat this grammar has, written on one declaration, and then every argument the plain road
/// publishes and the `@oneOf`'s own arm read back as the framework spells them. The words a
/// declaration CAN move are the two type names beside them, and those are asserted moved in the same
/// breath — so this is not a test that would pass for a grammar that had quietly stopped renaming
/// anything at all.
#[test]
fn no_seat_moves_an_argument_word_on_the_plain_road() {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.question = Some(word("ClipAsk"));
  skin.engines = Some(word("ClipLegs"));
  skin.keys = Some(word("aKeys"));
  skin.hydrated = Some(word("aHydrated"));
  skin.fused = Some(word("aFused"));
  skin.similar = Some(word("aSimilar"));
  skin.similar_hydrated = Some(word("aSimilarHydrated"));
  let mut head = IndexBackend::of(GraphqlKind::AsyncGraphql);
  head.prefix = Some(word("Reels"));
  let model = IndexModel {
    prefix: EmissionPrefix::default(),
    graphql: Some(IndexGraphql {
      backends: vec![head],
    }),
    rename: Some(IndexRename::Base(ident("ShotSearch"))),
    ..dressed(plain(), skin)
  };
  let emitted = tight(&model);
  for floor in [
    r#"name="question""#,
    r#"name="engine""#,
    r#"name="first""#,
    r#"name="depth""#,
    r#"name="key""#,
  ] {
    assert!(emitted.contains(floor), "`{floor}` moved: {emitted}");
  }
  // The `@oneOf`'s own arm, which is the question type's one row and is spelled twice — the registry
  // entry and the parse — so a rename that reached it would show at both.
  assert!(emitted.contains(r#"from("coordinates")"#), "{emitted}");
  // AND THE SEATS DID FIRE, which is what stops the assertions above from being vacuous.
  assert!(emitted.contains(r#"Cow::Borrowed("ClipAsk")"#), "{emitted}");
}

/// The same law over the FANNED road, which is where the answer ROWS live: a fused hit publishes the
/// score, the ordinal and the contribution one store put in, and a leaderboard's own evidence.
#[test]
fn no_seat_moves_an_answer_row_on_the_fused_road() {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.question = Some(word("ClipAsk"));
  skin.engines = Some(word("ClipLegs"));
  skin.fused = Some(word("clipEverywhere"));
  let emitted = tight(&dressed(fanned(), skin));
  for floor in [
    r#"name="score""#,
    r#"name="ordinal""#,
    r#"name="contribution""#,
    r#"name="evidence""#,
    r#"name="node""#,
    r#"name="engines""#,
    r#"name="question""#,
  ] {
    assert!(emitted.contains(floor), "`{floor}` moved: {emitted}");
  }
  assert_eq!(
    fields(&dressed(fanned(), {
      let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
      skin.fused = Some(word("clipEverywhere"));
      skin
    })),
    vec!["clipEverywhere".to_owned()],
    "the seats fired while every row above stayed put",
  );
}

/// **A DECLARATION THAT WROTE NOTHING PUBLISHES WHAT IT ALWAYS PUBLISHED** — the reshape is a
/// grammar change and not a naming change, so the silence has to be byte-identical.
#[test]
fn the_silence_is_untouched_by_the_new_seats() {
  assert_eq!(
    fields(&plain()),
    vec![
      "shotsByClipKeys".to_owned(),
      "shotsSimilarByClipKeys".to_owned(),
      "shotsByClip".to_owned(),
      "shotsSimilarByClip".to_owned(),
    ],
  );
  assert!(tight(&plain()).contains(r#"Cow::Borrowed("ShotsClipQuestion")"#));
  // AND THE ELECTION LABEL is the fixture's own, so this is the shape the two above read.
  assert!(matches!(
    plain().embeddings[0].label,
    ElectionLabel::Embedding
  ));
}