ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
use async_graphql::InputType;

use super::*;
use crate::{
  BytesFilter, FixedBytesFilter, ListFilter, Nullable, ScalarFilter, SetFilter, TextFilter,
};

/// **The text row's name, and the round trip it took.** The concrete registrations the axis replaced
/// published `StringFilter` and `TextFilter`; the axis carried both across unchanged, the NAMING
/// CONSTITUTION moved the first to lowercase `stringFilter`, and the 2026-08-18 amendment moved it
/// back — `String` is not a roster row at all, GraphQL's own name saying everything there is to say
/// about that operand, where `smol_str::SmolStr` is a NAMED type and keeps its own.
///
/// The moves are the constitution's and not a refactor's, which is the distinction this pin exists
/// to hold: a wire name is a schema commitment, so it moves when a law says so and never when a
/// Rust item is renamed. What never moved is the carrier — see [`Builtin`]'s row, where the ruling
/// is stated.
///
/// There is NO `Std` row beside this one and there cannot be: it would publish the same name over
/// the same operand, which is two Rust types under one GraphQL name and
/// `Registry::create_type`'s own panic. `tests/half_roster.rs` is where that merge is pinned against
/// a built schema.
#[test]
fn the_text_row_takes_the_canonical_name() {
  assert_eq!(
    <TextFilter<String> as InputType>::type_name(),
    "StringFilter"
  );
  assert_eq!(
    <Nullable<TextFilter<String>> as InputType>::type_name(),
    "NullableStringFilter"
  );
}

/// The same pin for the OTHER text type, SPLIT OUT because it names an optional dependency.
///
/// This file is compiled wherever the BINDING is, and `smol_str` is a vocabulary feature a build
/// with the binding need not have asked for — so the two assertions above hold at every such build
/// and these two hold only where the type exists.
///
/// A repair rather than a preference. Before the split, `--features async-graphql` without
/// `smol_str` was `E0433` here, and it had never been noticed because no lane in
/// `ci/test-matrix.sh` enabled the binding at all: `--all-features` has both, and every reduced
/// lane had neither. The batching round's own three-way feature matrix is the first set that has
/// one and not the other.
#[cfg(feature = "smol_str")]
#[test]
fn the_canonical_text_names_survive_the_axis_for_the_second_text_type() {
  assert_eq!(
    <TextFilter<smol_str::SmolStr> as InputType>::type_name(),
    "TextFilter"
  );
  assert_eq!(
    <Nullable<TextFilter<smol_str::SmolStr>> as InputType>::type_name(),
    "NullableTextFilter"
  );
}

/// **The default is the whole of what "zero churn" means.** `TextFilter<String>` and
/// `TextFilter<String, Builtin>` are ONE type, so every spelling written before the parameter existed
/// resolves to the same face — well formed only while that is true.
#[test]
fn the_reading_defaults_to_the_framework() {
  fn one_type_under_two_spellings(filter: TextFilter<String, Builtin>) -> TextFilter<String> {
    filter
  }

  let _ = one_type_under_two_spellings(TextFilter::new().with_eq("clapper".to_owned()));
}

/// **F-2's wall, fallen.** `Vec<u128>` is a collection of an operand with no `InputType` anywhere —
/// async-graphql's integers stop at 64 bits — so the sequence face could not be asked for one before
/// the element bound became the crossing. It resolves now, and the operands are the carrier's.
///
/// The SCALAR column of the same type always worked, which is what made the gap a wall rather than a
/// design: one position crossed and the other could not.
#[test]
fn a_collection_of_a_carrier_element_reaches_the_wire() {
  assert_eq!(
    <ListFilter<u128, ScalarFilter<u128>> as InputType>::type_name(),
    "U128ListFilter"
  );
  assert_eq!(
    <SetFilter<u128, ScalarFilter<u128>> as InputType>::type_name(),
    "U128SetFilter"
  );

  // The element's own row is what the face reads, and it is the carrier's.
  const _: InputCrossing<u128> = InputCrossing::WITNESS;
  const _: InputCrossing<i128> = InputCrossing::WITNESS;
}

/// **The row that COMPILED and lied.** A `Vec<Vec<u8>>` column's filter is
/// `ListFilter<Vec<u8>, BytesFilter<Vec<u8>>>`, whose element used to resolve through
/// async-graphql's blanket over `Vec<T>` — so a client asked about a list of thumbnails as a list of
/// lists of small integers while the same blob's own filter published hex.
///
/// The element's crossing is the household's own scalar now, so the two positions agree — and they
/// agree under ONE name, `U8Vector` at the element as at the filter's operand.
#[test]
fn a_list_of_blobs_crosses_as_hex_and_not_as_integers() {
  assert_eq!(
    <<Vec<u8> as ToGraphqlInput>::Input as InputType>::type_name(),
    "U8Vector"
  );
  assert_ne!(
    <<Vec<u8> as ToGraphqlInput>::Input as InputType>::type_name(),
    "[Int!]"
  );
}

/// **An ALIAS resolves to the type it names**, which is what keeps the map out of reach of a
/// token-matching reading. The witness below is `u128`'s row, reached through a word no macro could
/// match — the argument [`crate::ToGraphqlOutput`] makes for the other direction, made once here so
/// both vantages carry it.
#[test]
fn the_crossing_is_alias_proof() {
  type Uuid7 = u128;

  fn one_form_under_two_spellings(
    carried: <Uuid7 as ToGraphqlInput>::Input,
  ) -> <u128 as ToGraphqlInput>::Input {
    carried
  }

  let crossed = one_form_under_two_spellings(crate::U128::from(u128::MAX));
  assert_eq!(*crossed.get(), u128::MAX);
}

/// **A crossing is a ROUND TRIP**, and the two directions are written separately — so the pair is
/// pinned rather than assumed. `u128::MAX` is the operand chosen because a JSON number would lose
/// exactly it.
#[test]
fn an_operand_survives_both_directions() {
  let carried = <u128 as ToGraphqlInput>::carry(&u128::MAX);
  assert_eq!(<u128 as ToGraphqlInput>::cross(carried), Ok(u128::MAX));

  let blob = vec![0x89u8, 0x50, 0x4e, 0x47];
  let carried = <Vec<u8> as ToGraphqlInput>::carry(&blob);
  assert_eq!(carried.to_string(), "89504e47");
  assert_eq!(<Vec<u8> as ToGraphqlInput>::cross(carried), Ok(blob));
}

/// **A declarer's own text type reaches a schema** — F-1's wall, from the vantage that could not
/// write a single line of the way past it before the axis. Both impls below name a LOCAL type, which
/// is the whole of what changed: `impl InputType for TextFilter<Tag>` is `E0117` in a declaring
/// crate and always will be.
///
/// The refusal leg is what a total crossing would have hidden: a newtype VALIDATES, so `cross` is
/// fallible and the sentence reaches the client.
#[test]
fn a_declarers_own_reading_carries_a_name_and_a_refusal() {
  #[derive(Debug, Clone, PartialEq)]
  struct Tag(String);

  enum TagWire {}

  impl TextWire<Tag> for TagWire {
    const NAME: &'static str = "TagFilter";

    type Carrier = String;
    type Error = String;

    fn cross(carrier: String) -> Result<Tag, String> {
      if carrier.is_empty() {
        return Err(String::from("a tag is not empty"));
      }
      Ok(Tag(carrier))
    }

    fn carry(operand: &Tag) -> String {
      operand.0.clone()
    }
  }

  assert_eq!(
    <TextFilter<Tag, TagWire> as InputType>::type_name(),
    "TagFilter"
  );
  assert_eq!(
    <Nullable<TextFilter<Tag, TagWire>> as InputType>::type_name(),
    "NullableTagFilter"
  );

  // The operands cross, and the refusal is the reading's own sentence.
  let written = TextFilter::<Tag, TagWire>::new().with_contains(Tag(String::from("cam")));
  let read = <TextFilter<Tag, TagWire> as InputType>::parse(Some(written.to_value()))
    .expect("a written filter parses");
  assert_eq!(read, written);

  let refused = <TextFilter<Tag, TagWire> as InputType>::parse(Some(async_graphql::Value::Object(
    [(
      async_graphql::Name::new("eq"),
      async_graphql::Value::String(String::new()),
    )]
    .into_iter()
    .collect(),
  )))
  .expect_err("an empty tag is refused by the reading");
  let sentence = refused
    .into_server_error(async_graphql::Pos::default())
    .message;
  assert!(sentence.contains("a tag is not empty"), "{sentence}");
}

/// **Both walls, in an ACTUAL schema.** The type-level assertions above say the faces resolve; this
/// one says a client reads the crossed forms — which is the half a `type_name()` cannot show, the
/// operand types living inside the input object rather than in its name.
///
/// A schema of its own rather than a row in the inventory fixture beside it: that fixture asserts the
/// WHOLE list of registered input objects, so adding to it would be asserting this round's rows in a
/// test about a different claim.
#[test]
fn the_crossed_collections_reach_a_schema() {
  struct Query;

  #[async_graphql::Object]
  impl Query {
    /// F-2's wall: a collection of an operand with no `InputType` anywhere.
    async fn wide(&self, ids: ListFilter<u128>, id_set: SetFilter<u128>) -> bool {
      crate::GraphqlFilter::is_empty(&ids) && crate::GraphqlFilter::is_empty(&id_set)
    }

    /// The row that compiled and lied: a `Vec<Vec<u8>>` column's filter.
    async fn blobs(&self, covers: ListFilter<Vec<u8>>) -> bool {
      crate::GraphqlFilter::is_empty(&covers)
    }
  }

  let sdl = async_graphql::Schema::build(
    Query,
    async_graphql::EmptyMutation,
    async_graphql::EmptySubscription,
  )
  .finish()
  .sdl();

  // The wide integer's collection: every operand is the carrier, and the name is the one the
  // element's own filter mints.
  assert!(
    sdl.contains(
      "input U128ListFilter {\n\teq: [u128!]\n\tne: [u128!]\n\tgt: [u128!]\n\tgte: \
       [u128!]\n\tlt: [u128!]\n\tlte: [u128!]\n\thasElement: u128\n\tany: \
       U128Filter\n\tcount: CountFilter\n}\n"
    ),
    "{sdl}"
  );
  assert!(
    sdl.contains("input U128SetFilter {\n\teq: [u128!]"),
    "{sdl}"
  );

  // The blob's collection, in hex — where the same face published `[[Int!]!]` before, while the
  // blob's own filter published hex one field away. The NAME is the element FILTER's, with the family
  // suffix taken off, so it is `U8VectorListFilter` and not the carrier's own word.
  assert!(
    sdl.contains(
      "input U8VectorListFilter {\n\teq: [U8Vector!]\n\tne: [U8Vector!]\n\tgt: \
       [U8Vector!]\n\tgte: [U8Vector!]\n\tlt: [U8Vector!]\n\tlte: [U8Vector!]\n\thasElement: \
       U8Vector\n\tany: U8VectorFilter\n\tcount: CountFilter\n}\n"
    ),
    "{sdl}"
  );

  // The lie itself, gone: no operand in either collection is a list of small integers. `CountFilter`
  // keeps its `[Int!]` and is not one — a cardinality IS an integer, and that is the one place the
  // form is honest, so the assertion names the operand fields rather than the whole document.
  assert!(!sdl.contains("eq: [[Int!]!]"), "{sdl}");
  assert!(!sdl.contains("hasElement: [Int!]"), "{sdl}");
}

/// **EVERY NAME THE SCALAR AND BYTE ROWS HAD TO KEEP.** The registrations they replaced published
/// these, and a rename would have been a breaking schema change made by a refactor — the claim
/// [`the_canonical_text_names_survive_the_axis`] makes for the text pair, made here for the rest.
///
/// The list is the WHOLE unconditional set, so a row deleted along with its registration fails here
/// rather than silently leaving a column with no face. `graphql::tests::wire`'s inventory asserts
/// which names reach a SCHEMA; this asserts what each row publishes, which is the half that survives
/// a type nothing declares.
#[test]
fn the_canonical_scalar_and_byte_names_survive_the_axis() {
  assert_eq!(<ScalarFilter<i8> as InputType>::type_name(), "I8Filter");
  assert_eq!(<ScalarFilter<i16> as InputType>::type_name(), "I16Filter");
  assert_eq!(<ScalarFilter<i32> as InputType>::type_name(), "I32Filter");
  assert_eq!(<ScalarFilter<i64> as InputType>::type_name(), "I64Filter");
  assert_eq!(<ScalarFilter<i128> as InputType>::type_name(), "I128Filter");
  assert_eq!(<ScalarFilter<u8> as InputType>::type_name(), "U8Filter");
  assert_eq!(<ScalarFilter<u16> as InputType>::type_name(), "U16Filter");
  assert_eq!(<ScalarFilter<u32> as InputType>::type_name(), "U32Filter");
  assert_eq!(<ScalarFilter<u64> as InputType>::type_name(), "U64Filter");
  assert_eq!(<ScalarFilter<u128> as InputType>::type_name(), "U128Filter");
  assert_eq!(<ScalarFilter<f32> as InputType>::type_name(), "F32Filter");
  assert_eq!(<ScalarFilter<f64> as InputType>::type_name(), "F64Filter");

  assert_eq!(
    <ScalarFilter<core::num::NonZeroI32> as InputType>::type_name(),
    "NonZeroI32Filter"
  );
  assert_eq!(
    <ScalarFilter<core::num::NonZeroU64> as InputType>::type_name(),
    "NonZeroU64Filter"
  );
  assert_eq!(
    <ScalarFilter<crate::Timestamp> as InputType>::type_name(),
    "TimestampFilter"
  );
  assert_eq!(
    <ScalarFilter<usize> as InputType>::type_name(),
    "CountFilter"
  );
  // The DECLARED cardinality, which is the one row that could not take its own type's name — see
  // its registration for the collision with the line above, and `graphql::tests::wire` for the
  // schema that holds both.
  assert_eq!(
    <ScalarFilter<crate::Count> as InputType>::type_name(),
    "CardinalityFilter"
  );

  // The ROSTER's own byte row, and its operand is `bytes::Bytes` since the household swapped.
  assert_eq!(
    <BytesFilter<::bytes::Bytes> as InputType>::type_name(),
    "BytesFilter"
  );

  // And the twins, which are the framework's law over these names rather than a second literal.
  assert_eq!(
    <Nullable<ScalarFilter<i64>> as InputType>::type_name(),
    "NullableI64Filter"
  );
  assert_eq!(
    <Nullable<BytesFilter<::bytes::Bytes>> as InputType>::type_name(),
    "NullableBytesFilter"
  );
}

/// The temporal rows, SPLIT OUT for the reason the second text pin is: they name an optional
/// dependency, and this file is compiled wherever the BINDING is.
#[cfg(feature = "jiff")]
#[test]
fn the_canonical_temporal_names_survive_the_axis() {
  assert_eq!(
    <ScalarFilter<jiff::Timestamp> as InputType>::type_name(),
    "DateTimeFilter"
  );
  assert_eq!(
    <ScalarFilter<jiff::civil::Date> as InputType>::type_name(),
    "DateFilter"
  );
  assert_eq!(
    <ScalarFilter<jiff::civil::Time> as InputType>::type_name(),
    "TimeFilter"
  );
  assert_eq!(
    <ScalarFilter<jiff::Zoned> as InputType>::type_name(),
    "ZonedDateTimeFilter"
  );
  // The two this crate MINTS the scalar for, whose names had to dodge async-graphql's own: a second
  // `DateTime` would be one word on two things, and a bare `Offset` reads as a cursor's.
  assert_eq!(
    <ScalarFilter<jiff::civil::DateTime> as InputType>::type_name(),
    "LocalDateTimeFilter"
  );
  assert_eq!(
    <ScalarFilter<jiff::tz::Offset> as InputType>::type_name(),
    "UtcOffsetFilter"
  );
}

/// **THE CLAIMED VOCABULARIES' NAMES**, each written once in [`carrier`](super) and read back here.
///
/// The `smol-bytes` household is ONE name per face and the prefix names the CRATE — the strategy
/// modules are an allocation detail and never reached the wire. The `shared::` spelling is asserted
/// beside the root one because they are one type: a row that split them would be a schema panicking
/// on a name held twice.
#[test]
fn the_claimed_byte_vocabularies_carry_their_settled_names() {
  assert_eq!(
    <BytesFilter<smol_bytes::Bytes> as InputType>::type_name(),
    "SmolBytesFilter"
  );
  assert_eq!(
    <BytesFilter<smol_bytes::shared::Bytes> as InputType>::type_name(),
    "SmolBytesFilter"
  );
  assert_eq!(
    <TextFilter<smol_bytes::Utf8Bytes> as InputType>::type_name(),
    "SmolUtf8BytesFilter"
  );
  assert_eq!(
    <TextFilter<smol_bytes::shared::Utf8Bytes> as InputType>::type_name(),
    "SmolUtf8BytesFilter"
  );

  // The FIXED-WIDTH row, which is the one name assembled rather than stated: the base is
  // `U8ArrayFilter` and every published form carries a width.
  assert_eq!(
    <FixedBytesFilter<[u8; 16], 16> as InputType>::type_name(),
    "Fixed16U8ArrayFilter"
  );
  assert_eq!(
    <FixedBytesFilter<[u8; 32], 32> as InputType>::type_name(),
    "Fixed32U8ArrayFilter"
  );
  assert_eq!(
    <Nullable<FixedBytesFilter<[u8; 16], 16>> as InputType>::type_name(),
    "NullableFixed16U8ArrayFilter"
  );
}

/// **THE HOUSEHOLD SWAP, READ AS NAMES**: `bytes::Bytes` holds the roster's `bytes` row and derives
/// `BytesFilter`; `Vec<u8>` is a NAMED vocabulary and takes `U8VectorFilter`, the growable twin of
/// `Fixed{N}U8ArrayFilter`.
///
/// The clash the pre-constitution naming had no answer to is answered by the two being two names,
/// and it no longer even needs the case register to say so — under the amended derivation law every
/// filter is Pascal, and what tells these apart is which operand each is the filter OF.
///
/// No feature gate, where this pin had one: a default roster row cannot sit behind a word.
#[test]
fn the_default_byte_operand_and_the_named_ones_are_all_different_names() {
  assert_eq!(
    <BytesFilter<::bytes::Bytes> as InputType>::type_name(),
    "BytesFilter"
  );
  assert_eq!(
    <BytesFilter<Vec<u8>> as InputType>::type_name(),
    "U8VectorFilter"
  );
  assert_ne!(
    <BytesFilter<::bytes::Bytes> as InputType>::type_name(),
    <BytesFilter<Vec<u8>> as InputType>::type_name()
  );
  // And the two crates' immutable blobs, which is the collision the crate prefix answers.
  assert_ne!(
    <BytesFilter<::bytes::Bytes> as InputType>::type_name(),
    <BytesFilter<smol_bytes::Bytes> as InputType>::type_name()
  );
}

/// The CROSSINGS, both directions, at one row of each arm — the claim a name pin cannot make.
///
/// The fixed-width row is the only one that can refuse, and its sentence is the one a client reads.
#[test]
fn a_claimed_operand_survives_both_directions() {
  let digest: [u8; 4] = [0x89, 0x50, 0x4e, 0x47];
  let carried = <Builtin as BytesWire<[u8; 4]>>::carry(&digest);
  assert_eq!(
    <Builtin as BytesWire<[u8; 4]>>::cross(carried).expect("a four-byte value fits"),
    digest
  );

  let text = smol_bytes::shared::Utf8Bytes::from(String::from("a label"));
  let carried = <Builtin as TextWire<smol_bytes::shared::Utf8Bytes>>::carry(&text);
  assert_eq!(carried, "a label");
  assert_eq!(
    <Builtin as TextWire<smol_bytes::shared::Utf8Bytes>>::cross(carried)
      .expect("a text crossing cannot refuse"),
    text
  );

  let blob = smol_bytes::shared::Bytes::from(vec![0x0d, 0x0a]);
  let carried = <Builtin as BytesWire<smol_bytes::shared::Bytes>>::carry(&blob);
  assert_eq!(
    <Builtin as BytesWire<smol_bytes::shared::Bytes>>::cross(carried)
      .expect("a blob crossing cannot refuse"),
    blob
  );
}

/// **THE FIXED-WIDTH REFUSAL**, which is the only one the framework's own byte rows have.
///
/// Both directions of wrong: too few bytes and too many. A truncation or a zero pad would be a
/// different question answered in silence, so the refusal names both widths and the client reads
/// them.
#[test]
fn a_fixed_width_column_refuses_the_wrong_number_of_bytes() {
  let short = <Builtin as BytesWire<[u8; 16]>>::cross(crate::FixedU8Array::from(vec![0u8; 15]))
    .expect_err("fifteen bytes do not fit a sixteen-byte column");
  assert_eq!(short.expected(), 16);
  assert_eq!(short.got(), 15);
  assert_eq!(short.to_string(), "expected 16 bytes, got 15");

  let long = <Builtin as BytesWire<[u8; 16]>>::cross(crate::FixedU8Array::from(vec![0u8; 17]))
    .expect_err("seventeen bytes do not fit either");
  assert_eq!(long.to_string(), "expected 16 bytes, got 17");
}

/// **THE ROWS ARE DEMANDED, AND THERE IS EXACTLY ONE FACE PER KIND.** Both halves are compile-time
/// and neither is an assertion a body could make.
///
/// A row that went missing is `E0277` on ITS OWN LINE below, which is what the assertions above
/// cannot give: `type_name()` on a kind with no row does not compile at all, so a deleted row would
/// take the whole test file with it rather than naming itself.
///
/// The other half is the `E0119` this round bought: `ScalarFilter` and `BytesFilter` each have ONE
/// `impl InputType` in this crate, over the reading. A concrete row re-added beside either — the
/// shape every one of these operands used to have — collides with it, and the CRATE stops
/// compiling. So the invariant is held by coherence rather than by a reviewer counting impls.
#[expect(
  dead_code,
  reason = "a signature is the assertion — its `where` clause is what demands the rows, and calling \
            it would prove nothing the compiler has not already proved"
)]
fn every_builtin_reading_carries_a_face()
where
  ScalarFilter<i8>: InputType,
  ScalarFilter<i16>: InputType,
  ScalarFilter<i32>: InputType,
  ScalarFilter<i64>: InputType,
  ScalarFilter<i128>: InputType,
  ScalarFilter<u8>: InputType,
  ScalarFilter<u16>: InputType,
  ScalarFilter<u32>: InputType,
  ScalarFilter<u64>: InputType,
  ScalarFilter<u128>: InputType,
  ScalarFilter<f32>: InputType,
  ScalarFilter<f64>: InputType,
  ScalarFilter<core::num::NonZeroI8>: InputType,
  ScalarFilter<core::num::NonZeroI16>: InputType,
  ScalarFilter<core::num::NonZeroI32>: InputType,
  ScalarFilter<core::num::NonZeroI64>: InputType,
  ScalarFilter<core::num::NonZeroU8>: InputType,
  ScalarFilter<core::num::NonZeroU16>: InputType,
  ScalarFilter<core::num::NonZeroU32>: InputType,
  ScalarFilter<core::num::NonZeroU64>: InputType,
  // THE TWO WIDEST `NonZero` WIDTHS, which had a `to_filter!` row and NO FACE until the family moved
  // onto the suite: async-graphql's `non_zero_integers.rs` stops at 64 bits exactly as its plain
  // integers do, so these two lines are `E0277` against the reading that preceded 2026-08-25.
  ScalarFilter<core::num::NonZeroI128>: InputType,
  ScalarFilter<core::num::NonZeroU128>: InputType,
  // THE ADDRESS FAMILY, six rows and their collection crossings. async-graphql faces none of the six
  // — it ships an IP validator and no scalar — so every one of these is in `u128`'s position rather
  // than the blob's.
  ScalarFilter<std::net::Ipv4Addr>: InputType,
  ScalarFilter<std::net::Ipv6Addr>: InputType,
  ScalarFilter<std::net::IpAddr>: InputType,
  ScalarFilter<std::net::SocketAddrV4>: InputType,
  ScalarFilter<std::net::SocketAddrV6>: InputType,
  ScalarFilter<std::net::SocketAddr>: InputType,
  ListFilter<std::net::Ipv4Addr>: InputType,
  ListFilter<std::net::SocketAddr>: InputType,
  // The `NonZero` family's own element crossing, which is the row a `Vec<NonZeroU32>` column spends:
  // it refuses a zero MEMBER with the same sentence the scalar column's `eq` refuses one with.
  ListFilter<core::num::NonZeroU32>: InputType,
  crate::ConfidenceFilter: InputType,
  ScalarFilter<crate::Timestamp>: InputType,
  ScalarFilter<usize>: InputType,
  BytesFilter<Vec<u8>>: InputType,
  // The CLAIMED byte and UTF-8 vocabularies, each one row and each demanded on its own line.
  FixedBytesFilter<[u8; 16], 16>: InputType,
  BytesFilter<smol_bytes::Bytes>: InputType,
  TextFilter<smol_bytes::Utf8Bytes>: InputType,
  // And their ELEMENT crossings, demanded through the collection face that spends them: a claimed
  // vocabulary with a return and no `ToGraphqlInput` row is a `Vec` column that can be read back and
  // not filtered.
  ListFilter<[u8; 16]>: InputType,
  ListFilter<smol_bytes::Bytes>: InputType,
  ListFilter<smol_bytes::Utf8Bytes>: InputType,
  Nullable<ScalarFilter<i64>>: InputType,
  Nullable<BytesFilter<Vec<u8>>>: InputType,
{
}

/// The `bytes` crate's blob, demanded the same way. It kept a `#[cfg]` while the crate was an
/// optional dependency; the household swap made it mandatory, so the row is in every build and the
/// gate is gone. Its `BytesMut` left the wire on 2026-08-19 — see [`super`]'s byte household.
#[expect(
  dead_code,
  reason = "a signature is the assertion — see `every_builtin_reading_carries_a_face`"
)]
fn the_bytes_crates_rows_carry_a_face()
where
  BytesFilter<::bytes::Bytes>: InputType,
  ListFilter<::bytes::Bytes>: InputType,
{
}

/// **The default is the whole of what "zero churn" means**, at the two kinds that grew a parameter
/// this round — [`the_reading_defaults_to_the_framework`]'s claim, one and two kinds over.
///
/// `BytesFilter` had to keep TWO defaults in the right order while the WIDTH was a parameter of it.
/// The width is a KIND now, so each byte filter carries one defaulting parameter — and
/// `FixedBytesFilter`'s trails a const, which is the ordering this pins.
#[test]
fn the_scalar_and_byte_readings_default_to_the_framework() {
  fn one_scalar_under_two_spellings(filter: ScalarFilter<i64, Builtin>) -> ScalarFilter<i64> {
    filter
  }

  fn one_blob_under_two_spellings(filter: BytesFilter<Vec<u8>, Builtin>) -> BytesFilter<Vec<u8>> {
    filter
  }

  fn one_fixed_column_under_two_spellings(
    filter: FixedBytesFilter<[u8; 32], 32, Builtin>,
  ) -> FixedBytesFilter<[u8; 32], 32> {
    filter
  }

  let _ = one_scalar_under_two_spellings(ScalarFilter::new().with_eq(24));
  let _ = one_blob_under_two_spellings(BytesFilter::new().with_eq(vec![0x89]));
  let _ = one_fixed_column_under_two_spellings(FixedBytesFilter::new());
}

/// **A declarer's own ORDERED type and its own BLOB reach a schema** — the text pin's claim at the
/// two kinds this round opened, with the same two legs: the name is the READING's, and a refusal is
/// the reading's own sentence.
///
/// In-crate, this is a claim about the MECHANISM; `tests/wire_readings.rs` makes it from the vantage
/// where `impl InputType for ScalarFilter<Rate>` is actually `E0117`, which is the only place the
/// wall can be stood on.
#[test]
fn a_declarers_own_scalar_and_byte_readings_carry_a_name_and_a_refusal() {
  #[derive(Debug, Clone, Copy, PartialEq)]
  struct Rate(u32);

  enum RateWire {}

  impl ScalarWire<Rate> for RateWire {
    const NAME: &'static str = "RateFilter";

    type Carrier = crate::U32;
    type Error = String;

    fn cross(carrier: crate::U32) -> Result<Rate, String> {
      match u32::from(carrier) {
        0 => Err(String::from("a rate of zero is not a rate")),
        rate => Ok(Rate(rate)),
      }
    }

    fn carry(operand: &Rate) -> crate::U32 {
      crate::U32::from(operand.0)
    }
  }

  #[derive(Debug, Clone, PartialEq)]
  struct Sum(Vec<u8>);

  enum SumWire {}

  impl BytesWire<Sum> for SumWire {
    const NAME: &'static str = "SumFilter";

    type Carrier = HexBytes;
    type Error = String;

    fn cross(carrier: HexBytes) -> Result<Sum, String> {
      let bytes = Vec::from(carrier);
      if bytes.len() == 4 {
        return Ok(Sum(bytes));
      }
      Err(String::from("a checksum is 4 bytes"))
    }

    fn carry(operand: &Sum) -> HexBytes {
      HexBytes::from(operand.0.clone())
    }
  }

  assert_eq!(
    <ScalarFilter<Rate, RateWire> as InputType>::type_name(),
    "RateFilter"
  );
  assert_eq!(
    <Nullable<ScalarFilter<Rate, RateWire>> as InputType>::type_name(),
    "NullableRateFilter"
  );
  assert_eq!(
    <BytesFilter<Sum, SumWire> as InputType>::type_name(),
    "SumFilter"
  );

  // The FIXED KIND DECORATES the name the reading supplies, so one row over one operand gives a name
  // per width and the widths spell themselves. This is the pin that used to assert the opposite —
  // that both shapes published `SumFilter` — and it was the statement of a hazard rather than of a
  // property: two Rust types under one GraphQL name are `Registry::create_type`'s panic waiting for
  // a schema that reaches both.
  assert_eq!(
    <FixedBytesFilter<Sum, 4, SumWire> as InputType>::type_name(),
    "Fixed4SumFilter"
  );
  assert_eq!(
    <FixedBytesFilter<Sum, 32, SumWire> as InputType>::type_name(),
    "Fixed32SumFilter"
  );
  // And the wrapper composes onto the decorated name rather than around it, which is the whole of
  // why neither is spelled twice anywhere.
  assert_eq!(
    <Nullable<FixedBytesFilter<Sum, 4, SumWire>> as InputType>::type_name(),
    "NullableFixed4SumFilter"
  );

  // The operands cross, both directions.
  let written = ScalarFilter::<Rate, RateWire>::new()
    .with_gte(Rate(3))
    .with_in_([Rate(7), Rate(9)]);
  let read = <ScalarFilter<Rate, RateWire> as InputType>::parse(Some(written.to_value()))
    .expect("a written filter parses");
  assert_eq!(read, written);

  // And a refusal is the reading's own sentence, at the LIST slot as well as at the inline one —
  // the first refusal being the answer.
  let refused =
    <ScalarFilter<Rate, RateWire> as InputType>::parse(Some(async_graphql::Value::Object(
      [(
        async_graphql::Name::new("in"),
        async_graphql::Value::List(vec![
          async_graphql::Value::Number(7.into()),
          async_graphql::Value::Number(0.into()),
        ]),
      )]
      .into_iter()
      .collect(),
    )))
    .expect_err("a zero rate is refused by the reading");
  let sentence = refused
    .into_server_error(async_graphql::Pos::default())
    .message;
  assert!(
    sentence.contains("a rate of zero is not a rate"),
    "{sentence}"
  );

  let refused =
    <BytesFilter<Sum, SumWire> as InputType>::parse(Some(async_graphql::Value::Object(
      [(
        async_graphql::Name::new("eq"),
        async_graphql::Value::String(String::from("dead")),
      )]
      .into_iter()
      .collect(),
    )))
    .expect_err("a two-byte checksum is refused by the reading");
  let sentence = refused
    .into_server_error(async_graphql::Pos::default())
    .message;
  assert!(sentence.contains("a checksum is 4 bytes"), "{sentence}");
}

/// **A WIRE `0` REFUSES BY NAME, at both legs of a `NonZero` width** — the crossing's half of the
/// invariant [`NonZeroColumnError`](crate::NonZeroColumnError) holds at the storage end.
///
/// The two legs are asked separately because they are two rows: a SCALAR column spends
/// `ScalarWire::cross` inside the filter's own `parse`, and a COLLECTION column spends
/// `ToGraphqlInput::cross` per member. A width whose two rows disagreed would be a column that
/// refuses `eq: 0` and stores a zero through `hasElement`.
///
/// The sentence is read the way a client reads it — through `into_server_error`, which is the one
/// door onto an `InputValueError`'s message — and what is asserted is that it names the WIDTH, that
/// being the fact introspection cannot carry.
#[test]
fn a_wire_zero_is_refused_by_name_at_both_nonzero_legs() {
  use core::num::NonZeroU32;

  let refused = <ScalarFilter<NonZeroU32> as InputType>::parse(Some(async_graphql::Value::Object(
    [(
      async_graphql::Name::new("eq"),
      async_graphql::Value::Number(0.into()),
    )]
    .into_iter()
    .collect(),
  )))
  .expect_err("a zero operand is refused by the reading");
  let sentence = refused
    .into_server_error(async_graphql::Pos::default())
    .message;
  assert!(sentence.contains("NonZeroU32"), "{sentence}");
  assert!(sentence.contains("REFUSED and never wrapped"), "{sentence}");

  // The ELEMENT leg, through the collection face that spends it.
  let refused = <ListFilter<NonZeroU32> as InputType>::parse(Some(async_graphql::Value::Object(
    [(
      async_graphql::Name::new("hasElement"),
      async_graphql::Value::Number(0.into()),
    )]
    .into_iter()
    .collect(),
  )))
  .expect_err("a zero member is refused by the element crossing");
  let sentence = refused
    .into_server_error(async_graphql::Pos::default())
    .message;
  assert!(sentence.contains("NonZeroU32"), "{sentence}");

  // …and a NON-zero operand crosses, so the refusal is discriminating rather than a wall.
  let accepted =
    <ScalarFilter<NonZeroU32> as InputType>::parse(Some(async_graphql::Value::Object(
      [(
        async_graphql::Name::new("eq"),
        async_graphql::Value::Number(24.into()),
      )]
      .into_iter()
      .collect(),
    )))
    .expect("a non-zero operand crosses");
  assert_eq!(
    ScalarFilter::eq(&accepted),
    Some(&NonZeroU32::new(24).expect("24 is not zero"))
  );

  // The two rows in the OTHER direction, which cannot refuse: a value coming out of a `NonZero` is
  // not zero, so both `carry` legs are total and answer the underlying integer's carrier.
  let one = NonZeroU32::new(1).expect("1 is not zero");
  assert_eq!(
    <Builtin as ScalarWire<NonZeroU32>>::carry(&one),
    crate::U32::from(1)
  );
  assert_eq!(
    <NonZeroU32 as ToGraphqlInput>::carry(&one),
    crate::U32::from(1)
  );
}

/// **THE `NonZero` FAMILY PUBLISHES ITS UNDERLYING WIDTH'S SCALAR**, which is the 2026-08-25 ruling
/// read at the name a client meets: the input object says `NonZeroU32Filter` and its operands say
/// `u32`.
///
/// Asserted as a pair because that is the whole of the arrangement — one wire form under two names,
/// where the second name is the only place the domain hole can be stated.
#[test]
fn a_nonzero_width_crosses_on_its_own_integers_scalar() {
  assert_eq!(
    <ScalarFilter<core::num::NonZeroU32> as InputType>::type_name(),
    "NonZeroU32Filter"
  );
  assert_eq!(
    <<Builtin as ScalarWire<core::num::NonZeroU32>>::Carrier as InputType>::type_name(),
    "u32"
  );
  // The two widest widths, whose carrier is the HYBRID one — they had no face at all before the
  // move, so this pair is the completeness half of the same ruling.
  assert_eq!(
    <ScalarFilter<core::num::NonZeroI128> as InputType>::type_name(),
    "NonZeroI128Filter"
  );
  assert_eq!(
    <<Builtin as ScalarWire<core::num::NonZeroI128>>::Carrier as InputType>::type_name(),
    "i128"
  );
}

/// **THE ADDRESS FAMILY's six names**, each derived from the one literal its row was handed.
///
/// Pascal, because an address is a NAMED TYPE and not a width — see [`roster`](super::super::roster),
/// where law three is written and where the mechanism that agrees with it is: `capitalised` raises
/// one byte, so a lowercase snake row could not have derived its own filter name at all.
#[test]
fn the_address_family_publishes_pascal_names() {
  assert_eq!(
    <ScalarFilter<std::net::Ipv4Addr> as InputType>::type_name(),
    "Ipv4AddrFilter"
  );
  assert_eq!(
    <ScalarFilter<std::net::Ipv6Addr> as InputType>::type_name(),
    "Ipv6AddrFilter"
  );
  assert_eq!(
    <ScalarFilter<std::net::IpAddr> as InputType>::type_name(),
    "IpAddrFilter"
  );
  assert_eq!(
    <ScalarFilter<std::net::SocketAddrV4> as InputType>::type_name(),
    "SocketAddrV4Filter"
  );
  assert_eq!(
    <ScalarFilter<std::net::SocketAddrV6> as InputType>::type_name(),
    "SocketAddrV6Filter"
  );
  assert_eq!(
    <ScalarFilter<std::net::SocketAddr> as InputType>::type_name(),
    "SocketAddrFilter"
  );
  assert_eq!(
    <Nullable<ScalarFilter<std::net::Ipv4Addr>> as InputType>::type_name(),
    "NullableIpv4AddrFilter"
  );
}

/// **THE CARDINALITY CROSSES ON `u64`'s OWN CARRIER, IN BOTH DIRECTIONS**, at the three magnitudes
/// that tell the wire's hybrid boundary apart from the boundaries it is often confused with.
///
/// Below `i32::MAX`, above `i32::MAX` but below `2^53 − 1`, and past `2^53 − 1` — the last being
/// where [`U64`](super::super::scalar::U64) switches from a JSON number to decimal text, which is
/// `graphql::scalar`'s own boundary and not the spec's 32-bit `Int`. **Nothing narrows here.** The
/// `i64` the storage rows produce is a fact about columns with no unsigned 64-bit type, and the wire
/// has no such shortage — so a count of any magnitude reaches a client exactly.
///
/// Both directions out of one carrier, which is the mirror law: a `Count` column returned as `u64!`
/// and filtered with `eq: u64` cannot come to disagree when one type produces both forms.
#[test]
fn a_cardinality_crosses_on_the_hybrid_u64_carrier_at_every_magnitude() {
  use crate::{Count, ToGraphqlInput, ToGraphqlOutput};

  const SAFE: u64 = (1 << 53) - 1;

  for magnitude in [42_u64, 5_000_000_000, SAFE + 2, u64::MAX] {
    let count = Count::new(magnitude);

    assert_eq!(
      u64::from(<Count as ToGraphqlOutput>::to_graphql_output(&count)),
      magnitude,
      "the OUTPUT direction carries the whole width"
    );
    assert_eq!(
      u64::from(<Count as ToGraphqlInput>::carry(&count)),
      magnitude,
      "and so does the INPUT direction's write-back"
    );
    assert_eq!(
      <Count as ToGraphqlInput>::cross(<Count as ToGraphqlInput>::carry(&count)),
      Ok(count),
      "which makes the pair a round trip"
    );
  }

  // The READING's own crossing is the same pair one seat over — an operand rather than an element —
  // and it reaches the same carrier, so a filter and a `hasElement` cannot disagree either.
  assert_eq!(
    <Builtin as ScalarWire<Count>>::cross(<Builtin as ScalarWire<Count>>::carry(&Count::new(9))),
    Ok(Count::new(9))
  );
}