ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
//! What the RECIPE's QUERY UNIT is, read off the tokens: the two conditions that decide whether it
//! exists at all, the names it lands, the three seams it projects through, and the argument list.
//!
//! Beside [`super::super::bind::tests`] on this directory's one-file-per-thing precedent. What only a
//! real schema can say — that the SDL renders, that a document parses, that dedup makes the answer
//! unique and that the two tiers agree on order — is `ingraph/tests/search_wire_road.rs`.

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

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

fn seat(name: &str) -> SeatModel {
  SeatModel {
    name: ident(name),
    ty: syn::parse_quote!(::std::string::String),
  }
}

fn member(field: &str, ty: &str) -> MemberModel {
  MemberModel {
    field: ident(field),
    ty: syn::parse_str(ty).expect("an index type"),
    weight: None,
    depth: None,
    floor: None,
    arms: Vec::new(),
  }
}

/// A recipe over two members, dressed or not, with whatever seats a case hands it.
fn recipe(seats: Vec<SeatModel>, graphql: Option<GraphqlKind>) -> SearchModel {
  SearchModel {
    krate: syn::parse_quote!(::ingraph),
    vis: syn::parse_quote!(pub),
    name: ident("TravelSearch"),
    seats,
    dedup: Dedup::Hash,
    limit: None,
    graphql,
    members: vec![member("subs", "media::Subs"), member("shots", "Shots")],
  }
}

/// The DRESSED shape every claim below is read off.
fn dressed() -> SearchModel {
  recipe(vec![seat("text")], Some(GraphqlKind::AsyncGraphql))
}

/// ONE BOUND ARM, reading the recipe's own seat across the bridge `word` chose.
fn arm(name: &str, tower: &str, bridge: SharedBridge) -> ArmModel {
  seated("text", name, tower, bridge)
}

/// ONE BOUND ARM on a NAMED seat — the shape a choosing recipe is read off.
fn seated(seat: &str, name: &str, tower: &str, bridge: SharedBridge) -> ArmModel {
  ArmModel {
    name: ident(name),
    tower: syn::parse_str(tower).expect("a tower path"),
    shared: Some(SharedBinding {
      seat: ident(seat),
      bridge,
    }),
    floor: None,
  }
}

/// **THE TWO-SEAT SHAPE** — a `text` mode and a `code` mode, one member's arm bought by each, so
/// every claim about the choice is read off a recipe whose two modes reach DIFFERENT members.
fn choosing() -> SearchModel {
  let mut model = recipe(
    vec![seat("text"), seat("code")],
    Some(GraphqlKind::AsyncGraphql),
  );
  model.members[0].arms = vec![seated(
    "text",
    "words",
    "app::TextTower",
    SharedBridge::Total,
  )];
  model.members[1].arms = vec![seated(
    "code",
    "codes",
    "app::CodeTower",
    SharedBridge::Total,
  )];
  model
}

/// The dressed recipe with a tower bound to its FIRST member and nothing bound to its second — the
/// shape both halves of the crossing law are read off at once.
fn bound(bridge: SharedBridge) -> SearchModel {
  let mut model = dressed();
  model.members[0].arms = vec![arm("zh", "app::ZhTower", bridge)];
  model
}

/// The wire half of the emission with its spaces taken out.
fn tight(model: &SearchModel) -> String {
  model.wire().to_string().split_whitespace().collect()
}

/// EVERY TYPE the wire half lands at MODULE SCOPE — read WITHOUT opening the gate, which is what
/// makes a placement claim a claim.
fn landed(model: &SearchModel) -> Vec<String> {
  let file: syn::File = syn::parse2(model.wire()).expect("the emission parses");
  file
    .items
    .into_iter()
    .filter_map(|item| match item {
      syn::Item::Struct(declared) => Some(declared.ident.to_string()),
      syn::Item::Enum(declared) => Some(declared.ident.to_string()),
      _ => None,
    })
    .collect()
}

/// **A RECIPE THAT NAMED NO BACKEND MINTS NO CITIZENSHIP** — the retrieving family's presence law at
/// the grain above it, and the thing that keeps the wire seams off a Rust-only recipe.
#[test]
fn an_undressed_recipe_mints_nothing() {
  let plain = recipe(vec![seat("text")], None);
  assert!(!plain.mounts());
  assert!(plain.wire().is_empty());
}

/// **A RECIPE WITH NO SEAT MINTS NO FIELD, AND SEVERAL SEATS ARE A ROAD** — the one count the schema
/// still refuses, and the arm that retired when the choice became buildable.
#[test]
fn the_wire_road_needs_at_least_one_seat() {
  let none = recipe(Vec::new(), Some(GraphqlKind::AsyncGraphql));
  assert!(!none.mounts(), "a seatless recipe has nothing to be asked");
  assert!(none.wire().is_empty());

  assert!(dressed().mounts(), "one seat is the road");
  assert!(!dressed().chooses(), "one seat is not a choice");

  let several = recipe(
    vec![seat("text"), seat("point")],
    Some(GraphqlKind::AsyncGraphql),
  );
  assert!(several.mounts(), "several seats publish a choice");
  assert!(several.chooses());
  assert!(!several.wire().is_empty());
}

/// **THE UNIT AND THE SEAT STAND OUTSIDE THE BINDING GATE, and the ANSWER FAMILY inside it.**
///
/// The difference is measured rather than stylistic: `type Query = <Recipe>Queries` is bound in an
/// ungated impl, so the unit has to exist in every build — while the answer types are shaped by
/// `FusedEngine` and `Hydrating`, which are the wire's own seams and exist only behind the binding.
#[test]
fn the_unit_stands_outside_the_gate_and_the_answers_inside_it() {
  let model = dressed();
  assert_eq!(
    landed(&model),
    vec!["TravelSearchQueries".to_owned()],
    "an answer type escaped the gate, or the unit fell inside it",
  );

  let emitted = tight(&model);
  assert!(
    emitted.contains("impl::ingraph::__private::transform::GraphqlforTravelSearch"),
    "{emitted}",
  );
  assert!(
    emitted.contains("typeQuery=TravelSearchQueries;"),
    "{emitted}"
  );
  assert!(
    emitted.contains("typeInput=();") && emitted.contains("typeOutput=();"),
    "the two record-shaped halves stopped being the empty product: {emitted}",
  );
}

/// **THE ANSWER FAMILY IS ONE SIGHTING PER MEMBER, ONE UNION OVER THEM, AND ONE HIT PER TIER.**
#[test]
fn the_answer_family_is_a_sighting_per_member_and_a_hit_per_tier() {
  let emitted = tight(&dressed());
  for owed in [
    "structTravelSearchSubsSighting",
    "structTravelSearchShotsSighting",
    "enumTravelSearchSighting",
    "structTravelSearchKeyMatch",
    "structTravelSearchMatch",
  ] {
    assert!(emitted.contains(owed), "{owed} is missing: {emitted}");
  }
  assert!(
    emitted.contains("Subs(TravelSearchSubsSighting),")
      && emitted.contains("Shots(TravelSearchShotsSighting),"),
    "a member lost its union arm: {emitted}",
  );
}

/// **EVERY CROSS-WALL FACT IS A PROJECTION** — the engine, the root, the entity and each member's
/// evidence. A recipe that named one of them would be guessing inside a declaration it cannot see.
#[test]
fn every_members_fact_is_reached_by_projection() {
  let emitted = tight(&dressed());
  for owed in [
    // WHICH engine a schema asks a member through — the member's own answer.
    "<media::Subsas::ingraph::__private::graphql::FusedEngine>::Engine",
    "<Shotsas::ingraph::__private::graphql::FusedEngine>::Engine",
    // the schema-side read, out of the schema's own citizens
    "::ingraph::__private::graphql::FusedCitizen<",
    // the ROOT, off the FIRST member — the door's own equality proves the rest agree
    "<media::Subsas::ingraph::__private::retrieve::AsyncFusedRead<",
    // both published tiers, off the root
    "::ingraph::__private::graphql::WireRoot>::Address",
    "::ingraph::__private::graphql::WireRoot>::Entity",
  ] {
    assert!(emitted.contains(owed), "{owed} is missing: {emitted}");
  }
  assert!(
    !emitted.contains("SubsEngine") && !emitted.contains("ShotsEngine"),
    "an engine name was mangled out of a member's path: {emitted}",
  );
}

/// **THE THREE ROWS OF A SIGHTING ARE THE FOLD'S OWN THREE**, and the currency crosses as itself
/// through `WireScore` where the two framework numbers cross as themselves.
#[test]
fn a_sighting_publishes_the_currency_the_ordinal_and_the_contribution() {
  let emitted = tight(&dressed());
  assert!(emitted.contains("#[graphql(name=\"score\")]"), "{emitted}");
  assert!(
    emitted.contains("#[graphql(name=\"ordinal\")]"),
    "{emitted}"
  );
  assert!(
    emitted.contains("#[graphql(name=\"contribution\")]"),
    "{emitted}",
  );
  assert!(
    emitted.contains("::ingraph::__private::graphql::WireScore>::Wire<'__ingraph_row>"),
    "the member's currency stopped crossing as itself: {emitted}",
  );
  assert!(
    emitted.contains("__ingraph_contribution"),
    "the contribution stopped being carried out of the sighting: {emitted}",
  );
  assert!(
    !emitted.contains("60.0") && !emitted.contains("1.0/"),
    "the emission recomputed a number the fold already held: {emitted}",
  );
}

/// **THE UNION IS WRITTEN OUT** — three impls by hand, because a derive is written ON a declaration and
/// this one is inside a gate whose predicate no declaring crate can name.
#[test]
fn the_union_is_written_out_rather_than_derived() {
  let emitted = tight(&dressed());
  for owed in [
    "resolver_utils::ContainerTypeforTravelSearchSighting",
    "OutputTypeforTravelSearchSighting",
    "UnionTypeforTravelSearchSighting",
    "registry::MetaTypeId::Union",
  ] {
    assert!(emitted.contains(owed), "{owed} is missing: {emitted}");
  }
  assert!(
    !emitted.contains("derive(::ingraph::async_graphql::Union"),
    "a derive reached the emission: {emitted}",
  );
}

/// **THE TIER NOUN IS THE NAME, AND THE BARE NAME IS THE HYDRATED TWIN** — the retrieving family's own
/// naming law with the election position empty.
#[test]
fn the_two_fields_wear_the_tier_noun_law() {
  let emitted = tight(&dressed());
  assert!(
    emitted.contains("#[graphql(name=\"travelSearchKeys\")]"),
    "{emitted}",
  );
  assert!(
    emitted.contains("#[graphql(name=\"travelSearch\")]"),
    "{emitted}",
  );
  assert_eq!(
    dressed().field_name(true),
    "travelSearchKeys",
    "the keys tier lost its noun",
  );
  assert_eq!(dressed().field_name(false), "travelSearch");
}

/// **THE BROADCAST IS THE ARGUMENT, UNDER THE SEAT'S OWN NAME AND ITS OWN TYPE** — beside the two
/// preference numbers §4 says cross the wire, and no protective one.
///
/// # The `ceiling` guard is spelled at the ARGUMENT and no longer as a substring
///
/// It used to be `!emitted.contains("ceiling")` over the whole emission, and the paging round is
/// what showed the form to be wrong rather than merely strict: a paged road names the KEEPER's
/// depth wall in a local while composing it, and a local is not a surface. What the law forbids is
/// a protective number a CLIENT can write, so the check now reads the one place a client's word
/// lands — and it is not weaker for it, because the coarse form never distinguished the two.
#[test]
fn the_arguments_are_the_seat_and_the_two_numbers() {
  let emitted = tight(&dressed());
  assert!(emitted.contains("#[graphql(name=\"text\")]"), "{emitted}");
  assert!(
    emitted.contains("#[graphql(name=\"first\",default=20i32)]")
      || emitted.contains("#[graphql(name=\"first\",default=20)]"),
    "{emitted}",
  );
  assert!(emitted.contains("#[graphql(name=\"depth\")]"), "{emitted}");
  assert!(
    !emitted.contains("#[graphql(name=\"ceiling\")]"),
    "a protective number reached the wire: {emitted}",
  );
  assert!(
    !emitted.contains("#[graphql(name=\"capacity\")]")
      && !emitted.contains("#[graphql(name=\"ttl\")]"),
    "a keeper knob whose grain is the STORE reached a question's surface: {emitted}",
  );
}

/// **THE DECLARED `limit` IS THE SDL DEFAULT**, which is the ruling `DeclaredSearch::LIMIT` exists for:
/// the number is written into the schema at expansion and no door, seam or fold reads it back.
#[test]
fn the_declared_limit_becomes_the_published_default() {
  let mut model = dressed();
  model.limit = core::num::NonZeroU32::new(7);
  let emitted = tight(&model);
  assert!(
    emitted.contains("default=7i32") || emitted.contains("default=7)"),
    "{emitted}",
  );

  // AND THE FRAMEWORK'S OWN NUMBER WHERE THE WORD WAS OMITTED — a deferral resolved at the one tier
  // that has to answer, rather than a default written into the model.
  assert_eq!(dressed().wire_first(), crate::index::FRAMEWORK_LIMIT);
}

/// **THE EDGE-ZERO LAW IS ANSWERED BEFORE ANY CITIZEN LOOKUP** — `first: 0` is not a smaller question
/// but no question at all, and the door's currency has no zero to be handed.
#[test]
fn a_zero_page_answers_before_the_door() {
  let emitted = tight(&dressed());
  let at_zero = emitted
    .find("NonZeroU32::new(__ingraph_first)")
    .expect("the edge-zero read is emitted");
  let at_read = emitted
    .find("FusedCitizen<")
    .expect("the members are asked through the citizen seam");
  assert!(
    at_zero < at_read,
    "the zero read happens after a citizen lookup: {emitted}",
  );
}

/// **THE HYDRATED TIER IS THE KEYS TIER PLUS ONE STEP**, over ONE fold — so the answers cannot come
/// to disagree about what was asked.
///
/// FOUR published fields now share it, through TWO entries: the two unpaged tiers call `ask`
/// directly and the two paged tiers call `stretch`, which calls `ask` once on a CAPTURE and not at
/// all on a resume. So the declaration plus three call sites, and still exactly one fold written.
#[test]
fn both_fields_run_one_fold() {
  let emitted = tight(&dressed());
  assert_eq!(
    emitted.matches("fuse_weighted::<_,_,").count(),
    1,
    "the fold is written twice: {emitted}",
  );
  assert_eq!(
    emitted.matches("__ingraph_travel_search_ask(").count(),
    4,
    "the shared entry is not what the unpaged fields and the capture call: {emitted}",
  );
  assert_eq!(
    emitted.matches("__ingraph_travel_search_stretch(").count(),
    3,
    "the paged entry is not what both paged fields call: {emitted}",
  );
  assert_eq!(
    emitted.matches("WireRoot>::hydrate(").count(),
    2,
    "the hydrated tiers stopped hydrating: {emitted}",
  );
  assert!(
    emitted.contains("Iterator::filter_map"),
    "a hole stopped being dropped: {emitted}",
  );
}

/// **THE PAGED TWINS ARE ADDITIVE, AND THE UNPAGED PAIR KEEPS ITS NON-NULL SEAT** — the
/// absence-identity pin at the token grain, which the SDL half in `ingraph/tests/search_stretch.rs`
/// cannot say about the tokens themselves.
#[test]
fn the_paged_tier_is_a_second_pair_rather_than_a_change_to_the_first() {
  let model = dressed();
  assert_eq!(model.stretch_field_name(true), "travelSearchKeysStretch");
  assert_eq!(model.stretch_field_name(false), "travelSearchStretch");
  assert_eq!(
    model.stretch_name(true).to_string(),
    "TravelSearchKeyStretch"
  );
  assert_eq!(model.stretch_name(false).to_string(), "TravelSearchStretch");

  let emitted = tight(&model);
  for word in [
    "#[graphql(name=\"travelSearchKeys\")]",
    "#[graphql(name=\"travelSearch\")]",
    "#[graphql(name=\"travelSearchKeysStretch\")]",
    "#[graphql(name=\"travelSearchStretch\")]",
  ] {
    assert!(emitted.contains(word), "{word} missing from {emitted}");
  }
  // THE SEAT IS NAMED FOUR TIMES and only the paged two wrap it in an `Option` — the two modes,
  // written where a reader can count them.
  assert_eq!(
    emitted.matches("#[graphql(name=\"text\")]").count(),
    4,
    "the seat is not on all four fields: {emitted}",
  );
  assert_eq!(
    emitted
      .matches("#[graphql(name=\"text\")]__async_graphql_text:::core::option::Option<")
      .count(),
    2,
    "the paged seat is not the nullable one, or the unpaged seat became nullable: {emitted}",
  );
  // THE ARGUMENT AND THE FIELD FORK: `pageToken` on each paged field, `nextPageToken` on each
  // stretch answer — the asymmetry the ruling wants read back out of the emission. Counted apart
  // rather than pooled, because a regression that collapsed the two spellings into one could
  // still total four hits under a single naive count.
  assert_eq!(
    emitted
      .matches(
        "#[graphql(name=\"pageToken\")]__async_graphql_page_token:::core::option::Option<\
         ::std::string::String>",
      )
      .count(),
    2,
    "the pageToken argument is not on exactly the two paged fields: {emitted}",
  );
  assert_eq!(
    emitted
      .matches("#[graphql(name=\"nextPageToken\")]asyncfn__async_graphql_next_page_token(&self)")
      .count(),
    2,
    "the claim does not ride exactly the two stretch answers: {emitted}",
  );
}

/// **A RESUME REACHES NO CITIZEN**, which is the whole of what the keeper buys: the fold, the tower
/// and every engine call live on the CAPTURE arm, and the read that follows a page token is a cut.
#[test]
fn the_resume_arm_asks_nothing() {
  let emitted = tight(&dressed());
  let stretch = emitted
    .find("asyncfn__ingraph_travel_search_stretch(")
    .expect("the paged entry is emitted");
  let capture = emitted[stretch..]
    .find("__ingraph_travel_search_ask(")
    .expect("the capture arm calls the fold");
  let resume = emitted[stretch..]
    .find("FromStr>::from_str(")
    .expect("the resume arm parses a page token");
  assert!(
    resume < capture,
    "the resume arm reaches the fold: {emitted}",
  );
  assert!(
    emitted.contains("SnapshotKeeper::read::<"),
    "the cut is not the keeper's: {emitted}",
  );
  assert!(
    emitted.contains("installed_keeper("),
    "the paged road does not look a keeper up: {emitted}",
  );
}

/// **THE CAPTURE'S WALL IS THE PIPELINE'S OWN `route_depth`** — one function for every wall here, so
/// the keeper's ceiling cannot come to compose differently from a declaration's.
#[test]
fn the_capture_is_walled_by_the_one_depth_law() {
  let emitted = tight(&dressed());
  // FOUR: one per member edge, the fold's own at the recipe grain, and the capture's. The point
  // is that the CAPTURE's is one of them rather than a fourth kind of arithmetic.
  assert_eq!(
    emitted.matches("route_depth(").count(),
    4,
    "the capture's wall is not the fold's own law: {emitted}",
  );
  assert!(
    emitted.contains("SnapshotKeeper::depth("),
    "the ceiling is not read off the keeper: {emitted}",
  );
}

/// **THE WIRE ROAD AND THE RUST DOOR RESOLVE ONE EDGE THE SAME WAY** — the four numbers come out of
/// one emitter, so the two roads cannot come to disagree about what a recipe declared.
///
/// The door itself is NOT called from the wire road, and that is measured rather than chosen: its
/// parameters are `Ctx<'a>` GATs carrying `where E: 'a`, and calling it from inside an `async fn` is
/// rust-lang/rust#100013. What keeps the two honest is that the NUMBERS come from `member_edge` and
/// the ARITHMETIC from `fuse_weighted`.
#[test]
fn both_roads_splice_one_edge_law() {
  let model = dressed();
  let edge = model
    .member_edge(&model.members[0])
    .to_string()
    .split_whitespace()
    .collect::<String>();

  for road in [
    tight(&model),
    model.fuse().to_string().split_whitespace().collect(),
  ] {
    assert!(
      road.contains(&edge),
      "a road wrote its own edge law: {road}"
    );
  }
}

/// **A BOUND MEMBER'S QUESTION IS WALKED OUT OF ITS TOWER** — the road looked up, run, and its ANSWER
/// put in the broadcast position of the crossing.
///
/// This is the recorded boundary falling, read off the tokens: the arity that could not cross the
/// expansion wall is answered by a call whose arity is fixed.
#[test]
fn a_bound_member_looks_its_road_up_and_runs_it() {
  let emitted = tight(&bound(SharedBridge::Total));

  assert!(
    emitted.contains(
      "let(mut__ingraph_road,__ingraph_knobs,__ingraph_wall)=::ingraph::__private::graphql::\
       installed_road::<app::ZhTower>(__ingraph_ctx,__ingraph_word)?;"
    ),
    "{emitted}"
  );
  assert!(
    emitted.contains(
      "<app::ZhTowaras::ingraph::__private::retrieve::AssembledTower>::run(&mut__ingraph_road,"
    ) || emitted.contains(
      "<app::ZhToweras::ingraph::__private::retrieve::AssembledTower>::run(&mut__ingraph_road,"
    ),
    "{emitted}"
  );
  // THE CROSSING'S BROADCAST IS THE TOWER'S ANSWER, and the value it reads is the one the run gave.
  assert!(
    emitted.contains(
      "TrySharedQuestion<TravelSearchTextSeat,<app::ZhToweras::ingraph::__private::retrieve::\
       SearchTower>::Answer>>::try_from_shared(&__ingraph_answered)"
    ),
    "{emitted}"
  );
  // TIER TWO RIDES THE SAME LOOKUP: the deployment's knobs, out of the door the steps came from.
  assert!(emitted.contains("__ingraph_knobs,"), "{emitted}");
}

/// **THE WALL IS AROUND THE WHOLE RUN** — the budget seat off the same lookup, the tower named for
/// the refusal, and TIER THREE'S SIDE READ OFF THE REQUEST'S OWN PACKAGE.
///
/// Read off the tokens rather than through a schema, because what this pins is WHERE the wrapper
/// sits: outside the uniform run, so every stage of the walk — the fan cells included — is inside it.
/// The request's budget is read through `AssembledTower::asked_budget` because the wall is built
/// AROUND the run and cannot be raised from inside it, and the package itself rides into the run
/// whole.
#[test]
fn a_bound_member_walks_inside_the_budget_its_door_named() {
  let emitted = tight(&bound(SharedBridge::Total));

  assert!(
    emitted.contains(
      "let__ingraph_walked=::ingraph::__private::retrieve::walk_within(__ingraph_wall,<app::\
       ZhToweras::ingraph::__private::retrieve::AssembledTower>::asked_budget(::core::option::\
       Option::as_ref(&__ingraph_request)),::core::any::type_name::<app::ZhTower>(),<app::\
       ZhToweras::ingraph::__private::retrieve::AssembledTower>::run(&mut__ingraph_road,\
       __ingraph_asked,__ingraph_knobs,::core::clone::Clone::clone(&__ingraph_request),),).await;"
    ),
    "{emitted}"
  );
  // THE BUDGET'S OWN ARM, beside the tower's own refusal — a spent walk is SAID and never answered
  // empty.
  assert!(
    emitted.contains("::core::result::Result::Err(__ingraph_spent)=>"),
    "{emitted}"
  );
}

/// **ABSENCE-IDENTITY AT THE RECIPE GRAIN** — a member that binds no tower crosses from the seat
/// itself, with no lookup, no run and no road.
#[test]
fn an_unbound_member_crosses_from_the_seat_exactly_as_it_did() {
  let emitted = tight(&bound(SharedBridge::Total));

  assert!(
    emitted.contains(
      "TrySharedQuestion<TravelSearchTextSeat,::std::string::String>>::try_from_shared(\
       __ingraph_broadcast)"
    ),
    "the second member's crossing moved: {emitted}"
  );
  assert_eq!(
    emitted.matches("installed_road::<").count(),
    1,
    "a member with no arm reached for a road: {emitted}"
  );

  // AND A RECIPE THAT BINDS NOTHING REACHES FOR NOTHING AT ALL — no road, no run, and no wall
  // around a walk it never takes.
  let plain = tight(&dressed());
  assert!(!plain.contains("installed_road"), "{plain}");
  assert!(!plain.contains("AssembledTower"), "{plain}");
  assert!(!plain.contains("walk_within"), "{plain}");
}

/// **THE FOUR BRIDGES ARE THE FOUR THE WORD CHOSE**, each spelled as the call `super::bind` proved —
/// and only the two TRAIT bridges take a copy of the broadcast.
#[test]
fn each_bridge_crosses_the_way_its_word_named() {
  let total = tight(&bound(SharedBridge::Total));
  assert!(
    total.contains(
      "::core::convert::From<_>>::from(::core::clone::Clone::clone(\
                    __ingraph_broadcast))"
    ),
    "{total}"
  );

  let fallible = tight(&bound(SharedBridge::Fallible));
  assert!(
    fallible.contains(
      "::core::convert::TryFrom<_>>::try_from(::core::clone::Clone::clone(\
                       __ingraph_broadcast))"
    ),
    "{fallible}"
  );

  let hooked = tight(&bound(SharedBridge::Hook(syn::parse_quote!(app::cross))));
  assert!(
    hooked.contains("app::cross(__ingraph_broadcast)"),
    "{hooked}"
  );
  assert!(
    !hooked.contains("Clone::clone(__ingraph_broadcast)"),
    "a hook takes the borrow: {hooked}"
  );

  let tried = tight(&bound(SharedBridge::FallibleHook(syn::parse_quote!(
    app::try_cross
  ))));
  assert!(
    tried.contains("matchapp::try_cross(__ingraph_broadcast)"),
    "{tried}"
  );
}

/// **A SINGLE-SEAT RECIPE NEVER MEETS THE CHOICE** — the absence-identity at the token grain: no
/// input type is minted, no `@oneOf` flag is written, and the argument is the seat's own word.
#[test]
fn one_seat_publishes_the_bare_argument_and_no_choice_at_all() {
  let emitted = tight(&dressed());
  assert!(
    !emitted.contains("TravelSearchAskInput"),
    "a one-seat recipe minted a choice: {emitted}",
  );
  assert!(
    !emitted.contains("oneof:true") && !emitted.contains("OneofObjectType"),
    "a one-seat recipe published a `@oneOf`: {emitted}",
  );
  assert!(
    !emitted.contains("#[graphql(name=\"ask\")]"),
    "a one-seat recipe named the choice's argument: {emitted}",
  );
  assert_eq!(
    landed(&dressed()),
    vec!["TravelSearchQueries".to_owned()],
    "a type appeared beside the unit at module scope",
  );
  assert_eq!(
    emitted.matches("#[graphql(name=\"text\")]").count(),
    4,
    "the seat stopped being the argument on all four fields: {emitted}",
  );
}

/// **SEVERAL SEATS MAKE ONE ARGUMENT HOLDING AN `@oneOf`** — one field per seat, under the seat's own
/// word, and the exactly-one rule written as the library writes it.
#[test]
fn several_seats_publish_one_oneof_argument() {
  let model = choosing();
  let emitted = tight(&model);

  // THE TYPE IS A DECLARATION AND IT IS BEHIND THE BINDING GATE, exactly where the answer family
  // sits: it names `InputType`, which is the wire's own seam and exists only behind the binding.
  assert_eq!(
    landed(&model),
    vec!["TravelSearchQueries".to_owned()],
    "the choice escaped the gate, or the unit fell inside it",
  );
  assert!(emitted.contains("pubenumTravelSearchAskInput"), "{emitted}");
  assert!(
    emitted.contains("Text(::std::string::String),")
      && emitted.contains("Code(::std::string::String),"),
    "a seat lost its variant: {emitted}",
  );

  // THE `@oneOf` FLAG AND ITS TWO MARKER IMPLS — the election road's own shape, mirrored.
  assert!(emitted.contains("oneof:true"), "{emitted}");
  assert!(
    emitted.contains("InputObjectTypeforTravelSearchAskInput")
      && emitted.contains("OneofObjectTypeforTravelSearchAskInput"),
    "{emitted}",
  );
  // EXACTLY ONE KEY, and it is the library's own parse rather than a rule this emission invented.
  assert_eq!(
    emitted.matches("__ingraph_object.len()==1").count(),
    2,
    "the exactly-one read is not one per seat: {emitted}",
  );

  // THE SEAT'S OWN WORD SURVIVES THE MOVE — `text:` became `ask: { text: … }`.
  assert!(
    emitted.contains("::std::string::String::from(\"text\")")
      && emitted.contains("::std::string::String::from(\"code\")"),
    "{emitted}",
  );
  assert_eq!(
    emitted.matches("#[graphql(name=\"ask\")]").count(),
    4,
    "the choice is not the argument on all four fields: {emitted}",
  );
  assert!(
    !emitted.contains("#[graphql(name=\"text\")]"),
    "a seat stayed an argument of its own beside the choice: {emitted}",
  );
  // AND THE DERIVE LIST IS EMPTY, because the payloads are the application's own seat types.
  assert!(
    !emitted.contains(
      "#[derive(::core::fmt::Debug,::core::clone::Clone,::core::cmp::PartialEq,)]\
                       pubenumTravelSearchAskInput"
    ),
    "the choice put an obligation on a seat type: {emitted}",
  );
}

/// **THE ARRIVING VARIANT IS THE MODE, AND ONLY ITS MEMBERS ARE ASKED** — the dispatch, read off the
/// tokens: two match arms, each crossing exactly the member whose arm bought that seat.
#[test]
fn each_seat_reaches_only_the_members_whose_arms_bought_it() {
  let emitted = tight(&choosing());

  let text_arm = emitted
    .find("TravelSearchAskInput::Text(__ingraph_broadcast)=>{")
    .expect("the text seat has an arm");
  let code_arm = emitted
    .find("TravelSearchAskInput::Code(__ingraph_broadcast)=>{")
    .expect("the code seat has an arm");
  assert!(text_arm < code_arm, "the arms are out of declaration order");

  // ONE ROAD PER ARM — the member of the OTHER seat contributes no crossing at all, which is how it
  // contributes nothing to this request's fuse.
  let text = &emitted[text_arm..code_arm];
  assert!(text.contains("app::TextTower"), "{text}");
  assert!(
    !text.contains("app::CodeTower"),
    "the code member was asked on a text request: {text}",
  );
  assert_eq!(
    text.matches("try_from_shared(").count(),
    1,
    "the text arm crossed a member it does not reach: {text}",
  );

  let code = &emitted[code_arm..];
  let code = &code[..code
    .find("letquestion=&__ingraph_question;")
    .unwrap_or(code.len())];
  assert!(code.contains("app::CodeTower"), "{code}");
  assert!(
    !code.contains("app::TextTower"),
    "the text member was asked on a code request: {code}",
  );
  assert_eq!(
    code.matches("try_from_shared(").count(),
    1,
    "the code arm crossed a member it does not reach: {code}",
  );

  // AND THE SEAT MARKERS KEY THE TWO CROSSINGS APART, which is what lets one question read two
  // broadcasts without the impls colliding.
  assert!(text.contains("TravelSearchTextSeat,"), "{text}");
  assert!(code.contains("TravelSearchCodeSeat,"), "{code}");
}

/// **THE OTHER THREE ARGUMENTS DO NOT NOTICE THE CHOICE** — `first`, `depth` and `pageToken` ride the
/// same positions in both shapes, so what several seats changed is the question and nothing beside it.
#[test]
fn the_numbers_and_the_page_token_ride_both_shapes() {
  let bare = tight(&dressed());
  let chosen = tight(&choosing());
  for (word, count) in [
    ("#[graphql(name=\"first\",default=", 4),
    ("#[graphql(name=\"depth\")]", 4),
    ("#[graphql(name=\"pageToken\")]", 2),
    ("#[graphql(name=\"nextPageToken\")]", 2),
  ] {
    assert_eq!(bare.matches(word).count(), count, "{word} in {bare}");
    assert_eq!(chosen.matches(word).count(), count, "{word} in {chosen}");
  }
  // THE RESUME NAMES NO SEAT IN EITHER SHAPE: the paged pair's question is nullable, and a captured
  // snapshot already knows which members made it.
  for road in [&bare, &chosen] {
    assert_eq!(
      road
        .matches("__ingraph_broadcast:::core::option::Option<")
        .count(),
      1,
      "the paged entry stopped taking an optional question: {road}",
    );
  }
}

/// **THE FIELD THAT ASKED IS CARRIED**, so a missing road names the tier a deployment has to look at
/// rather than whichever one the emitter happened to freeze.
#[test]
fn each_published_tier_hands_the_fold_its_own_name() {
  let emitted = tight(&bound(SharedBridge::Total));
  assert!(
    emitted.contains("__ingraph_travel_search_ask(__async_graphql_ctx,\"travelSearchKeys\","),
    "{emitted}"
  );
  assert!(
    emitted.contains("__ingraph_travel_search_ask(__async_graphql_ctx,\"travelSearch\","),
    "{emitted}"
  );
}