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
//! THE FUSION TREE, read off its tokens — the binding table, the de-Option law, the fractal's
//! descent and the presence law's ABSENCES.
//!
//! Models built by hand, this crate's own rule: nothing here parses a declaration, because an
//! emitter that could only be driven from a `DeriveInput` is an emitter a manifest front end could
//! not reach.
//!
//! What a package DOES — that a client can build one, that it crosses the wire, that the fold word
//! reaches the fold TYPE — is asserted where the emission can be run, in `ingraph`'s own
//! `tests/fusion_spine.rs`. What is here is what a token stream can be read for.

use crate::{
  engine::{Engine, FieldEngines},
  index::{Dedup, Elected, ElectionLabel, Fold, IndexGraphql, IndexModel, Upstream},
  model::{GraphqlKind, NodeKind},
  prefix::EmissionPrefix,
};

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

/// An election as the derive builds one — the label decides whether a fold vocabulary is minted.
fn elected(field: &str, label: ElectionLabel, fold: Option<Fold>) -> Elected {
  Elected::new(
    ident(field),
    label,
    syn::parse_quote!(::ingraph::Embedding<f32, 4, Clip>),
    fold,
  )
}

/// A set election, whose `ty` is the collection the label states.
fn set(field: &str, fold: Option<Fold>) -> Elected {
  Elected::new(
    ident(field),
    ElectionLabel::List,
    syn::parse_quote!(::std::vec::Vec<::ingraph::Embedding<f32, 4, Clip>>),
    fold,
  )
}

fn engines(field: &str, words: &[&str], fanout: bool) -> FieldEngines {
  FieldEngines {
    field: ident(field),
    engines: words.iter().map(|word| Engine::bare(ident(word))).collect(),
    fanout,
  }
}

fn index(name: &str, kind: NodeKind) -> IndexModel {
  IndexModel {
    prefix: EmissionPrefix::default(),
    numbers: crate::index::Numbers::default(),
    field_numbers: Vec::new(),
    index: ident(name),
    kind,
    vis: syn::parse_quote!(pub),
    krate: syn::parse_quote!(::ingraph),
    source: Upstream {
      node: syn::parse_quote!(Caption),
      projections: Vec::new(),
    },
    dedup: Dedup::Hash,
    embeddings: Vec::new(),
    labelled: Vec::new(),
    searchable: Vec::new(),
    engines: Vec::new(),
    stores: Vec::new(),
    extension: None,
    data: false,
    keys: false,
    subscribe: false,
    graphql: Some(IndexGraphql::of(GraphqlKind::AsyncGraphql)),
    rename: None,
    slot: None,
    fields: Vec::new(),
  }
}

/// A VECTOR declaration electing one field, written to one engine — the flat leaf.
pub(super) fn one_slot() -> IndexModel {
  let mut model = index("Captions", NodeKind::Vector);
  model.embeddings = vec![elected("image_embedding", ElectionLabel::Embedding, None)];
  model.engines = vec![engines("image_embedding", &["hnsw"], false)];
  model
}

/// A VECTOR declaration electing TWO fields — the multi-route tier.
pub(super) fn two_slots() -> IndexModel {
  let mut model = index("Frames", NodeKind::Vector);
  model.embeddings = vec![
    set(
      "frames",
      Some(Fold::Custom(syn::parse_quote!(app::PositionWeighted))),
    ),
    elected("poster", ElectionLabel::Embedding, None),
  ];
  model.engines = vec![
    engines("frames", &["hnsw"], false),
    engines("poster", &["hnsw"], false),
  ];
  model
}

/// A VECTOR declaration whose ONE election is FANNED across two engines — the fractal's next level.
pub(super) fn fanned() -> IndexModel {
  let mut model = index("Shots", NodeKind::Vector);
  model.embeddings = vec![elected("clip", ElectionLabel::Embedding, None)];
  model.engines = vec![engines("clip", &["hnsw", "lance"], true)];
  model
}

/// A FULL-TEXT declaration — one subject, two elected fields, one route.
pub(super) fn fulltext() -> IndexModel {
  let mut model = index("Transcript", NodeKind::Fulltext);
  model.searchable = vec![ident("body"), ident("title")];
  model.engines = vec![
    engines("body", &["tantivy"], false),
    engines("title", &["tantivy"], false),
  ];
  model
}

/// A BLOB family — the kind that does not retrieve.
pub(super) fn blob() -> IndexModel {
  let mut model = index("Posters", NodeKind::Blob);
  model.stores = vec![Engine::bare(ident("fs"))];
  model
}

/// The tier's tokens with every space taken out — what a claim about a TYPE or a word is read off.
///
/// The TOKEN STREAM rather than the formatted file, and the difference is load-bearing: a formatter
/// wraps a long generic and leaves a trailing comma inside it, so `Option<Route<T>>` reads back as
/// `Option<Route<T>,>` and every assertion about a shape would be an assertion about a line width.
fn compact(model: &IndexModel) -> String {
  model.tier().emit().to_string().split_whitespace().collect()
}

/// The tier's tokens, formatted — what a failing claim prints.
fn rendered(model: &IndexModel) -> String {
  let tokens = model.tier().emit();
  syn::parse2::<syn::File>(tokens.clone())
    .map_or_else(|_| tokens.to_string(), |file| prettyplease::unparse(&file))
}

// -------------------------------------------------------------------------------------------------
// THE BINDING TABLE
// -------------------------------------------------------------------------------------------------

/// **THE BINDING TABLE, all four rows.** A parent absorbs whichever shape a member has through ONE
/// projection, so which shape that is has to be decided in exactly one place — here.
#[test]
fn the_binding_table_picks_one_package_per_tier_shape() {
  assert_eq!(
    one_slot()
      .tier()
      .options_name()
      .map(|name| name.to_string()),
    Some("CaptionsImageEmbeddingVectorOptions".to_owned()),
    "a single-slot vector tier IS its leaf",
  );
  assert_eq!(
    fanned().tier().options_name().map(|name| name.to_string()),
    Some("ShotsClipFuseOptions".to_owned()),
    "a fanned slot is a tier, not a leaf",
  );
  assert_eq!(
    two_slots()
      .tier()
      .options_name()
      .map(|name| name.to_string()),
    Some("FramesFuseOptions".to_owned()),
    "several elections fuse",
  );
  assert_eq!(
    fulltext()
      .tier()
      .options_name()
      .map(|name| name.to_string()),
    Some("TranscriptFulltextOptions".to_owned()),
    "a full-text declaration has ONE subject however many fields it elects",
  );
}

/// The question tree is ISOMORPHIC, so its binding table is the same table — a sister package per
/// tier, picked by the same shape.
#[test]
fn the_question_tree_binds_by_the_same_table() {
  assert_eq!(
    one_slot()
      .tier()
      .question_name()
      .map(|name| name.to_string()),
    Some("CaptionsImageEmbeddingVectorQuestion".to_owned()),
  );
  assert_eq!(
    fanned().tier().question_name().map(|name| name.to_string()),
    Some("ShotsClipVectorQuestion".to_owned()),
    "the legs are ONE field's coordinates in several stores, so the question does not descend",
  );
  assert_eq!(
    two_slots()
      .tier()
      .question_name()
      .map(|name| name.to_string()),
    Some("FramesFuseQuestion".to_owned()),
  );
  assert_eq!(
    fulltext()
      .tier()
      .question_name()
      .map(|name| name.to_string()),
    Some("TranscriptFulltextQuestion".to_owned()),
  );
}

/// **THE PROJECTION IS SPELLED, and the emitter resolves nothing.** The impl is the one item a
/// parent ever reaches.
#[test]
fn every_retrieving_tier_binds_both_seats_through_fusable() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("::retrieve::FusableforFrames"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("typeOptions=FramesFuseOptions;"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("typeQuestion=FramesFuseQuestion;"),
    "{}",
    rendered(&two_slots()),
  );
}

// -------------------------------------------------------------------------------------------------
// THE MODALITY PRESENCE LAW — asserted as ABSENCES
// -------------------------------------------------------------------------------------------------

/// **A FULL-TEXT DECLARATION EMITS NOTHING VECTOR-FLAVOURED.** Not an empty package and not one
/// behind a bound nobody satisfies — no type at all.
#[test]
fn a_fulltext_tier_emits_no_vector_flavoured_type() {
  let emitted = compact(&fulltext());

  for absent in [
    "VectorOptions",
    "VectorQuestion",
    "Semantics",
    "coordinates",
  ] {
    assert!(
      !emitted.contains(absent),
      "`{absent}` reached a full-text declaration:\n{}",
      rendered(&fulltext()),
    );
  }
  assert!(
    emitted.contains("structTranscriptFulltextOptions"),
    "{}",
    rendered(&fulltext())
  );
}

/// The law's other half: a vector declaration emits nothing full-text-flavoured.
#[test]
fn a_vector_tier_emits_no_fulltext_flavoured_type() {
  let emitted = compact(&two_slots());

  assert!(
    !emitted.contains("FulltextOptions"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    !emitted.contains("FulltextQuestion"),
    "{}",
    rendered(&two_slots()),
  );
}

/// **A NON-RETRIEVING MEMBER GETS NO `Fusable` IMPL**, which is what makes its absence from a
/// parent's package a COMPILE fact rather than a silently empty field.
#[test]
fn a_blob_family_emits_no_fusion_tree_at_all() {
  assert!(compact(&blob()).is_empty(), "{}", rendered(&blob()),);
  assert_eq!(blob().tier().options_name(), None);
  assert_eq!(blob().tier().question_name(), None);
}

// -------------------------------------------------------------------------------------------------
// THE DE-OPTION LAW
// -------------------------------------------------------------------------------------------------

/// **EVERY ROW OF EVERY PACKAGE DEFERS, so every row is an `Option`.** The two fields that do NOT
/// defer are on `Route`, where they are bare — asserted here by the absence of any bare row.
#[test]
fn every_package_row_is_an_option_because_every_one_defers() {
  let emitted = compact(&two_slots());

  for row in [
    "semantics:::core::option::Option<FramesFramesSemantics>",
    "fusion:::core::option::Option<::ingraph::__private::retrieve::FusionOptions>",
    "question:::core::option::Option<::std::string::String>",
  ] {
    assert!(
      emitted.contains(row),
      "`{row}` is missing:\n{}",
      rendered(&two_slots()),
    );
  }
}

/// The factory chain: `new()` names nothing, `Default` delegates to it, and one `with_*`/reader pair
/// rides each row — the options pattern whole.
#[test]
fn a_package_is_an_options_pattern_whole() {
  let emitted = compact(&one_slot());

  assert!(
    emitted.contains("constfnnew()->Self"),
    "{}",
    rendered(&one_slot())
  );
  // RESPELLED onto a row that survives the wall law: `ceiling` was this fixture's only row before
  // it retired, and what a package that names nothing has to say is said by whichever row it does
  // carry. The claim is the FACTORY CHAIN — `new()` fills every row with `None` — and it is read at
  // the two-slot fixture, whose leaf keeps a fold word.
  assert!(
    compact(&two_slots()).contains("semantics:::core::option::Option::None"),
    "`new()` names nothing:\n{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("fndefault()->Self{Self::new()}"),
    "{}",
    rendered(&one_slot()),
  );
  // THE `with_*`/reader PAIR, read at the fixture that still has a row to carry one — `ceiling`
  // was this pair's subject and retired with the wall law, and the pattern it demonstrated is what
  // survives: one setter and one reader per row, the reader answering an `Option` reference.
  let two = compact(&two_slots());
  assert!(two.contains("fnwith_semantics(mutself,"), "{two}");
  assert!(
    two.contains("constfnsemantics(&self)->::core::option::Option<&FramesFramesSemantics>"),
    "{two}",
  );
  // AND THE ROWLESS PACKAGE IS STILL WHOLE: a declaration whose leaf has nothing left to carry gets
  // `new`, `Default` and no accessors — which is the options pattern at its degenerate arity rather
  // than a package that failed to be emitted.
  assert!(
    emitted.contains("pubstructCaptionsImageEmbeddingVectorOptions{}"),
    "{}",
    rendered(&one_slot()),
  );
}

// -------------------------------------------------------------------------------------------------
// THE FRACTAL
// -------------------------------------------------------------------------------------------------

/// **EVERY ROUTE WEARS `Route`** — a slot route and a child-tier route alike, which is what makes
/// the tree fractal rather than two shapes that happen to nest.
#[test]
fn every_route_of_a_tier_wears_the_edge_wrapper() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("frames:::core::option::Option<::ingraph::__private::retrieve::Route<FramesFramesVectorOptions>>"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("poster:::core::option::Option<::ingraph::__private::retrieve::Route<FramesPosterVectorOptions>>"),
    "{}",
    rendered(&two_slots()),
  );
}

/// **A FANNED SLOT DESCENDS ONE MORE LEVEL**: a leg package per engine, and a mini tier with its own
/// fusion flavour fusing them. The parent above it changes in nothing.
#[test]
fn a_fanned_slot_becomes_a_tier_with_one_route_per_leg() {
  let emitted = compact(&fanned());

  assert!(
    emitted.contains("structShotsClipHnswLegOptions"),
    "{}",
    rendered(&fanned())
  );
  assert!(
    emitted.contains("structShotsClipLanceLegOptions"),
    "{}",
    rendered(&fanned())
  );
  assert!(
    emitted.contains("structShotsClipFuseOptions"),
    "{}",
    rendered(&fanned())
  );
  assert!(
    emitted.contains(
      "hnsw:::core::option::Option<::ingraph::__private::retrieve::Route<ShotsClipHnswLegOptions>>"
    ),
    "{}",
    rendered(&fanned()),
  );
  assert!(
    emitted.contains("lance:::core::option::Option<::ingraph::__private::retrieve::Route<ShotsClipLanceLegOptions>>"),
    "{}",
    rendered(&fanned()),
  );
  assert!(
    emitted
      .contains("fusion:::core::option::Option<::ingraph::__private::retrieve::FusionOptions>"),
    "a mini tier carries its own algorithm:\n{}",
    rendered(&fanned()),
  );
}

/// A PORTABLE field — several engines declared, one of them opened — is NOT fanned, so it stays a
/// leaf. The exclusion matters: an emission that descended by default would pass an inclusion-only
/// suite while minting a tier for every declaration that named two engines.
#[test]
fn a_portable_slot_stays_a_leaf() {
  let mut model = fanned();
  model.engines = vec![engines("clip", &["hnsw", "lance"], false)];
  let emitted = compact(&model);

  assert!(!emitted.contains("LegOptions"), "{}", rendered(&model),);
  assert!(
    emitted.contains("structShotsClipVectorOptions"),
    "{}",
    rendered(&model)
  );
}

/// A ONE-ROUTE tier IS its route: a fuse package above one route would be a fold over a list of one,
/// and the parent absorbs the leaf directly.
///
/// THE WITNESS IS THE FIRST ASSERTION and not decoration. Two absences alone are a test that passes
/// when the naming rule moves — `CaptionsFuseOptions` is a name nothing in the tree mints, so a
/// suffix renamed tomorrow leaves both `!contains` true and this test green over an emission that
/// grew the very package it forbids. What pins the rule is the LEAF package, whose name is built by
/// the same rule at the same grain: it must be there, and the fuse pair must not.
#[test]
fn a_one_route_tier_mints_no_fuse_package() {
  let emitted = compact(&one_slot());

  assert!(
    emitted.contains("pubstructCaptionsImageEmbeddingVectorOptions"),
    "the leaf package the absences are measured against is missing:\n{}",
    rendered(&one_slot()),
  );
  assert!(
    !emitted.contains("CaptionsFuseOptions"),
    "{}",
    rendered(&one_slot()),
  );
  assert!(
    !emitted.contains("CaptionsFuseQuestion"),
    "{}",
    rendered(&one_slot()),
  );
}

// -------------------------------------------------------------------------------------------------
// THE WIRE FOLD VOCABULARY — the ⑥叉四 enum's birth
// -------------------------------------------------------------------------------------------------

/// **THE VOCABULARY IS MINTED PER ELECTION**, which is `semantics`' own ruling: the framework's
/// vocabulary IS the trait, so a closed enum can exist only where the set is closed — at a
/// declaration whose `semantics(fold = …)` word says which folds this election has.
#[test]
fn a_set_election_mints_the_wire_fold_vocabulary() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("enumFramesFramesSemantics{"),
    "{}",
    rendered(&two_slots())
  );
  for variant in ["Sum,", "Max,", "PositionWeighted,"] {
    assert!(
      emitted.contains(variant),
      "`{variant}` is missing:\n{}",
      rendered(&two_slots()),
    );
  }
}

/// **THE DECLARED CUSTOM IS A THIRD WORD, not a replacement.** A declaration naming its own fold
/// does not take `Sum` and `Max` away from a client who asks for one; what it sets is `DECLARED`.
#[test]
fn a_declared_fold_joins_the_citizens_and_becomes_the_default() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("constDECLARED:Self=Self::PositionWeighted;"),
    "{}",
    rendered(&two_slots()),
  );
}

/// An election that named no fold declares the shipped citizen — the ruled chain's last tier,
/// stated in the emission rather than left to a caller.
#[test]
fn an_election_naming_no_fold_declares_the_shipped_citizen() {
  let mut model = two_slots();
  model.embeddings = vec![set("frames", None)];
  model.engines = vec![engines("frames", &["hnsw"], false)];
  let emitted = compact(&model);

  assert!(
    emitted.contains("constDECLARED:Self=Self::Sum;"),
    "{}",
    rendered(&model),
  );
  assert!(
    !emitted.contains("PositionWeighted"),
    "an election that named nothing mints no custom word:\n{}",
    rendered(&model),
  );
}

/// A SINGLE election has no fold — the pair asks with one vector, and `m = 1` needs no fold — so it
/// mints no vocabulary either. A word nothing spends is a promise rather than a rule.
#[test]
fn a_single_election_mints_no_fold_vocabulary() {
  let emitted = compact(&one_slot());

  assert!(!emitted.contains("Semantics"), "{}", rendered(&one_slot()));
  assert!(!emitted.contains("semantics:"), "{}", rendered(&one_slot()));
}

/// **THE WORD CROSSES BACK TO THE TYPE THROUGH A VISITOR**, because the arms produce different
/// types: a `match` handing each arm's fold to a generic `visit` monomorphizes into its own body,
/// where a returned value would have had to be one type or a `Box<dyn …>`.
#[test]
fn the_fold_word_crosses_back_through_a_visitor() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("fnwith_fold<__INGRAPH_SCORE__,__INGRAPH_VISITOR__>"),
    "{}",
    rendered(&two_slots()),
  );
  for arm in [
    "Self::Sum=>::ingraph::__private::retrieve::FoldVisitor::visit(__ingraph_visitor,<::ingraph::__private::retrieve::Sumas::core::default::Default>::default())",
    "Self::Max=>::ingraph::__private::retrieve::FoldVisitor::visit(__ingraph_visitor,<::ingraph::__private::retrieve::Maxas::core::default::Default>::default())",
    "Self::PositionWeighted=>::ingraph::__private::retrieve::FoldVisitor::visit(__ingraph_visitor,<app::PositionWeightedas::core::default::Default>::default())",
  ] {
    assert!(
      emitted.contains(arm),
      "the arm is missing:\n{}",
      rendered(&two_slots()),
    );
  }
}

/// The wire words are SCREAMING_SNAKE — the GraphQL namespace's own default casing in this grammar,
/// reached rather than restated.
#[test]
fn the_fold_words_render_in_the_graphql_namespaces_casing() {
  let emitted = compact(&two_slots());

  for word in [
    r#"name:"SUM""#,
    r#"name:"MAX""#,
    r#"name:"POSITION_WEIGHTED""#,
  ] {
    assert!(
      emitted.contains(word),
      "`{word}` is missing:\n{}",
      rendered(&two_slots()),
    );
  }
}

// -------------------------------------------------------------------------------------------------
// THE WIRE FACES
// -------------------------------------------------------------------------------------------------

/// Every OPTIONS package crosses the wire as an ordinary input object, hand-written for
/// `emit::wire`'s measured reason: a derive belongs to the type's own declaration, which is written
/// outside the binding gate.
#[test]
fn every_options_package_carries_a_hand_written_input_face() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("::async_graphql::InputTypeforFramesFuseOptions"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("::async_graphql::InputObjectTypeforFramesFuseOptions"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("oneof:false"),
    "a package is an ordinary input object; the @oneOf flag is the FLAVOUR's:\n{}",
    rendered(&two_slots()),
  );
}

/// **THE QUESTION TREE CROSSES, AND `coordinates` IS THE ONE ROW THAT DOES NOT.** Both halves in
/// one test, because they are one decision: a face over the whole package would be `E0277` at the
/// declaration — a vector route's currency is an `Embedding<E, N, S>` and `InputType` is not
/// implemented for it — and no face at all published nothing where the TEXT half was always
/// publishable. So the exclusion is a ROW's rather than a package's.
#[test]
fn the_question_tree_crosses_as_text_and_leaves_its_coordinates_behind() {
  let emitted = compact(&two_slots());

  for faced in [
    "::async_graphql::InputTypeforFramesFuseQuestion",
    "::async_graphql::InputTypeforFramesFramesVectorQuestion",
  ] {
    assert!(emitted.contains(faced), "{}", rendered(&two_slots()));
  }
  // The row is on the STRUCT and absent from the face's three halves — the schema, the write and
  // the read, which fills it with `None` rather than parsing a value no client could send.
  assert!(
    emitted.contains("coordinates:::core::option::Option<"),
    "{}",
    rendered(&two_slots()),
  );
  assert!(
    !emitted.contains("\"coordinates\""),
    "a row with no wire form reached the wire:\n{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("coordinates:::core::option::Option::None"),
    "the read does not fill the absent row:\n{}",
    rendered(&two_slots()),
  );
}

/// **THE ROUTE'S CURRENCY IS THE ELECTION'S POINT, and never its CARRIER.** A carrier is a storage
/// fact a third party may supply for itself; the question is `m` query vectors, which is
/// `Embedding<E, N, S>` for every carrier there will ever be. Projected rather than spelled, so one
/// door shape serves them all — and so a package's derives never reach a declaring crate's own type.
#[test]
fn a_route_is_asked_in_the_elections_own_point() {
  let emitted = compact(&two_slots());

  assert!(
    emitted.contains("coordinates:::core::option::Option<::std::vec::Vec<<::std::vec::Vec<"),
    "the SET election is asked with a set of its points:\n{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("coordinates:::core::option::Option<<::ingraph::Embedding<f32,4,Clip>as"),
    "the SINGLE election is asked with one point:\n{}",
    rendered(&two_slots()),
  );
  assert!(
    emitted.contains("EmbeddingMarker>::Item"),
    "the point is PROJECTED off the carrier:\n{}",
    rendered(&two_slots()),
  );
}

/// The tokens PARSE as a file — the cheapest guard there is against an emission that reads well and
/// is not Rust.
#[test]
fn every_tier_shape_parses_as_a_file() {
  for model in [one_slot(), two_slots(), fanned(), fulltext()] {
    syn::parse2::<syn::File>(model.tier().emit())
      .unwrap_or_else(|error| panic!("the tier parses as a file: {error}"));
  }
}

/// **A CUSTOM WHOSE LAST SEGMENT IS A CITIZEN'S WORD IS REFUSED BY NAME.** `app::Sum` is a different
/// fold from this framework's `Sum` and both want `SUM` on the wire — one vocabulary with two
/// meanings, which is the collision the shipped-word table refuses one family over. Left alone it
/// would have been `E0428` on a type nobody wrote.
#[test]
fn a_custom_fold_colliding_with_a_citizens_word_is_refused_by_name() {
  let mut model = two_slots();
  model.embeddings = vec![set(
    "frames",
    Some(Fold::Custom(syn::parse_quote!(app::Sum))),
  )];
  model.engines = vec![engines("frames", &["hnsw"], false)];
  let emitted = compact(&model);

  assert!(emitted.contains("compile_error!"), "{}", rendered(&model));
  assert!(
    emitted.contains("app::Sum"),
    "the refusal names the path its author wrote:\n{}",
    rendered(&model),
  );
  assert!(
    !emitted.contains("enumFramesFramesSemantics"),
    "no vocabulary is minted beside the refusal:\n{}",
    rendered(&model),
  );
}

/// **TWO ROWS UNDER ONE NAME ARE REFUSED BY NAME.** A package's rows come from two sources — the
/// framework's own words and the declaration's elections and engine words — so a field elected as
/// `fusion` collides with the tier's algorithm row. Left alone it was `E0124` on a struct nobody
/// wrote.
#[test]
fn a_declaration_that_elects_a_framework_word_is_refused_by_name() {
  let mut model = two_slots();
  model.embeddings = vec![
    elected("fusion", ElectionLabel::Embedding, None),
    elected("poster", ElectionLabel::Embedding, None),
  ];
  model.engines = vec![
    engines("fusion", &["hnsw"], false),
    engines("poster", &["hnsw"], false),
  ];
  let emitted = compact(&model);

  assert!(emitted.contains("compile_error!"), "{}", rendered(&model));
  assert!(
    emitted.contains("tworowsnamed`fusion`"),
    "the refusal names the row:\n{}",
    rendered(&model),
  );
}

/// The check is at the ONE place every package is built through, so the QUESTION tree is covered by
/// the same line — an election named `question` collides with its tier's own question row.
#[test]
fn the_question_tree_is_covered_by_the_same_check() {
  let mut model = two_slots();
  model.embeddings = vec![
    elected("question", ElectionLabel::Embedding, None),
    elected("poster", ElectionLabel::Embedding, None),
  ];
  model.engines = vec![
    engines("question", &["hnsw"], false),
    engines("poster", &["hnsw"], false),
  ];

  assert!(
    compact(&model).contains("tworowsnamed`question`"),
    "{}",
    rendered(&model),
  );
}