ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! **THE ANSWER SIDE'S TWO RENAME SEATS** — `sighting(rename = "…")` and
//! `fused_key_match(rename = "…")` on an election, what each moves, and the arms neither of them
//! reaches.
//!
//! ```text
//!   #[ingraph(embedding, knn, deep(type=…), shallow(type=…), fanout, graphql(async_graphql(
//!     sighting(rename = "ClipAgreement"),
//!     fused_key_match(rename = "ClipLeader"),
//!   )))]
//!
//!   union ClipAgreement = ShotsClipDeepSighting | ShotsClipShallowSighting   ← ARMS UNMOVED
//!   type  ClipLeader { node: …, score: Float!, evidence: [ClipAgreement!]! }
//! ```
//!
//! Beside [`rename_resolution`](super::rename_resolution) rather than inside it, on this directory's
//! one-file-per-thing precedent: that file proves the REQUEST side's seats and the resolution order,
//! and this one proves the ANSWER side's two — which is the pair the 2026-08-18 ruling minted, and
//! the pair whose absence `fuse::skins` had recorded as a real gap.
//!
//! # What is asserted here and what is asserted elsewhere
//!
//! Here: the RESOLVED SDL name, read off the token stream, and the two things a seat must NOT move —
//! the Rust declaration and the union's arms. The GRAMMAR is `ingraph-derive`'s
//! `index/rename_seats.rs`; WHICH types a fanned election publishes at all is
//! [`answers`](super::answers), whose fixtures this file borrows so the two readings cannot drift
//! apart about what a fanned road even is.
//!
//! # The ARMS are the claim, and they are why each accepting test states an exclusion
//!
//! An arm is `<Index><Field><Engine>Sighting`, derived from the leg's own word — so a seat over the
//! union that also moved the arms would be one word moving a SET of types, which is the shape
//! `engine(rename = …)` is refused for at the head. Every test below therefore names the seat that
//! was filled AND at least one name that was not.

use super::{
  ElectionBackend, FieldNumbers, IndexBackend, IndexGraphql, IndexModel, IndexRename, Numbers,
  answers::{fanned, 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` — [`super::rename_resolution`]'s own helper, one
/// file over, because a fixture that dressed an election differently here would be proving something
/// about this file rather than about the seats.
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 the UNION seat filled and nothing else.
fn sighting(spelled: &str) -> ElectionBackend {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.sighting = Some(word(spelled));
  skin
}

/// An election block with the ROW seat filled and nothing else.
fn fused_key_match(spelled: &str) -> ElectionBackend {
  let mut skin = ElectionBackend::of(GraphqlKind::AsyncGraphql);
  skin.fused_key_match = Some(word(spelled));
  skin
}

/// **THE UNION SEAT MOVES THE PUBLISHED UNION AND LEAVES THE ARMS**, which is the whole content of
/// the ruling that the arms stay leg-derived.
///
/// Three claims in one, because two of them are the exclusions: the word reaches the union's own
/// published name, the Rust declaration does not move with it (the axis law this family lives
/// under), and neither arm's published name moves.
#[test]
fn the_sighting_seat_moves_the_union_and_never_its_arms() {
  let emitted = tight(&dressed(fanned(), sighting("ClipAgreement")));

  assert!(
    emitted.contains(r#""ClipAgreement""#),
    "the seat did not reach the published name: {emitted}",
  );
  assert!(
    !emitted.contains(r#""ShotsClipSighting""#),
    "the derived union name survived the rename: {emitted}",
  );
  assert!(
    emitted.contains("enumShotsClipSighting{"),
    "the schema word moved the RUST declaration: {emitted}",
  );
  for arm in ["ShotsClipDeepSighting", "ShotsClipShallowSighting"] {
    assert!(
      emitted.contains(&format!(r#""{arm}""#)),
      "the union's word moved `{arm}` with it: {emitted}",
    );
  }
}

/// **THE ROW SEAT MOVES THE FUSED ROW AND NOTHING ELSE** — [`the_sighting_seat_moves_the_union_and_never_its_arms`]'s
/// twin at the other half of one answer.
///
/// The exclusion that matters here is the UNION: the two are one answer's two types, and a grammar
/// that had wired one seat to both slots would show as this word moving the union as well.
#[test]
fn the_fused_key_match_seat_moves_the_row_and_leaves_the_union() {
  let emitted = tight(&dressed(fanned(), fused_key_match("ClipLeader")));

  assert!(
    emitted.contains(r#""ClipLeader""#),
    "the seat did not reach the published name: {emitted}",
  );
  assert!(
    !emitted.contains(r#""ShotsClipFusedKeyMatch""#),
    "the derived row name survived the rename: {emitted}",
  );
  assert!(
    emitted.contains("structShotsClipFusedKeyMatch{"),
    "the schema word moved the RUST declaration: {emitted}",
  );
  assert!(
    emitted.contains(r#""ShotsClipSighting""#),
    "the row's word moved the union with it: {emitted}",
  );
}

/// **THE TWO SEATS ARE TWO SEATS**, filled together in one block, each reaching its own type.
///
/// Written as a pair rather than trusted to the two tests above, because those fill one seat each: a
/// grammar whose second reader overwrote the first's slot passes both of them and fails here.
#[test]
fn the_two_answer_seats_fill_independently() {
  let mut skin = sighting("ClipAgreement");
  skin.fused_key_match = Some(word("ClipLeader"));
  let emitted = tight(&dressed(fanned(), skin));

  assert!(emitted.contains(r#""ClipAgreement""#), "{emitted}");
  assert!(emitted.contains(r#""ClipLeader""#), "{emitted}");
  assert!(!emitted.contains(r#""ShotsClipSighting""#), "{emitted}");
  assert!(
    !emitted.contains(r#""ShotsClipFusedKeyMatch""#),
    "{emitted}"
  );
}

/// **THE ROW WORD IS UNTOUCHED BY EITHER SEAT** — law 3's floor, read at the answer this pair
/// renames.
///
/// A seat names the TYPE, and what a client writes inside it is `node`, `score` and `evidence`
/// whatever the type is called. The claim is a PRESENCE, which is the only shape it can take: an
/// absence of a rename is not observable except as the framework's own words still being there.
#[test]
fn a_renamed_answer_still_carries_the_frameworks_own_rows() {
  let mut skin = sighting("ClipAgreement");
  skin.fused_key_match = Some(word("ClipLeader"));
  let emitted = tight(&dressed(fanned(), skin));

  for row in ["node", "score", "evidence", "ordinal", "contribution"] {
    assert!(
      emitted.contains(&format!(r#"#[graphql(name="{row}")]"#)),
      "the floor row `{row}` is not published: {emitted}",
    );
  }
  assert!(
    !emitted.contains(r#"#[graphql(name="key")]"#),
    "the retired address spelling reached a fused answer: {emitted}",
  );
}

/// **THE SEATS WIN OVER THE SKIN'S BASE, AND THE BASE TAKES THE REST** — the resolution order the
/// request-side seats already carry, read at the answer side.
///
/// One model with a base AND one of the two seats, because the claim is PRECEDENCE: two declarations
/// would prove each answer reachable and nothing about which of them wins.
#[test]
fn an_answer_seat_wins_over_the_skin_base_which_takes_the_other_half() {
  let mut head = IndexBackend::of(GraphqlKind::AsyncGraphql);
  head.prefix = Some(word("Reels"));
  let model = IndexModel {
    prefix: EmissionPrefix::default(),
    graphql: Some(IndexGraphql {
      backends: vec![head],
    }),
    ..dressed(fanned(), sighting("ClipAgreement"))
  };
  let emitted = tight(&model);

  assert!(
    emitted.contains(r#""ClipAgreement""#),
    "the MEMBER lost to the base: {emitted}",
  );
  assert!(
    emitted.contains(r#""ReelsClipFusedKeyMatch""#),
    "the BASE did not reach the half the member left it: {emitted}",
  );
  assert!(
    !emitted.contains(r#""ShotsClipFusedKeyMatch""#),
    "a face kept the DEFAULT although a base was written: {emitted}",
  );
}

/// **A SEAT IS AN SDL NAME AND MOVES NO RUST ONE**, read against the BONES rename that does move
/// Rust names — the two axes side by side in one declaration.
#[test]
fn an_answer_seat_and_the_bones_rename_move_two_different_things() {
  let model = IndexModel {
    prefix: EmissionPrefix::default(),
    rename: Some(IndexRename::Base(ident("ShotSearch"))),
    ..dressed(fanned(), sighting("ClipAgreement"))
  };
  let emitted = tight(&model);

  assert!(
    emitted.contains("enumShotSearchClipSighting{"),
    "the BONES rename did not move the Rust declaration: {emitted}",
  );
  assert!(
    emitted.contains(r#""ClipAgreement""#),
    "the SKIN seat did not survive the bones rename: {emitted}",
  );
}

/// **AN UNFANNED ELECTION MINTS NEITHER TYPE, AND THE WORDS ARE THEN SIMPLY UNSPENT** — the state
/// every other seat in this block is already in on a shape that does not publish its road.
///
/// The measurement is that the expansion is UNCHANGED rather than refused: a resolution that had
/// pushed an override for a name nothing mints would still be harmless, and this is what says so
/// rather than assuming it.
#[test]
fn the_answer_seats_are_unspent_on_a_road_that_publishes_no_fused_answer() {
  let mut skin = sighting("ClipAgreement");
  skin.fused_key_match = Some(word("ClipLeader"));
  let dressed_up = tight(&dressed(plain(), skin));
  let bare = tight(&dressed(
    plain(),
    ElectionBackend::of(GraphqlKind::AsyncGraphql),
  ));

  assert_eq!(dressed_up, bare, "an unspent word reached the expansion");
  for absent in ["ClipAgreement", "ClipLeader"] {
    assert!(
      !dressed_up.contains(absent),
      "`{absent}` landed on a road with no fused answer: {dressed_up}",
    );
  }
}