ingraph-derive 0.1.0

The attribute and derive macros for ingraph: the words a record, node, key, filter and vocabulary declaration is written in.
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
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
//! The vocabulary door's acceptance: what a declaration may say, every shape it may not, and the ONE
//! citizenship it earns.

use ingraph_codegen::{
  enumeration::{EnumModel, EnumVariant, IntegerWidth, Namespace, StorageForm},
  model::GraphqlKind,
};
use quote::ToTokens as _;

/// The pass under test. A derive is handed the item as it stands, so the declaration's own
/// `#[ingraph(…)]` is read where a reader sees it — there is no second place for it to be.
fn parse(input: &syn::DeriveInput) -> syn::Result<ingraph_codegen::enumeration::EnumModel> {
  super::parse(input)
}

/// Every variant a model kept, as Rust spells them.
fn variants(model: &EnumModel) -> Vec<String> {
  model
    .variants
    .iter()
    .map(|variant| variant.ident.to_string())
    .collect()
}

/// Every variant's word in one namespace.
fn spelled(model: &EnumModel, namespace: Namespace) -> Vec<String> {
  model
    .variants
    .iter()
    .map(|variant| variant.name(namespace))
    .collect()
}

/// A path as it would be written, with the token spacing removed.
fn rendered(path: &syn::Path) -> String {
  path.to_token_stream().to_string().replace(' ', "")
}

/// The model a declaration this pass ACCEPTS produces.
fn accepted(input: &syn::DeriveInput) -> EnumModel {
  parse(input).expect("the declaration is accepted")
}

/// The refusal a declaration gets, as one string.
fn refusal(input: &syn::DeriveInput) -> String {
  parse(input)
    .expect_err("the declaration is refused")
    .into_iter()
    .map(|error| error.to_string())
    .collect::<Vec<_>>()
    .join(" | ")
}

/// **A vocabulary declares NOTHING and is complete.** Storage is machine-facing, so every database
/// takes the discriminant and the wire takes the name, from a declaration that says neither.
#[test]
fn a_bare_vocabulary_stores_numbers_and_shows_names() {
  let model = parse(&syn::parse_quote! {
    pub enum Codec { H264, Vp9, Av1 }
  })
  .expect("unit variants and nothing else is the whole shape");

  assert_eq!(model.name, "Codec");
  assert_eq!(variants(&model), ["H264", "Vp9", "Av1"]);
  assert_eq!(rendered(&model.krate), "::ingraph");
  assert!(model.forms.is_empty());
  for namespace in [
    Namespace::Sqlite,
    Namespace::Postgres,
    Namespace::Mysql,
    Namespace::Mongo,
  ] {
    assert_eq!(model.form(namespace), StorageForm::Integer);
  }
  assert_eq!(model.form(Namespace::Graphql), StorageForm::Text);
  assert_eq!(model.width(), IntegerWidth::I64);
}

/// A per-face block is an OVERRIDE and moves that face alone.
#[test]
fn one_face_takes_a_form_without_moving_the_others() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(postgres(text), graphql(integer))]
    enum Codec { H264 }
  })
  .expect("a face states its own form");

  assert_eq!(model.form(Namespace::Postgres), StorageForm::Text);
  assert_eq!(model.form(Namespace::Graphql), StorageForm::Integer);
  assert_eq!(model.form(Namespace::Sqlite), StorageForm::Integer);
}

/// A block with no form word is the face declared at ITS OWN DEFAULT, and that is legal: a form
/// chosen by silence is a form the framework RULED rather than one nobody answered, so there is
/// nothing here to refuse.
#[test]
fn a_face_block_may_carry_no_form_at_all() {
  for input in [
    syn::parse_quote! {
      #[ingraph(mysql)]
      enum Codec { H264 }
    },
    syn::parse_quote! {
      #[ingraph(mysql())]
      enum Codec { H264 }
    },
  ] {
    let model = parse(&input).expect("a face named and left at its default");
    assert_eq!(model.form(Namespace::Mysql), StorageForm::Integer);
  }
}

/// The `#[repr(…)]` a declaration already writes IS the width — nothing restates it.
#[test]
fn the_width_is_read_off_the_repr() {
  for width in IntegerWidth::ALL {
    let word = syn::Ident::new(width.as_str(), proc_macro2::Span::call_site());
    let model = parse(&syn::parse_quote! {
      #[repr(#word)]
      enum Grade { Low }
    })
    .expect("every width the framework carries is one a declaration may write");
    assert_eq!(model.width, Some(width), "{}", width.as_str());
  }
}

/// A LAYOUT hint says nothing about a stored width, so an enum carrying one is not a declaration
/// this derive objects to — it takes the default width like any other.
#[test]
fn a_layout_repr_is_not_a_width() {
  let model = parse(&syn::parse_quote! {
    #[repr(C)]
    enum Grade { Low }
  })
  .expect("`repr(C)` is a fact about layout");

  assert_eq!(model.width, None);
  assert_eq!(model.width(), IntegerWidth::I64);
}

/// The `crate` option is the shared parsing layer's, and it behaves here exactly as it does on a
/// record — which is the whole reason that layer is separate.
#[test]
fn the_crate_path_overrides_the_default() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(crate = "shim::ingraph")]
    enum Codec { H264 }
  })
  .expect("a re-export shim is a path like any other");

  assert_eq!(rendered(&model.krate), "shim::ingraph");
}

/// A discriminant is the DECLARATION's to write, and the parser keeps out of it: the emitted map
/// casts the variant, so the number never passes through this layer at all.
#[test]
fn a_declared_discriminant_does_not_disturb_the_parse() {
  let model = parse(&syn::parse_quote! {
    enum Grade { Low = 3, High = 9 }
  })
  .expect("an explicit discriminant is still a unit variant");

  assert_eq!(variants(&model), ["Low", "High"]);
}

/// **The three renames, and which face each moves.** A global one moves the canonical word and
/// every face that stated none; a per-face one moves that face alone.
#[test]
fn a_global_rename_moves_every_face_that_stated_none() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(sqlite(text), postgres(text))]
    enum Grade {
      #[ingraph(rename = "lo", postgres(rename = "LO"), graphql(rename = "LOW"))]
      Low,
      High,
    }
  })
  .expect("a variant states its words");

  assert_eq!(model.variants[0].canonical(), "lo");
  assert_eq!(spelled(&model, Namespace::Sqlite), ["lo", "High"]);
  assert_eq!(spelled(&model, Namespace::Postgres), ["LO", "High"]);
  assert_eq!(spelled(&model, Namespace::Graphql), ["LOW", "HIGH"]);
}

/// **The refusal type takes the name the declaration gives it**, and the default is what a
/// declaration that says nothing gets.
#[test]
fn the_refusal_type_is_named_by_the_declaration_or_by_the_convention() {
  let named = parse(&syn::parse_quote! {
    #[ingraph(error(rename = "NoSuchCodec"))]
    enum Codec { H264 }
  })
  .expect("a vocabulary may name the one type it emits");

  assert_eq!(named.error, Some(syn::parse_quote!(NoSuchCodec)));
  assert_eq!(named.error(), "NoSuchCodec");

  let defaulted = parse(&syn::parse_quote! {
    enum Codec { H264 }
  })
  .expect("and a declaration that says nothing keeps the convention");

  assert_eq!(defaulted.error, None);
  assert_eq!(defaulted.error(), "CodecParseError");
}

/// A rename goes through a string so a RAW identifier stays spellable — the record grammar's rule,
/// reached here through the reader both derives share.
#[test]
fn a_refusal_may_be_named_with_a_raw_identifier() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(error(rename = "r#type"))]
    enum Codec { H264 }
  })
  .expect("`r#type` is an identifier");

  assert_eq!(model.error(), "r#type");
}

/// **The one name the refusal may not take is the vocabulary's own** — the two land in one scope,
/// where the expansion would be a second definition of the enum's name.
#[test]
fn refuses_a_refusal_named_after_the_vocabulary() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(error(rename = "Codec"))]
    enum Codec { H264 }
  });
  assert!(
    refused.contains("already the vocabulary's own name"),
    "{refused}"
  );
}

/// A type name reaches only Rust, so the string has to BE one — and an empty string is refused for
/// exactly that reason rather than as a special case of its own.
#[test]
fn refuses_a_refusal_name_that_is_not_an_identifier() {
  for spelling in ["", "Not An Ident", "9Lives"] {
    let refused = refusal(&syn::parse_quote! {
      #[ingraph(error(rename = #spelling))]
      enum Codec { H264 }
    });
    assert!(
      refused.contains("must be a valid identifier"),
      "{spelling:?}: {refused}"
    );
  }
}

/// The block exists to carry the one option, so writing it without one is refused rather than read
/// as the default.
#[test]
fn refuses_an_error_block_that_names_nothing() {
  for input in [
    syn::parse_quote! {
      #[ingraph(error)]
      enum Codec { H264 }
    },
    syn::parse_quote! {
      #[ingraph(error())]
      enum Codec { H264 }
    },
  ] {
    let refused = refusal(&input);
    assert!(
      refused.contains("`error(…)` needs `rename = \"…\"`"),
      "{refused}"
    );
  }

  let twice = refusal(&syn::parse_quote! {
    #[ingraph(error(rename = "A", rename = "B"))]
    enum Codec { H264 }
  });
  assert!(
    twice.contains("declared more than once in `error(…)`"),
    "{twice}"
  );

  let stray = refusal(&syn::parse_quote! {
    #[ingraph(error(text))]
    enum Codec { H264 }
  });
  assert!(stray.contains("unknown entry in `error(…)`"), "{stray}");
}

#[test]
fn refuses_a_declaration_that_is_not_an_enum() {
  let refused = refusal(&syn::parse_quote! {
    struct Codec { name: String }
  });
  assert!(refused.contains("supports enums only"), "{refused}");
}

#[test]
fn refuses_an_enum_with_no_variants() {
  let refused = refusal(&syn::parse_quote! {
    enum Codec {}
  });
  assert!(refused.contains("declares no vocabulary"), "{refused}");
}

/// Every offending variant is named, not just the first — the accumulation the shared error layer
/// exists for, over the refusal a vocabulary is most likely to hit.
#[test]
fn refuses_every_variant_that_carries_data() {
  let refused = refusal(&syn::parse_quote! {
    enum Shape { Unit, Tuple(u8), Named { width: u8 } }
  });
  assert!(refused.contains("`Tuple` carries data"), "{refused}");
  assert!(refused.contains("`Named` carries data"), "{refused}");
}

#[test]
fn refuses_a_generic_vocabulary() {
  let refused = refusal(&syn::parse_quote! {
    enum Codec<T> { H264, Vp9 }
  });
  assert!(refused.contains("generic vocabularies"), "{refused}");
}

#[test]
fn refuses_a_lifetime_and_a_where_clause_for_the_same_reason() {
  let by_lifetime = refusal(&syn::parse_quote! {
    enum Codec<'a> { H264 }
  });
  assert!(
    by_lifetime.contains("generic vocabularies"),
    "{by_lifetime}"
  );

  let by_clause = refusal(&syn::parse_quote! {
    enum Codec where Self: Sized { H264 }
  });
  assert!(by_clause.contains("generic vocabularies"), "{by_clause}");
}

/// **A rename under a face that stores numbers is refused**, rather than kept where nothing would
/// read it — and the message names the form and how to change it.
#[test]
fn refuses_a_rename_under_a_face_that_stores_the_discriminant() {
  let by_default = refusal(&syn::parse_quote! {
    enum Grade {
      #[ingraph(sqlite(rename = "lo"))]
      Low,
    }
  });
  assert!(
    by_default.contains("stores the discriminant"),
    "{by_default}"
  );
  assert!(by_default.contains("by default"), "{by_default}");

  let declared = refusal(&syn::parse_quote! {
    #[ingraph(mysql(integer))]
    enum Grade {
      #[ingraph(mysql(rename = "lo"))]
      Low,
    }
  });
  assert!(declared.contains("as this declaration says"), "{declared}");
}

/// **Two variants sharing one namespace's word is refused, and the CANONICAL namespace is checked
/// whether or not any face stores text** — `FromStr` parses it and a cursor pages through it, so a
/// collision there is a value that reads back as two variants.
#[test]
fn refuses_two_variants_that_collide_in_one_namespace() {
  let canonical = refusal(&syn::parse_quote! {
    enum Grade {
      #[ingraph(rename = "same")]
      Low,
      #[ingraph(rename = "same")]
      High,
    }
  });
  assert!(
    canonical.contains("in the canonical namespace"),
    "{canonical}"
  );

  let per_face = refusal(&syn::parse_quote! {
    #[ingraph(postgres(text))]
    enum Grade {
      #[ingraph(postgres(rename = "same"))]
      Low,
      #[ingraph(postgres(rename = "same"))]
      High,
    }
  });
  assert!(
    per_face.contains("in the `postgres` namespace"),
    "{per_face}"
  );

  // The same words in DIFFERENT namespaces are not a collision: a face spells each variant once,
  // and two faces are two namespaces.
  parse(&syn::parse_quote! {
    #[ingraph(postgres(text))]
    enum Grade {
      #[ingraph(postgres(rename = "same"), graphql(rename = "SAME"))]
      Low,
      High,
    }
  })
  .expect("one word per face per variant is the rule, and this keeps it");
}

/// The WIRE's default casing can collide where the canonical words do not — `Vp9` and `VP9` are two
/// stored words and one GraphQL member, and the sentence is the WIRE's because what breaks is a
/// document rather than a column.
#[test]
fn refuses_a_collision_the_wire_casing_creates() {
  let refused = refusal(&syn::parse_quote! {
    enum Codec { Vp9, VP9 }
  });
  assert!(refused.contains("are both `VP9` on the wire"), "{refused}");
}

/// The wire face is checked EVEN WHERE THE DECLARATION FLIPPED IT to the integer form, because that
/// block moves the ACCESSOR and not the schema: the face is emitted for every declaration and its
/// values are names, so two variants shouting one word is still a document with two meanings.
#[test]
fn refuses_a_wire_collision_under_a_face_declared_integer() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(graphql(integer))]
    enum Codec { Vp9, VP9 }
  });
  assert!(refused.contains("are both `VP9` on the wire"), "{refused}");
}

/// Two variants whose predicates are one method: a duplicate definition inside the expansion, at a
/// span the declaration cannot edit.
#[test]
fn refuses_two_variants_that_derive_one_predicate() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(graphql(integer))]
    enum Codec { Vp9, VP9 }
  });
  assert!(refused.contains("both derive `is_vp9`"), "{refused}");
}

/// A wire name is held to GraphQL's own Name production, exactly as a record's field is: nothing
/// downstream refuses one, and a schema naming a member outside that grammar is unreachable.
#[test]
fn refuses_a_wire_rename_that_is_not_a_graphql_name() {
  let refused = refusal(&syn::parse_quote! {
    enum Grade {
      #[ingraph(graphql(rename = "low grade"))]
      Low,
    }
  });
  assert!(refused.contains("is not a GraphQL name"), "{refused}");
}

/// **A width no dialect carries is refused where it would be STORED**, and left alone where it
/// would not — a vocabulary whose every face takes text renders no discriminant at all.
#[test]
fn refuses_a_repr_width_no_dialect_can_carry() {
  for word in IntegerWidth::UNCARRIED {
    let repr = syn::Ident::new(word, proc_macro2::Span::call_site());
    let refused = refusal(&syn::parse_quote! {
      #[repr(#repr)]
      enum Grade { Low }
    });
    assert!(refused.contains("not a width a vocabulary"), "{refused}");
  }

  parse(&syn::parse_quote! {
    #[repr(u64)]
    #[ingraph(sqlite(text), postgres(text), mysql(text), mongo(text))]
    enum Grade { Low }
  })
  .expect("a vocabulary stored as text everywhere renders no discriminant");
}

#[test]
fn refuses_a_word_no_form_answers_to() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(blob))]
    enum Codec { H264 }
  });
  assert!(
    refused.contains("unknown entry in `sqlite(…)`"),
    "{refused}"
  );
}

#[test]
fn refuses_two_forms_in_one_face() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(text, integer))]
    enum Codec { H264 }
  });
  assert!(refused.contains("a face takes ONE form"), "{refused}");
}

#[test]
fn refuses_a_repeated_face_block() {
  let on_the_enum = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(text), sqlite(integer))]
    enum Codec { H264 }
  });
  assert!(
    on_the_enum.contains("declared more than once"),
    "{on_the_enum}"
  );

  let on_a_variant = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(text))]
    enum Codec {
      #[ingraph(sqlite(rename = "a"), sqlite(rename = "b"))]
      H264,
    }
  });
  assert!(
    on_a_variant.contains("declared more than once on this variant"),
    "{on_a_variant}"
  );
}

/// An entry nobody reads is a rule its author believes they declared, so an unrecognised one is
/// refused rather than ignored — and the sentence names what this level does take.
///
/// The variant row was written with `persist`, the record grammar's own participation marker landing
/// where it means nothing. That marker is gone — a record's data fields ARE its row — so the row is
/// written with `skip`, which is the word the participation inversion left in its seat and is just
/// as much a record's field word and just as little a variant's.
#[test]
fn refuses_an_entry_a_vocabulary_does_not_take() {
  let on_the_enum = refusal(&syn::parse_quote! {
    #[ingraph(persist(sqlite))]
    enum Codec { H264 }
  });
  assert!(on_the_enum.contains("unknown entry"), "{on_the_enum}");
  assert!(on_the_enum.contains("`sqlite`"), "{on_the_enum}");

  let on_a_variant = refusal(&syn::parse_quote! {
    enum Codec {
      #[ingraph(skip)]
      H264,
    }
  });
  assert!(
    on_a_variant.contains("unknown entry in `#[ingraph(…)]` on a variant"),
    "{on_a_variant}"
  );

  let in_a_face = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(text))]
    enum Codec {
      #[ingraph(sqlite(type = "String"))]
      H264,
    }
  });
  assert!(
    in_a_face.contains("unknown entry in `sqlite(…)` on a variant"),
    "{in_a_face}"
  );
}

/// One compile reports the whole declaration, which is what the accumulating error layer buys: the
/// grammar mistake and the shape mistake are both here, from one pass.
#[test]
fn one_pass_reports_the_grammar_and_the_shape_together() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(blob))]
    enum Shape { Tuple(u8) }
  });
  assert!(
    refused.contains("unknown entry in `sqlite(…)`"),
    "{refused}"
  );
  assert!(refused.contains("`Tuple` carries data"), "{refused}");
}

/// The parser keeps the RUST spelling and hands the emitter an unraw'd canonical word — the `r#` is
/// Rust's escape and no part of the name.
#[test]
fn a_raw_variant_keeps_its_spelling_and_loses_its_escape() {
  let model = parse(&syn::parse_quote! {
    enum Codec { r#type }
  })
  .expect("a raw identifier is a variant like any other");
  let variant: &EnumVariant = &model.variants[0];

  assert_eq!(variant.ident.to_string(), "r#type");
  assert_eq!(variant.canonical(), "type");
  assert_eq!(variant.predicate(), "is_type");
}

/// **The WIRE words a bare declaration gets**: `SCREAMING_SNAKE_CASE`, which is GraphQL's own
/// convention, over the canonical word.
#[test]
fn a_bare_declaration_shouts_every_wire_value() {
  let model = parse(&syn::parse_quote! {
    pub enum Codec { H264, Vp9, Av1 }
  })
  .expect("unit variants and nothing else is the whole shape");

  assert_eq!(spelled(&model, Namespace::Graphql), ["H264", "VP9", "AV1"]);
}

/// **Both rename axes reach the wire**: a canonical `rename` moves every face that stated none, and
/// `graphql(rename = "…")` moves this one alone.
#[test]
fn both_rename_axes_move_the_wire_word() {
  let model = parse(&syn::parse_quote! {
    pub enum Channel {
      #[ingraph(rename = "mono")]
      Mono,
      #[ingraph(graphql(rename = "TWO_CHANNEL"))]
      Stereo,
      #[ingraph(rename = "sur", graphql(rename = "SURROUND_5_1"))]
      Surround,
    }
  })
  .expect("both axes are the vocabulary's own words");

  assert_eq!(
    spelled(&model, Namespace::Graphql),
    ["MONO", "TWO_CHANNEL", "SURROUND_5_1"],
    "the canonical word is what the default casing is applied TO, and a face's own word wins"
  );
}

/// **A raw identifier is canonically the word without its escape**, on the TYPE as well as on a
/// variant — the schema name is the Rust one unraw'd.
#[test]
fn a_raw_name_loses_only_its_escape_on_the_wire() {
  let model = parse(&syn::parse_quote! {
    pub enum r#Match { r#Type, r#Move }
  })
  .expect("a raw identifier is a name like any other");

  assert_eq!(spelled(&model, Namespace::Graphql), ["TYPE", "MOVE"]);
}

/// **A name outside GraphQL's Name grammar is refused**, on a variant and on the TYPE alike —
/// nothing downstream would: the schema builds, and the SDL it exports is not parseable GraphQL.
///
/// The type's own name is checked unconditionally now, because the wire face is emitted
/// unconditionally: there is no declaration that carries the storage rows and no schema surface for
/// the check to be premature for.
#[test]
fn a_wire_name_must_be_a_graphql_name() {
  let variant = refusal(&syn::parse_quote! {
    pub enum Codec {
      #[ingraph(graphql(rename = "h-264"))]
      H264,
    }
  });
  assert!(
    variant.contains("`h-264` is not a GraphQL name"),
    "{variant}"
  );

  let named = refusal(&syn::parse_quote! {
    pub enum Codéc { H264 }
  });
  assert!(named.contains("is not a GraphQL name"), "{named}");
}

/// **THE FOLD, as a test: ONE door emits BOTH organs.**
///
/// The storage citizenship and the wire face come out of one expansion — a vocabulary is not a thing
/// a declaration equips twice — and the wire half is wholly inside the binding gate, so a build
/// without `async-graphql` gets the storage rows and nothing else.
#[test]
fn one_door_emits_the_storage_rows_and_the_wire_face() {
  let model = parse(&syn::parse_quote! {
    pub enum Channel { Mono, Stereo }
  })
  .expect("the one door");
  let emitted = model.emit().to_string();

  for row in ["EnumFilterMarker", "DefaultMarker", "CursorValue"] {
    assert!(emitted.contains(row), "`{row}` is missing:\n{emitted}");
  }
  for face in ["if_async_graphql", "InputType", "EnumType"] {
    assert!(emitted.contains(face), "`{face}` is missing:\n{emitted}");
  }
  assert_eq!(
    emitted.matches("if_async_graphql").count(),
    1,
    "the wire face is ONE gated block:\n{emitted}"
  );
}

/// **The wire face reads the SAME words the storage accessors do**, which is what one model buys:
/// the value a client writes and the word `as_graphql_str` hands back come from one table.
#[test]
fn the_wire_face_carries_the_declarations_own_words() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(sqlite(text))]
    pub enum Channel {
      #[ingraph(rename = "mono", sqlite(rename = "m"), graphql(rename = "MONAURAL"))]
      Mono,
      Stereo,
      r#Type,
    }
  })
  .expect("every axis at once");
  let emitted = model.emit().to_string();

  for word in ["\"MONAURAL\"", "\"STEREO\"", "\"TYPE\"", "\"m\""] {
    assert!(emitted.contains(word), "`{word}` is missing:\n{emitted}");
  }
}

/// The upstream a mirror names, as it would be written.
fn mirrored(model: &EnumModel) -> String {
  rendered(&model.remote.as_ref().expect("the declaration mirrors").path)
}

/// **A MIRROR restates identifiers and nothing else**, and what it earns for them is the whole of
/// the mode: an upstream to convert to, and no word of its own anywhere.
#[test]
fn a_mirror_names_its_upstream_and_restates_its_variants() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Yuv420p,
      Rgb24,
    }
  })
  .expect("a restatement and the word that says whose");

  assert_eq!(mirrored(&model), "mediaframe::PixelFormat");
  assert_eq!(variants(&model), ["Yuv420p", "Rgb24"]);
  assert!(model.escape().is_none(), "no escape was declared");
  for variant in &model.variants {
    assert_eq!(
      variant.upstream(),
      variant.ident,
      "spelled alike by default"
    );
  }
}

/// **`rename` names the UPSTREAM variant on a mirror**, where on a declared vocabulary it names the
/// canonical word. There is no word here for it to move — the upstream spells them all — and a
/// restatement that misspells one is the one thing this mode can get wrong.
#[test]
fn a_renamed_variant_restates_a_differently_spelled_upstream() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      #[ingraph(rename = "Rgb888")]
      Rgb24,
    }
  })
  .expect("a rename names the upstream");

  assert_eq!(model.variants[0].upstream(), "Rgb888");
  assert!(
    model.variants[0].rename.is_none(),
    "and it moves no canonical word, a mirror having none"
  );
}

/// **The ESCAPE is marked, not guessed.** The name is free — the marker is what says which variant
/// catches a word this mirror does not name — and it carries that word in one unnamed field.
#[test]
fn the_escape_is_the_marked_variant_and_its_name_is_free() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other)]
      Unknown(::ingraph::Utf8Bytes),
    }
  })
  .expect("a marked escape");

  let escape = model.escape().expect("the marker found it");
  assert_eq!(escape.ident, "Unknown");
  assert_eq!(
    model.restated().count(),
    1,
    "the escape restates no upstream variant"
  );
}

/// **`delegate(fn …)` takes RUST, and it has to**: the language has no `typeof`, so the return type
/// of a forwarding method is written where it is known.
#[test]
fn delegated_signatures_are_carried_verbatim() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn is_planar(&self) -> bool,
      fn bits_per_component(&self, plane: usize) -> u8,
    ))]
    pub enum PixelFormat {
      Rgb24,
    }
  })
  .expect("two borrowed methods");

  let delegates = &model.remote.as_ref().expect("a mirror").delegates;
  assert_eq!(delegates.len(), 2);
  assert_eq!(delegates[0].signature.ident, "is_planar");
  assert_eq!(delegates[1].signature.ident, "bits_per_component");
}

/// **A CLOSED mirror keeps the refusal type and its rename**, because a closed upstream can refuse a
/// word and this vocabulary reports that as its own.
#[test]
fn a_closed_mirror_still_names_its_refusal() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", error(rename = "NoSuchFormat"))]
    pub enum PixelFormat {
      Rgb24,
    }
  })
  .expect("a closed mirror refuses, and names the refusal");

  assert_eq!(model.error(), "NoSuchFormat");
}

/// **Neither OPEN posture has a refusal type to name.** The escape says every word parses — the
/// upstream's own parse where the marker is bare, the gate's signature where `from` names one — so
/// `Err` is `Infallible` and the knob names something the expansion does not declare.
#[test]
fn an_open_mirror_has_no_refusal_type_for_the_knob_to_move() {
  for door in ["other", "other(from = \"mediaframe::PixelFormat::other\")"] {
    let cell: syn::Meta = syn::parse_str(door).expect("a marker");
    let refused = refusal(&syn::parse_quote! {
      #[ingraph(remote = "mediaframe::PixelFormat", error(rename = "NoSuchFormat"))]
      pub enum PixelFormat {
        Rgb24,
        #[ingraph(#cell)]
        Other(::ingraph::Utf8Bytes),
      }
    });

    assert!(
      refused.contains("this mirror has none"),
      "{door}: {refused}"
    );
    assert!(
      refused.contains("`other(try_from = \"…\")` is the posture whose door CAN refuse"),
      "and the sentence names the posture the knob IS for — {door}: {refused}"
    );
  }
}

/// **The HALF-OPEN posture is where the knob becomes legal**, the coexistence loosening exactly
/// where a refusal path exists and nowhere else.
#[test]
fn a_refusable_gate_may_name_its_refusal() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", error(rename = "NoSuchFormat"))]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other(try_from = "mediaframe::PixelFormat::try_other"))]
      Other(::ingraph::Utf8Bytes),
    }
  })
  .expect("a half-open mirror casts a refusal type, so the knob has one to move");

  assert_eq!(model.error(), "NoSuchFormat");
  assert!(model.refuses(), "and the parse can refuse");
}

/// **The escape takes ONE cell, and the words are the conversion family's.**
#[test]
fn the_escape_opens_one_of_two_doors() {
  for (door, gate, refuses) in [
    ("from", "mediaframe::PixelFormat::other", false),
    ("try_from", "mediaframe::PixelFormat::try_other", true),
  ] {
    let cell: syn::Meta = syn::parse_str(&format!("other({door} = \"{gate}\")")).expect("a cell");
    let model = parse(&syn::parse_quote! {
      #[ingraph(remote = "mediaframe::PixelFormat")]
      pub enum PixelFormat {
        Rgb24,
        #[ingraph(#cell)]
        Other(::ingraph::Utf8Bytes),
      }
    })
    .expect("a gated escape");

    let posture = model.posture().expect("the marker found it");
    assert_eq!(
      posture
        .gate()
        .map(|path| quote::quote!(#path).to_string().replace(' ', "")),
      Some(gate.to_owned()),
      "{door} names the gate"
    );
    assert_eq!(posture.refuses(), refuses, "{door}");
    assert_eq!(model.refuses(), refuses, "and the mirror follows it");
  }
}

/// **A BARE marker is the posture it always was**, reading the totality off the upstream's own type.
#[test]
fn a_bare_escape_still_reads_the_upstreams_type() {
  let model = parse(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  })
  .expect("a bare escape");

  let posture = model.posture().expect("the marker found it");
  assert!(posture.gate().is_none(), "no gate to name");
  assert!(!posture.refuses(), "and the mirror is open");
}

/// **Both cells at once is refused**, a door either being able to refuse a word or not.
#[test]
fn the_escape_opens_one_door_and_not_two() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other(from = "a::b", try_from = "c::d"))]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("are both declared on this escape"),
    "{refused}"
  );
  assert!(refused.contains("there is no third answer"), "{refused}");
}

/// **An EMPTY cell names no door**, where a bare marker already says the upstream's parse is total.
#[test]
fn an_empty_cell_names_no_door() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other())]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("An empty block names neither"),
    "{refused}"
  );
}

/// **The cell is a BLOCK**, never a value: `other = "…"` names nothing this grammar reads.
#[test]
fn the_escapes_cell_is_a_block_and_not_a_value() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other = "mediaframe::PixelFormat::other")]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(refused.contains("it carries a BLOCK"), "{refused}");
}

/// **A word inside the cell that names neither door is refused**, with the two that do named.
#[test]
fn a_cell_takes_the_two_words_it_knows() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other(via = "a::b"))]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(refused.contains("an escape opens ONE door"), "{refused}");
}

/// **A cell whose value is not a path is refused at the value**, as every typed option in this
/// grammar is.
#[test]
fn a_gate_is_a_path_in_a_string() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(other(from = 7))]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("take a PATH to the gate function"),
    "{refused}"
  );
}

/// **A GATE NEEDS AN UPSTREAM.** The two cells name a function turning a word into somebody else's
/// value, and a vocabulary this crate declares has no somebody else — its door is the roster walked
/// under the fold, which is total by construction.
#[test]
fn a_celled_escape_on_a_declaration_with_no_upstream_names_the_absent_upstream() {
  for cell in [
    quote::quote!(other(from = "a::b")),
    quote::quote!(other(try_from = "a::b")),
  ] {
    let refused = refusal(&syn::parse_quote! {
      pub enum Codec {
        H264,
        #[ingraph(#cell)]
        Other(::ingraph::Utf8Bytes),
      }
    });

    assert!(
      refused.contains("this declaration has no upstream"),
      "{refused}"
    );
    assert!(
      refused.contains("BARE `#[ingraph(other)]` is the whole marker here"),
      "{refused}"
    );
  }
}

/// **THE FOURTH CELL.** The bare marker on a declaration that mirrors nothing is an OPEN vocabulary
/// this crate declares, and the mode is read off the SHAPE — there is no word for it.
#[test]
fn the_escape_marker_opens_a_vocabulary_of_this_crates_own() {
  let model = accepted(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      LeftShoulder,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(model.remote.is_none(), "it mirrors nothing");
  assert_eq!(
    model.escape().map(|escape| escape.ident.to_string()),
    Some("Other".to_owned())
  );
  assert!(!model.refuses(), "an open door cannot refuse");
  assert_eq!(
    model
      .restated()
      .map(EnumVariant::folded)
      .collect::<Vec<_>>(),
    ["nose", "left_shoulder"],
    "and the words are the household fold of the Rust names"
  );
}

/// **`rename` OVERRIDES the fold**, and it is the only thing that moves a word in this cell.
#[test]
fn an_open_vocabularys_rename_names_a_word_rather_than_an_upstream_variant() {
  let model = accepted(&syn::parse_quote! {
    pub enum Symbology {
      #[ingraph(rename = "i2of5")]
      InterleavedTwoOfFive,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert_eq!(
    model
      .restated()
      .map(EnumVariant::folded)
      .collect::<Vec<_>>(),
    ["i2of5"]
  );
}

/// **ONE ESCAPE, in this cell too.** Two would be two answers to where an unnamed word goes, and the
/// refusal names both variants — a VOCABULARY rather than a mirror, since neither mirrors anything.
#[test]
fn an_open_vocabulary_takes_one_escape_and_refuses_a_second() {
  let refused = refusal(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
      #[ingraph(other)]
      Unknown(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("`Unknown` and `Other` are both marked"),
    "{refused}"
  );
  assert!(refused.contains("a vocabulary has ONE escape"), "{refused}");
}

/// **THE FORM KNOBS ARE GONE with the escape**, for the reason a mirror's are: a runtime word has no
/// discriminant behind it, so a face storing numbers could hold the members and not the one that is
/// not a member.
#[test]
fn an_open_vocabulary_names_no_form_and_spells_no_face() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(integer))]
    pub enum BodyJoint {
      #[ingraph(graphql(rename = "NOSE"))]
      Nose,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("an OPEN vocabulary has none to name"),
    "{refused}"
  );
  assert!(
    refused.contains("an OPEN vocabulary spells it one way everywhere"),
    "{refused}"
  );
}

/// **AN OPEN DOOR CANNOT REFUSE**, so `error(rename = "…")` has no type beside the enum to move —
/// which is the mirror's own law, one cell over.
#[test]
fn an_open_vocabulary_has_no_refusal_type_for_the_knob_to_move() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(error(rename = "NoSuchJoint"))]
    pub enum BodyJoint {
      Nose,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(refused.contains("this vocabulary has none"), "{refused}");
  assert!(refused.contains("Drop the escape"), "{refused}");
}

/// **THE ESCAPE HAS NO WORD TO RENAME** — it carries one rather than spelling one, so a `rename`
/// there would be a rule nobody reads.
#[test]
fn an_open_vocabularys_escape_carries_its_word_rather_than_spelling_one() {
  let refused = refusal(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      #[ingraph(other, rename = "unknown")]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("the escape has no canonical word for `rename` to move"),
    "{refused}"
  );
}

/// **TWO MEMBERS, ONE WORD** is refused at the second, whether the collision comes from the fold's
/// arithmetic or from a `rename` that walked onto another member's word.
#[test]
fn two_members_of_one_roster_may_not_spell_one_word() {
  let refused = refusal(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      #[ingraph(rename = "nose")]
      Snout,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("`Snout` and `Nose` are both `nose`"),
    "{refused}"
  );
}

/// **A PAYLOAD VARIANT IN AN OPEN VOCABULARY** is refused, the escape already existing — so the
/// accident the closed cell's sentence catches is not available as a reading here.
#[test]
fn a_roster_names_its_members_and_carries_one_word() {
  let refused = refusal(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      Extra(u8),
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("this vocabulary already has its escape"),
    "{refused}"
  );
}

/// **THE CLOSED CELL'S REFUSAL CARRIES THE ACCIDENT.** A declaration one word away from the shape it
/// wanted is told about `#[ingraph(other)]` before it is told about the union.
#[test]
fn a_payload_variant_in_a_closed_vocabulary_is_told_about_the_marker_it_forgot() {
  let refused = refusal(&syn::parse_quote! {
    pub enum BodyJoint {
      Nose,
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("`#[ingraph(other)]` on this variant is what says so"),
    "{refused}"
  );
  assert!(
    refused.contains("`#[derive(ingraph::Union)]` is the word for one"),
    "and the other road is still named: {refused}"
  );
}

/// **ONE escape.** Two would be two answers to where a word this mirror does not name goes, and the
/// refusal names both variants.
#[test]
fn a_mirror_takes_one_escape_and_refuses_a_second() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
      #[ingraph(other)]
      Unknown(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("`Unknown` and `Other` are both marked"),
    "{refused}"
  );
}

/// **The escape mirrors no upstream variant**, so there is none for a `rename` to name.
#[test]
fn the_escape_cannot_also_be_renamed() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      #[ingraph(other, rename = "Unknown")]
      Other(::ingraph::Utf8Bytes),
    }
  });

  assert!(
    refused.contains("the escape mirrors no upstream variant"),
    "{refused}"
  );
}

/// **The escape's SHAPE is one unnamed field**, that being where the word goes.
#[test]
fn the_escape_carries_exactly_one_unnamed_field() {
  for shape in [
    quote::quote!(Other),
    quote::quote!(Other(::ingraph::Utf8Bytes, u8)),
    quote::quote!(Other {
      word: ::ingraph::Utf8Bytes
    }),
  ] {
    let refused = refusal(&syn::parse_quote! {
      #[ingraph(remote = "mediaframe::PixelFormat")]
      pub enum PixelFormat {
        Rgb24,
        #[ingraph(other)]
        #shape,
      }
    });
    assert!(
      refused.contains("must carry EXACTLY ONE unnamed field"),
      "{shape}: {refused}"
    );
  }
}

/// **Only the escape may carry anything**, a restatement being identifiers.
#[test]
fn a_restated_variant_carries_no_payload() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24(u8),
    }
  });

  assert!(
    refused.contains("A mirror RESTATES its upstream's variants"),
    "{refused}"
  );
}

/// **No form knob on a mirror**, in either position: the stored word is the upstream's rendering,
/// the same in every face.
#[test]
fn a_mirror_takes_no_face_block() {
  let enum_level = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", sqlite(text))]
    pub enum PixelFormat {
      Rgb24,
    }
  });
  assert!(
    enum_level.contains("names a FORM for one face"),
    "{enum_level}"
  );

  let variant_level = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      #[ingraph(graphql(rename = "RGB24"))]
      Rgb24,
    }
  });
  assert!(
    variant_level.contains("a mirror spells it one way everywhere"),
    "{variant_level}"
  );
}

/// **`delegate(…)` needs something to forward to.**
#[test]
fn a_declaration_that_mirrors_nothing_delegates_nothing() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(delegate(fn is_planar(&self) -> bool))]
    pub enum Codec { H264 }
  });

  assert!(
    refused.contains("forwards a method onto a MIRRORED upstream value"),
    "{refused}"
  );
}

/// **THE FULL FORM REACHES THE MIRROR'S MODEL**, with the target on the entry it was written on.
///
/// One grammar, read once, for the two declarations that spend the seat — and now spent by both. The
/// two spellings are two `delegate(…)` blocks, which the seat ACCUMULATES, so one declaration says a
/// shorthand list and a named entry beside it, and the word moves that entry alone.
#[test]
fn the_full_form_carries_the_target_on_its_own_entry() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(
      remote = "mediaframe::PixelFormat",
      delegate(fn is_planar(&self) -> bool),
      delegate(
        #[graphql(async_graphql(rename = "depth"))]
        signature = fn bit_depth(&self) -> u32,
        on = self,
      ),
    )]
    pub enum PixelFormat { Rgb24 }
  });
  let delegates = &model.remote.as_ref().expect("a mirror").delegates;

  assert_eq!(delegates.len(), 2);
  assert_eq!(delegates[0].signature.ident, "is_planar");
  assert!(
    delegates[0].on_self.is_none(),
    "a shorthand entry waives nothing"
  );
  assert_eq!(delegates[1].signature.ident, "bit_depth");
  assert!(
    delegates[1].on_self.is_some(),
    "and the full form's own carries the word"
  );
  assert_eq!(
    delegates[1].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("depth"),
    "the PROMOTED half is untouched by the waiver — the resolver's arm is a qualified call on the \
     mirror either way"
  );
  assert_eq!(
    model.promoted(GraphqlKind::AsyncGraphql).count(),
    1,
    "and the promotion law reads `wire`, which the property does not touch"
  );
}

/// **THE SHARED DOOR IS REACHED FROM THIS MOUNT TOO** — the two refusals the grammar owns, earned at
/// the enum's own `delegate` entry.
#[test]
fn the_mirrors_mount_reaches_the_shared_grammar() {
  let mixed = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn is_planar(&self) -> bool,
      on = self,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(mixed.contains("written in ONE of two spellings"), "{mixed}");

  let target = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      signature = fn is_planar(&self) -> bool,
      on = upstream,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    target.contains("`on = upstream` names no target"),
    "{target}"
  );
  assert!(
    target.contains("`on` takes `self`, and `self` is the whole of it"),
    "and the roster is named: {target}"
  );
}

/// **A WAIVED ENTRY THAT PUBLISHES NOTHING HAS NO READER**, which is this tier's whole half of the
/// no-reader law.
///
/// A mirror always wraps — `delegate(…)` on a declaration that mirrors nothing is refused whole — so
/// the word is the only thing that can empty an entry here, and the companion verdict the field
/// fragment carries (a waiver with no mint to suppress) is unreachable.
#[test]
fn a_waived_entry_publishes_or_it_says_nothing() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      signature = fn bit_depth(&self) -> u32,
      on = self,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    refused.contains("`on = self` waives its forwarding half, so the entry has no reader"),
    "{refused}"
  );

  let shorthand = accepted(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(fn is_planar(&self) -> bool))]
    pub enum PixelFormat { Rgb24 }
  });
  assert_eq!(
    shorthand.remote.as_ref().expect("a mirror").delegates.len(),
    1,
    "and an unpublished entry that wrote NO property still mints, so it still has one"
  );
}

/// **AN ENTRY MEETING THE MIRROR'S OWN PREDICATE IS REFUSED AT THE ENTRY**, naming the variant whose
/// question it took.
///
/// The whole point of the walk: `E0592` reports this at the derive, a span the author cannot edit,
/// with a message that never mentions `Bayer`. Here the caret is on the restatement and the sentence
/// names both sides.
#[test]
fn a_delegate_may_not_take_a_variants_predicate() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(fn is_bayer(&self) -> bool))]
    pub enum PixelFormat { Rgb24, Bayer }
  });

  assert!(
    refused.contains("would declare `is_bayer` twice"),
    "{refused}"
  );
  assert!(
    refused.contains("the `Bayer` variant's predicate"),
    "the sentence names WHICH variant: {refused}"
  );
  assert!(
    refused.contains("the delegated `is_bayer`"),
    "and which side is the author's: {refused}"
  );
}

/// **THE WAIVER DOES NOT EXCUSE THE COLLISION**, because the name is taken either way.
///
/// `on = self` waives the forwarding mint, so the expansion writes nothing for the entry — and the
/// method exists all the same, on the `impl` the author wrote, meeting the emitted predicate there.
/// The enumeration answers which names are TAKEN rather than which tokens the emitter produced.
#[test]
fn a_waived_entry_may_not_take_a_variants_predicate_either() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql(async_graphql)]
      signature = fn is_bayer(&self) -> bool,
      on = self,
    ))]
    pub enum PixelFormat { Rgb24, Bayer }
  });

  assert!(
    refused.contains("would declare `is_bayer` twice"),
    "{refused}"
  );
  assert!(
    refused.contains("the `Bayer` variant's predicate"),
    "{refused}"
  );
}

/// **THE MODE'S OWN TWO WORDS ARE TAKEN TOO** — `remote()`, the single materialization gate, and the
/// `VARIANTS` roster beside it.
///
/// `VARIANTS` is an associated CONST rather than a method, and it is walked all the same: Rust's
/// value namespace holds consts and functions together, so an entry spelled that way is a duplicate
/// definition exactly as a second `remote` would be.
#[test]
fn a_delegate_may_not_take_the_modes_own_words() {
  let gate = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(fn remote(&self) -> u8))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(gate.contains("would declare `remote` twice"), "{gate}");
  assert!(
    gate.contains("the mirror's own upstream materialization"),
    "{gate}"
  );

  let roster = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(fn VARIANTS(&self) -> u8))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    roster.contains("would declare `VARIANTS` twice"),
    "{roster}"
  );
  assert!(
    roster.contains("the mirror's own restated-variant roster"),
    "{roster}"
  );
}

/// **TWO ENTRIES OF ONE NAME ARE TWO METHODS OF ONE NAME**, and this walk is their only reader.
///
/// The census (2026-08-26): nothing refused them before it. `published_fields` compares the SCHEMA
/// word of PUBLISHED entries — a different axis, a different namespace, and silent about two
/// unpublished entries — so the duplicate reached rustc as `E0592` inside the expansion. That is why
/// the record walk's `origin != origin` guard is not copied here: there, two methods of one origin
/// are a duplicate COLUMN name with a refusal of its own, and here they have no other reader.
#[test]
fn two_delegate_entries_may_not_share_a_name() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn planar(&self) -> bool,
      fn planar(&self) -> u8,
    ))]
    pub enum PixelFormat { Rgb24 }
  });

  assert!(
    refused.contains("would declare `planar` twice"),
    "{refused}"
  );
  assert!(
    refused.contains("the delegated `planar`, and the delegated `planar`"),
    "both sides are entries: {refused}"
  );
}

/// **TWO VARIANTS FOLDING TO ONE PREDICATE KEEP THEIR OWN RULE**, and earn one sentence rather than
/// two.
///
/// [`super::predicates`] refuses that pair at the second VARIANT's ident, which is a better caret
/// than anything this walk could reach — so the walk defers, exactly as the record's defers to its
/// duplicate-column rule. The deferral is what keeps one mistake to one sentence.
#[test]
fn two_variants_folding_to_one_predicate_are_still_the_variants_rule() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat { Rgb24, RGB24 }
  });

  assert!(refused.contains("both derive `is_rgb24`"), "{refused}");
  assert!(
    !refused.contains("would declare `is_rgb24` twice"),
    "and the collision walk says nothing about it: {refused}"
  );
}

/// **A NEAR MISS IS NOT A COLLISION** — the walk compares names and never spellings-that-look-alike.
///
/// The worse failure of the two would be a declaration refused for a clash that never happens, over
/// a method name its author chose. `is_bayer2` and `bayer` are both one character from a name this
/// mirror declares and neither is one.
#[test]
fn a_near_miss_of_an_emitted_name_still_compiles() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn is_bayer2(&self) -> bool,
      fn bayer(&self) -> bool,
      fn remotes(&self) -> u8,
      fn variants(&self) -> u8,
    ))]
    pub enum PixelFormat { Rgb24, Bayer }
  });

  assert_eq!(
    model
      .remote
      .as_ref()
      .expect("a mirror")
      .delegates
      .iter()
      .map(|delegate| delegate.signature.ident.to_string())
      .collect::<Vec<_>>(),
    ["is_bayer2", "bayer", "remotes", "variants"]
  );
}

/// **A delegated method BORROWS its receiver**, the body calling it on a value this side
/// materializes — so there is no `self` to consume and nothing for a receiverless signature to
/// forward from.
#[test]
fn a_delegated_method_borrows_its_receiver() {
  for signature in [
    quote::quote!(fn into_upstream(self) -> u8),
    quote::quote!(fn free() -> u8),
  ] {
    let refused = refusal(&syn::parse_quote! {
      #[ingraph(remote = "mediaframe::PixelFormat", delegate(#signature))]
      pub enum PixelFormat { Rgb24 }
    });
    assert!(
      refused.contains("a delegated method BORROWS its receiver"),
      "{signature}: {refused}"
    );
  }
}

/// **BOTH borrows are admitted, and the model says which is which** — the one fact the emitted body
/// forks on.
#[test]
fn a_delegate_takes_a_shared_or_an_exclusive_borrow() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn planar(&self) -> bool,
      fn demote(&mut self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  let delegates = &model.remote.as_ref().expect("a mirror").delegates;

  assert_eq!(delegates.len(), 2);
  assert!(!delegates[0].exclusive, "`&self` forwards");
  assert!(delegates[1].exclusive, "`&mut self` writes back");
}

/// **`#[graphql(<backend>)]` is an INCREMENTAL attribute**: the entry is still a function, and the
/// word only says it also reaches a schema.
#[test]
fn a_published_entry_is_a_delegate_that_also_reaches_a_schema() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn to_u32(&self) -> Option<u32>,
      #[graphql(async_graphql)]
      fn is_bayer(&self) -> bool,
      #[graphql(async_graphql(rename = "bayer"))]
      fn is_hdr(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  let delegates = &model.remote.as_ref().expect("a mirror").delegates;

  assert_eq!(delegates.len(), 3, "every entry is a method");
  assert_eq!(
    delegates[0].word(GraphqlKind::AsyncGraphql),
    None,
    "and the bare one publishes nothing"
  );
  assert_eq!(
    delegates[1].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("isBayer"),
    "the default knob folds to lower camel case"
  );
  assert_eq!(
    delegates[2].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("bayer"),
    "and `rename` is the word verbatim"
  );
  assert_eq!(
    model.promoted(GraphqlKind::AsyncGraphql).count(),
    2,
    "two of the three promote this mirror"
  );
}

/// **A `&mut self` entry may not be published** — a resolver READS, and that body writes a new value
/// back into the row it was called on.
#[test]
fn a_published_delegate_reads_its_receiver() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql(async_graphql)]
      fn demote(&mut self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });

  assert!(
    refused.contains("a published delegate takes `&self`"),
    "{refused}"
  );
}

/// **`#[graphql]` names a BACKEND**, in both of the shapes that name none — and any OTHER attribute
/// on an entry is refused outright.
#[test]
fn a_delegate_entry_wears_one_attribute_and_it_names_a_backend() {
  let bare = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql]
      fn planar(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(bare.contains("`#[graphql]` names no backend"), "{bare}");

  let empty = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql()]
      fn planar(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(empty.contains("`#[graphql]` names no backend"), "{empty}");

  let foreign = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[inline]
      fn planar(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    foreign.contains("a `delegate(…)` entry takes one attribute"),
    "{foreign}"
  );
}

/// **A promoted mirror's fields are ONE NAMESPACE** — `text` is taken, and lower camel case folds
/// two Rust spellings into one word.
#[test]
fn two_published_delegates_cannot_take_one_word() {
  let slug = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql(async_graphql(rename = "text"))]
      fn slug(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(slug.contains("this field would be called `text`"), "{slug}");

  let twice = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql(async_graphql)]
      fn is_bayer(&self) -> bool,
      #[graphql(async_graphql(rename = "isBayer"))]
      fn bayer(&self) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    twice.contains("two published methods are both called `isBayer`"),
    "{twice}"
  );
}

/// **A published delegate takes its receiver and nothing else**, a field's arguments being a grammar
/// this axis has not got. Unpublished, the same signature is fine.
#[test]
fn a_published_delegate_takes_no_arguments() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      #[graphql(async_graphql)]
      fn wider_than(&self, other: u32) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    refused.contains("takes its receiver and nothing else"),
    "{refused}"
  );

  let accepted = accepted(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat", delegate(
      fn wider_than(&self, other: u32) -> bool,
    ))]
    pub enum PixelFormat { Rgb24 }
  });
  assert_eq!(
    accepted.promoted(GraphqlKind::AsyncGraphql).count(),
    0,
    "and it promotes nothing"
  );
}

/// **Two variants cannot restate ONE upstream variant** — the second arm names a value the first
/// already took.
#[test]
fn two_variants_cannot_mirror_one_upstream_variant() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      Rgb24,
      #[ingraph(rename = "Rgb24")]
      Rgb888,
    }
  });

  assert!(refused.contains("both restate `Rgb24`"), "{refused}");
}

/// **A mirror is an enum**, there being no variants to restate anywhere else.
#[test]
fn a_mirror_of_a_struct_is_refused_as_a_mirror() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub struct PixelFormat(mediaframe::PixelFormat);
  });

  assert!(
    refused.contains("a mirror RESTATES its upstream's"),
    "{refused}"
  );
}

/// **The two values this grammar re-parses are refused where they are written.**
#[test]
fn the_mirrors_own_words_are_read_as_what_they_name() {
  let path = refusal(&syn::parse_quote! {
    #[ingraph(remote = "not a path!")]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(path.contains("must be a path to the vocabulary"), "{path}");

  let twice = refusal(&syn::parse_quote! {
    #[ingraph(remote = "a::One", remote = "a::Two")]
    pub enum PixelFormat { Rgb24 }
  });
  assert!(
    twice.contains("one declaration mirrors one vocabulary"),
    "{twice}"
  );

  let word = refusal(&syn::parse_quote! {
    #[ingraph(remote = "mediaframe::PixelFormat")]
    pub enum PixelFormat {
      #[ingraph(rename = "rgb-24")]
      Rgb24,
    }
  });
  assert!(word.contains("it names the UPSTREAM variant"), "{word}");
}

/// **`graphql(rename = "…")` MOVES THE SCHEMA NAME AND NOTHING ELSE** — the rename-parity ruling's
/// row for this device.
///
/// Three claims in one, because the word's whole value is that the three do not move together: the
/// wire name is the declaration's, the RUST name is untouched, and the refusal type — the other
/// emitted name in this grammar — still answers to `error(rename = "…")` alone.
#[test]
fn the_wire_name_is_the_declarations_and_reaches_nothing_else() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(graphql(rename = "BodyJoint"))]
    pub enum BodyJointName { Nose, LeftShoulder }
  });

  assert_eq!(model.wire_name.as_deref(), Some("BodyJoint"));
  assert_eq!(model.name, "BodyJointName", "the Rust name does not move");
  assert_eq!(
    model.error().to_string(),
    "BodyJointNameParseError",
    "the refusal type is built from the RUST name, which the wire word never touched"
  );
}

/// The name word and the FORM word are neighbours in one block and answer different questions, so a
/// declaration may write either, both, or neither.
#[test]
fn the_wire_block_holds_a_name_beside_a_form() {
  let both = accepted(&syn::parse_quote! {
    #[ingraph(graphql(text, rename = "Codec"))]
    pub enum VideoCodec { H264, Vp9 }
  });
  assert_eq!(both.wire_name.as_deref(), Some("Codec"));
  assert_eq!(both.form(Namespace::Graphql), StorageForm::Text);

  let neither = accepted(&syn::parse_quote! {
    pub enum VideoCodec { H264, Vp9 }
  });
  assert_eq!(neither.wire_name, None);
}

/// **A MIRROR AND AN OPEN VOCABULARY TAKE THE NAME AND REFUSE THE FORM**, and that split is the
/// whole reason the two words share a block without sharing a fate.
///
/// What a face STORES is settled by the mode — both of these store a word in every face — so a form
/// word there is refused. What a SCHEMA calls the declaration is a live question in all four cells,
/// a scalar's name being as much a commitment as an `enum`'s.
#[test]
fn a_word_storing_mode_still_names_its_scalar() {
  let open = accepted(&syn::parse_quote! {
    #[ingraph(graphql(rename = "BodyJoint"))]
    pub enum BodyJointName {
      Nose,
      #[ingraph(other)]
      Other(::ingraph::Utf8Bytes),
    }
  });
  assert_eq!(open.wire_name.as_deref(), Some("BodyJoint"));

  let mirror = accepted(&syn::parse_quote! {
    #[ingraph(remote = "upstream::Codec", graphql(rename = "Codec"))]
    pub enum MirroredCodec { H264, Vp9 }
  });
  assert_eq!(mirror.wire_name.as_deref(), Some("Codec"));

  let form = refusal(&syn::parse_quote! {
    #[ingraph(remote = "upstream::Codec", graphql(text))]
    pub enum MirroredCodec { H264, Vp9 }
  });
  assert!(form.contains("names a FORM for one face"), "{form}");
}

/// A word that is not a GraphQL Name is refused AT THE LITERAL, and the Rust name it replaced is no
/// longer anybody's business — so a declaration whose Rust name is fine and whose word is not still
/// earns exactly one sentence.
#[test]
fn refuses_a_wire_name_outside_graphqls_own_grammar() {
  for spelling in ["", "Not A Name", "9Lives"] {
    let refused = refusal(&syn::parse_quote! {
      #[ingraph(graphql(rename = #spelling))]
      pub enum Codec { H264 }
    });
    assert!(
      refused.contains("is not a GraphQL name") || refused.contains("a word in a string literal"),
      "{spelling:?}: {refused}"
    );
  }
}

/// A schema entity's name is not a Rust identifier, which is the 2026-08-13 ruling: a word that
/// names a type in GraphQL's own namespace has no Rust item behind it, so a Rust KEYWORD is an
/// ordinary word here.
#[test]
fn a_wire_name_may_be_a_rust_keyword() {
  let model = accepted(&syn::parse_quote! {
    #[ingraph(graphql(rename = "type"))]
    pub enum Kind { Reel, Frame }
  });
  assert_eq!(model.wire_name.as_deref(), Some("type"));
}

/// One declaration, one schema name.
#[test]
fn refuses_a_wire_name_declared_twice() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(graphql(rename = "A", rename = "B"))]
    pub enum Codec { H264 }
  });
  assert!(
    refused.contains("`rename` is declared more than once in `graphql(…)`"),
    "{refused}"
  );
}

/// **A STORED FACE HAS NO TYPE NAME**, and the refusal sends the author to the position that does
/// carry a word: the variant's own.
///
/// A column holds one member at a time, so a database face has a per-variant WORD and nothing at the
/// declaration's own grain for a `rename` to be about.
#[test]
fn refuses_a_rename_on_a_stored_face() {
  let refused = refusal(&syn::parse_quote! {
    #[ingraph(sqlite(rename = "codecs"))]
    pub enum Codec { H264 }
  });
  assert!(
    refused.contains("STORES this vocabulary and does not name it"),
    "{refused}"
  );
  assert!(
    refused.contains("`graphql(rename = \"…\")`"),
    "and it names the face that does: {refused}"
  );
}