ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! RECIPE FUSION's own shapes — the migrated suite.
//!
//! Every claim below was made about `graph::fuse` before the ONE HOME move, over the same members,
//! and is restated here about the recipe that now mints them: the packages by projection, the nested
//! evidence, the one root parameter, the mechanism rows, and the depth chain. What is NEW is the
//! two facts the migration created — the tower seats at the search grain, and the declared numbers
//! reaching the fold.
//!
//! What is GONE is the door law's own suite: a recipe LISTS its members, so there is no count for a
//! law to read and no trim for a claim to be about.

use core::num::NonZeroU32;

use super::SearchModel;
use crate::{
  index::Dedup,
  search::{ArmModel, MemberModel, SeatModel, SharedBinding, SharedBridge},
};

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

/// A member reading `ty`, with nothing declared about its route and no tower bound.
pub(super) fn member(field: &str, ty: &str) -> MemberModel {
  MemberModel {
    field: ident(field),
    ty: syn::parse_str(ty).expect("a member type"),
    weight: None,
    depth: None,
    floor: None,
    arms: Vec::new(),
  }
}

/// One arm of a member's question, bound to `tower`.
pub(super) fn arm(name: &str, tower: &str) -> ArmModel {
  ArmModel {
    name: ident(name),
    tower: syn::parse_str(tower).expect("a tower type"),
    shared: None,
    floor: None,
  }
}

/// A recipe over `members`, joining under `dedup`.
pub(super) fn recipe(members: Vec<MemberModel>, dedup: Dedup) -> SearchModel {
  SearchModel {
    krate: syn::parse_quote!(::ingraph),
    vis: syn::parse_quote!(pub),
    name: ident("TravelSearch"),
    seats: Vec::new(),
    dedup,
    limit: None,
    graphql: None,
    members,
  }
}

/// The emission with its spaces taken out — what a claim about a type or a row is read off.
pub(super) fn tight(model: &SearchModel) -> String {
  model.fuse().to_string().split_whitespace().collect()
}

/// The two members every migrated claim below is made over.
fn travel() -> SearchModel {
  recipe(
    vec![member("subs", "media::Subs"), member("shots", "Shots")],
    Dedup::Hash,
  )
}

/// **THE PACKAGES ARE MINTED BY PROJECTION** — a recipe names no member's package type, so a
/// third-party member joins with no edit here. Migrated verbatim from the root's own suite.
#[test]
fn the_recipe_packages_hold_their_members_by_projection() {
  let emitted = tight(&travel());
  assert!(
    emitted.contains("structTravelSearchFuseOptions"),
    "{emitted}",
  );
  assert!(
    emitted.contains("media::Subsas::ingraph::__private::retrieve::Fusable>::Options"),
    "the member's package is named rather than projected: {emitted}",
  );
  assert!(
    emitted.contains("structTravelSearchFuseQuestion"),
    "{emitted}",
  );
  assert!(
    emitted.contains("fnwith_subs") && emitted.contains("fnwith_shots"),
    "a member lost its seat: {emitted}",
  );
}

/// **THE EVIDENCE IS NESTED AND PER MEMBER**, one parameter each, so the recipe opens nothing.
#[test]
fn the_evidence_carries_each_members_own() {
  let emitted = tight(&travel());
  assert!(
    emitted.contains(
      "enumTravelSearchFusedEvidence<__INGRAPH_EVIDENCE_SUBS__,__INGRAPH_EVIDENCE_SHOTS__,>"
    ),
    "{emitted}",
  );
  assert!(
    emitted.contains("enumTravelSearchFusedError<__INGRAPH_ERROR_SUBS__,__INGRAPH_ERROR_SHOTS__,>"),
    "{emitted}",
  );
  assert!(
    emitted.contains("Subs(__INGRAPH_EVIDENCE_SUBS__)"),
    "{emitted}",
  );
}

/// **THE ROOT IS A PARAMETER**, bound equal across every member — two members answering two key
/// types have no root to be fused at, and the equality bound is what says so.
#[test]
fn every_member_is_bound_to_one_root() {
  let emitted = tight(&travel());
  assert_eq!(
    emitted.matches("Root=__INGRAPH_ROOT__").count(),
    2,
    "a member is not bound to the root the others answer in: {emitted}",
  );
}

/// **THE WORD-COUNT DOOR LAW IS GONE, AND A ONE-MEMBER RECIPE STILL MINTS ITS DOOR** — which is the
/// migration's own claim: a root emitted nothing below two members because its members arrived by a
/// word, and a recipe's arrive by a list.
///
/// The root's `a_root_with_nothing_to_fuse_mints_nothing` is this test's ancestor, and its assertion
/// is INVERTED here on purpose rather than dropped.
#[test]
fn one_member_is_a_recipe_and_mints_its_door() {
  let emitted = tight(&recipe(vec![member("subs", "Subs")], Dedup::Hash));
  assert!(emitted.contains("asyncfnfuse"), "{emitted}");
  assert!(
    emitted.contains("structTravelSearchFuseOptions"),
    "{emitted}"
  );
}

/// **NO TRIM, NO TYPED DOOR, NO MARKER DEMAND** — the retirement, asserted where it would show.
///
/// A recipe mints ONE door called `fuse`, and neither modality marker appears anywhere in its
/// emission. The root's `the_trim_is_what_puts_the_marker_in_a_where_clause` is what this replaces.
#[test]
fn a_recipe_mints_one_door_over_the_uniform_seam() {
  let emitted = tight(&travel());
  assert_eq!(
    emitted.matches("asyncfn").count(),
    1,
    "a recipe minted more than the one door its member list describes: {emitted}",
  );
  assert!(
    !emitted.contains("vector_fuse") && !emitted.contains("fulltext_fuse"),
    "a typed door survived the trim's retirement: {emitted}",
  );
  // The two modality markers were struck from `ingraph` on 2026-08-19, so a pin naming them here
  // would pass over any emission at all. What is asserted instead is the LIVE seam the door does
  // demand: one uniform `AsyncFusedRead` road, which is the shape a typed door's return would have
  // broken.
  assert!(
    emitted.contains("AsyncFusedRead"),
    "the door reaches its members through something other than the uniform seam: {emitted}",
  );
}

/// **THE TOWERS SIT AT THE SEARCH GRAIN**, in the recipe's own options tree, reached through
/// `<Tower as DeclaredTower>::StepOptions` and never through a name mangled out of the path.
///
/// It is the DEPLOYMENT's clock that seats here. The request's — `<Tower>SearchOptions` — is
/// published as the wire road's own `options` ARGUMENT and is no row of this tree.
///
/// The whole of what the retired inline `arm(…)` / `chain(…)` form used to spell, now spelled here.
#[test]
fn a_bound_tower_seats_its_options_on_the_recipe() {
  let mut subs = member("subs", "Subs");
  subs.arms.push(arm("zh", "crate::ZhQuery"));
  let mut shots = member("shots", "Shots");
  shots.arms.push(arm("text", "crate::ClipText"));
  shots.arms.push(arm("image", "crate::ClipImage"));
  let emitted = tight(&recipe(vec![subs, shots], Dedup::Hash));

  assert!(
    emitted.contains("structTravelSearchSubsTowerOptions"),
    "the member's tower package is missing: {emitted}",
  );
  assert!(
    emitted.contains("structTravelSearchShotsTowerOptions"),
    "the member's tower package is missing: {emitted}",
  );
  assert!(
    emitted
      .contains("crate::ClipTextas::ingraph::__private::retrieve::DeclaredTower>::StepOptions"),
    "the tower's options are named rather than projected: {emitted}",
  );
  assert!(
    emitted.contains("subs_towers:::core::option::Option<TravelSearchSubsTowerOptions>")
      && emitted.contains("shots_towers:::core::option::Option<TravelSearchShotsTowerOptions>"),
    "the tower package has no seat on the recipe's own options: {emitted}",
  );
}

/// **A MEMBER THAT BINDS NO TOWER MINTS NO TOWER PACKAGE AND TAKES NO SEAT** — the presence law,
/// which is what keeps an empty knob out of every recipe that binds nothing.
#[test]
fn an_unbound_member_mints_no_tower_seat() {
  let emitted = tight(&travel());
  assert!(!emitted.contains("TowerOptions"), "{emitted}");
  assert!(!emitted.contains("_towers"), "{emitted}");
}

/// **THE DECLARED WEIGHT IS WHAT AN UNCONFIGURED MEMBER TAKES** — the word's first declaration-side
/// home, spent.
///
/// MUTATION-CHECKED: leave the fallback at `DEFAULT_WEIGHT` and the first assertion reds; the
/// negative half is what makes the pair a claim rather than a presence check, an emission that wrote
/// the literal somewhere else passing the first alone.
#[test]
fn a_declared_weight_is_the_fold_coefficient_a_request_did_not_name() {
  let mut subs = member("subs", "Subs");
  subs.weight = Some(2.5);
  let emitted = tight(&recipe(vec![subs, member("shots", "Shots")], Dedup::Hash));

  assert!(
    emitted.contains("__ingraph_route,2.5f64,::ingraph::__private::retrieve::Route::weight,"),
    "the declared coefficient is not what an unconfigured member takes: {emitted}",
  );
  assert_eq!(
    emitted.matches("DEFAULT_WEIGHT").count(),
    1,
    "the member that declared a weight still fell back to the framework's own: {emitted}",
  );
}

/// **A DECLARED DEPTH IS THE MIDDLE TIER THE ROOT STRUCTURALLY COULD NOT FILL** — the request's ask,
/// capped by the declaration, cut at the caller's budget.
#[test]
fn a_declared_depth_caps_the_members_own_ask() {
  let mut subs = member("subs", "Subs");
  subs.depth = NonZeroU32::new(50);
  let emitted = tight(&recipe(vec![subs, member("shots", "Shots")], Dedup::Hash));

  assert!(
    emitted.contains("::core::num::NonZeroU32::new(50u32)"),
    "the declared depth never reached the resolution: {emitted}",
  );
  assert_eq!(
    emitted
      .matches("::ingraph::__private::retrieve::route_depth(")
      .count(),
    2,
    "one resolution per member, no more and no fewer: {emitted}",
  );
  assert_eq!(
    emitted.matches("__ingraph_asked,__ingraph_depth,)").count(),
    2,
    "a member was handed something other than its own resolved depth: {emitted}",
  );
}

/// **A RECIPE THAT DECLARED NO NUMBER IS THE ROOT'S OWN BEHAVIOUR EXACTLY** — which is what makes
/// the migration behaviour-preserving where nothing new was written.
#[test]
fn an_undeclared_member_keeps_the_roots_two_tier_chain() {
  let emitted = tight(&travel());
  assert_eq!(
    emitted.matches("DEFAULT_WEIGHT").count(),
    2,
    "an unweighted member stopped taking the multiplicative identity: {emitted}",
  );
  assert_eq!(
    emitted
      .matches("::core::option::Option::None;let__ingraph_depth")
      .count(),
    2,
    "a member with no declared depth stopped deferring to the caller's budget: {emitted}",
  );
  assert!(!emitted.contains("ceiling"), "{emitted}");
}

/// **THE DOOR CARRIES THE FAMILY'S CURRENCY** — the retype the whole door family shares.
#[test]
fn the_door_takes_a_non_zero_budget() {
  let emitted = tight(&travel());
  assert!(
    emitted.contains("limit:::core::num::NonZeroUsize"),
    "{emitted}",
  );
  assert!(!emitted.contains("limit:usize"), "{emitted}");
}

/// **EVERY MEMBER'S SEAT IS A `Route`**, so the wire half of `depth`, `weight` and `enabled` rides
/// inside `Route`'s own single generic impl and there is nothing per-recipe to forget.
#[test]
fn a_members_seat_is_the_edge_and_the_row_rides_inside_it() {
  let emitted = tight(&travel());
  for field in ["subs", "shots"] {
    assert!(
      emitted.contains(&format!(
        "{field}:::core::option::Option<::ingraph::__private::retrieve::Route<"
      )),
      "`{field}` lost its edge seat: {emitted}",
    );
  }
}

/// **A `shared` ARM CHANGES NOTHING THE FUSION UNIT EMITS** — the broadcast is the question layer's,
/// and this round's emission is the fold. Pinned so that the round that builds the question layer
/// has a statement of what it moved.
#[test]
fn the_broadcast_has_not_reached_the_fold_yet() {
  let mut subs = member("subs", "Subs");
  subs.arms.push(ArmModel {
    shared: Some(SharedBinding {
      seat: ident("text"),
      bridge: SharedBridge::Total,
    }),
    ..arm("zh", "crate::ZhQuery")
  });
  let mut plain = member("subs", "Subs");
  plain.arms.push(arm("zh", "crate::ZhQuery"));

  let mut broadcast = recipe(vec![subs], Dedup::Hash);
  broadcast.seats.push(SeatModel {
    name: ident("text"),
    ty: syn::parse_quote!(String),
  });
  assert_eq!(
    tight(&broadcast),
    tight(&recipe(vec![plain], Dedup::Hash)),
    "the fusion unit moved on a word the question layer owns",
  );
}