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
//! The field-fragment tier's acceptance: the fields a fragment declares, and every family it may
//! not claim.

use ingraph_codegen::{fields::FieldsModel, prelude::*};
use quote::ToTokens as _;

/// The pass under test, over a declaration written the way the derive took one — see
/// [`host::split`](crate::host::split) — with BOTH HOST KINDS activated.
///
/// # Why the activation is supplied here rather than written thirty times
///
/// A fragment that names no host kind is a named refusal, and every fixture in this file that is not
/// ABOUT that rule would otherwise carry the same two words for no assertion — thirty copies of a
/// fact one test proves. So the words are appended after the declaration's own, where `set_once` sees
/// them as the first `record`/`entity` a declaration that wrote none has.
///
/// The WIRE face rides with them for the same reason: the tier publishes nothing unless asked, and a
/// suite about the field grammar would otherwise refuse every `graphql(rename = "…")` it wrote.
///
/// Appended rather than prepended, so a fixture writing its own `record(sqlite)` keeps it and earns
/// the DECLARED-TWICE refusal for the injected one — which is why the fixtures that write their own
/// activation, and every fixture about the activation itself, go through [`unactivated`] instead.
fn parse(input: &syn::DeriveInput) -> syn::Result<ingraph_codegen::fields::FieldsModel> {
  let (host, mut arguments) = crate::host::split(input);
  arguments.push(syn::parse_quote!(#[ingraph(record, entity, graphql)]));
  super::parse(&host, &arguments)
}

/// The same pass with NOTHING added — the door the activation's own fixtures come through.
fn unactivated(input: &syn::DeriveInput) -> syn::Result<ingraph_codegen::fields::FieldsModel> {
  let (host, arguments) = crate::host::split(input);
  super::parse(&host, &arguments)
}

/// The names of a model's fields, in declared order.
fn names(model: &FieldsModel) -> Vec<String> {
  model
    .fields
    .iter()
    .map(|field| field.column.name.to_string())
    .collect()
}

/// Every refusal the pass reported, JOINED — one compile reports every rule it can still see, and
/// a `syn::Error` renders only the first of a combined one.
fn refusals(input: syn::DeriveInput) -> String {
  parse(&input)
    .expect_err("the declaration is refused")
    .into_iter()
    .map(|e| e.to_string())
    .collect::<Vec<_>>()
    .join("\n")
}

#[test]
fn a_fragment_is_its_fields_in_order() {
  let m = parse(&syn::parse_quote! {
    pub struct Dimensions {
      #[ingraph(copy)] width: u32,
      #[ingraph(copy)] height: u32,
      label: String,
    }
  })
  .expect("a field-fragment declaration");
  assert_eq!(names(&m), ["width", "height", "label"]);
  assert_eq!(m.fragment, "Dimensions");
}

/// The three PROJECTION words are what this emission spends, so they are what it admits — and each
/// reaches the model as the shape it names. They are DECLARED rather than read off the written type,
/// which is a record's rule and holds here for its reason: a macro holds tokens, so an alias hiding
/// a `Vec` is one shape at this layer and only a declaration can say which.
#[test]
fn the_three_projection_words_reach_the_model() {
  let m = parse(&syn::parse_quote! {
    struct Shape {
      #[ingraph(copy)] width: u32,
      #[ingraph(repeated)] tags: Vec<String>,
      #[ingraph(optional)] note: Option<String>,
      plain: String,
    }
  })
  .expect("a field-fragment declaration");
  let project = |name: &str| {
    m.fields
      .iter()
      .map(|field| &field.column)
      .find(|column| column.name == name)
      .unwrap_or_else(|| panic!("`{name}` is a field"))
      .project
  };
  assert_eq!(project("width"), Projection::Copied);
  assert_eq!(project("tags"), Projection::Repeated);
  assert_eq!(project("note"), Projection::Optional);
  assert_eq!(
    project("plain"),
    Projection::Borrowed,
    "and none is the default"
  );
}

#[test]
fn the_crate_path_defaults_and_is_moveable() {
  let m = parse(&syn::parse_quote! { struct D { w: u32 } }).expect("the default");
  assert_eq!(m.krate.to_token_stream().to_string(), ":: ingraph");
  let m = parse(&syn::parse_quote! {
    #[ingraph(crate = "shim::vendored")]
    struct D { w: u32 }
  })
  .expect("a re-export shim");
  assert_eq!(m.krate.to_token_stream().to_string(), "shim :: vendored");
}

/// EVERY family a node writes, refused by name and in one pass — so an author migrating a
/// declaration reads what a fragment has instead of each, rather than one word per compile.
#[test]
fn every_family_a_node_claims_is_refused_by_name() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(
      subscribe = "a::A",
      implements(Media),
      key(rename = "DKey"),
      lineage(fields(a)),
      sqlite,
      fulltext(tantivy),
      vector(lance),
      blob(fs))]
    struct D { a: u32 }
  });
  for rule in [
    "a field fragment subscribes to nothing",
    "an interface's members are NODES WITH ROWS",
    "a field fragment has no key",
    "a field fragment has no lineage",
    "a field fragment is stored in no table of its own",
    "a field fragment owns no full-text index",
    "a field fragment owns no embedding index",
    "a field fragment owns no artifact store",
  ] {
    assert!(e.contains(rule), "missing `{rule}` in: {e}");
  }
  assert!(
    e.contains("A field fragment is HELD by whatever declares it"),
    "and every one of them carries the tier's own reason: {e}"
  );
  assert!(
    e.contains("is an `entity`, and one that holds rows besides is a `record`"),
    "which names BOTH rungs above it, so a migrating author reads which one they wanted: {e}"
  );
}

/// The id is refused PERMANENTLY and by definition, which is what separates it from the words that
/// are waiting for the inheritance.
#[test]
fn a_fragment_has_no_id_and_the_refusal_says_why() {
  let e = refusals(syn::parse_quote! { struct D { #[ingraph(id)] id: u128, w: u32 } });
  assert!(
    e.contains("cannot be a fragment's id, because a fragment has none")
      && e.contains("bearing no identity is what this tier means"),
    "{e}"
  );
}

/// A reference OUT of a fragment is refused by name rather than under the general wait, and the
/// sentence says where the question is tracked: it is not waiting for the inheritance, it is waiting
/// for a ruling on what such a reference would mean.
#[test]
fn a_reference_out_of_a_fragment_is_named_and_tracked() {
  let e = refusals(syn::parse_quote! {
    struct D { #[ingraph(ref = "media::Media")] media: MediaId, w: u32 }
  });
  assert!(
    e.contains("cannot reference another node from inside a fragment") && e.contains("issues/168"),
    "{e}"
  );
}

/// And the rest of the grammar is refused as a WAIT rather than as a law: the message names what
/// the words are for and what has not arrived to read them.
#[test]
fn the_inherited_field_grammar_is_a_named_refuse_until() {
  let e = refusals(syn::parse_quote! {
    struct D { #[ingraph(string)] label: String }
  });
  assert!(
    e.contains("a fragment's field takes the projection words")
      && e.contains("inherited by every holder"),
    "{e}"
  );
}

#[test]
fn a_fragment_with_no_fields_extracts_nothing() {
  let e = refusals(syn::parse_quote! { struct D {} });
  assert!(
    e.contains("a field fragment with no fields extracts nothing"),
    "{e}"
  );
}

#[test]
fn the_shape_rules_are_the_tiers_own() {
  let e = refusals(syn::parse_quote! { enum D { A } });
  assert!(
    e.contains("`#[ingraph::fields(record, entity)]` supports structs only"),
    "{e}"
  );
  let e = refusals(syn::parse_quote! { struct D(u32); });
  assert!(
    e.contains("what a holder inherits is a field's name as much as its type"),
    "{e}"
  );
  let e = refusals(syn::parse_quote! { struct D<T> { w: T } });
  assert!(
    e.contains("generic field fragments are not supported"),
    "{e}"
  );
}

/// The two EMISSION rules, which are a record's own in this tier's terms: a field may not take the
/// framework's reserved shape, and two of them may not derive one method.
#[test]
fn the_emission_rules_hold_over_a_fragment_too() {
  let e = refusals(syn::parse_quote! { struct D { __width__: u32 } });
  assert!(
    e.contains("__width__"),
    "the framework namespace is fenced: {e}"
  );
  let e = refusals(syn::parse_quote! {
    struct D { width: u32, #[ingraph(copy)] set_width: u32 }
  });
  assert!(e.contains("would declare `set_width` twice"), "{e}");
}

/// The REWRITE word reaches the model as a path, and one declaration wraps one type.
#[test]
fn the_rewrite_word_reaches_the_model_and_is_declared_once() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions")]
    struct D { #[ingraph(copy)] width: u32 }
  })
  .expect("a wrapping fragment");
  assert_eq!(
    m.remote
      .as_ref()
      .expect("the word reached the model")
      .to_token_stream()
      .to_string(),
    "upstream :: Dimensions"
  );
  // And ABSENT is the ordinary fragment, which is what keeps the mode free.
  assert!(
    parse(&syn::parse_quote! { struct D { w: u32 } })
      .expect("an ordinary fragment")
      .remote
      .is_none()
  );
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "a::A", remote = "b::B")]
    struct D { w: u32 }
  });
  assert!(e.contains("one declaration wraps one type"), "{e}");
}

/// THE MACRO OWNS THE REPRESENTATION of a wrapper, and only of a wrapper: `#[repr(…)]` is refused
/// where the mode makes it load-bearing and left alone where the author's item survives.
#[test]
fn a_wrapping_fragment_does_not_choose_its_own_representation() {
  let e = refusals(syn::parse_quote! {
    #[repr(C)]
    #[ingraph(remote = "upstream::Dimensions")]
    struct D { w: u32 }
  });
  assert!(
    e.contains("does not choose its own representation"),
    "the wrapper's `repr(transparent)` is the emission's: {e}"
  );
  parse(&syn::parse_quote! {
    #[repr(C)]
    struct D { w: u32 }
  })
  .expect("an ordinary fragment keeps its own item, and its own representation with it");
}

/// A MANIFEST FIELD has no real body, so an attribute with nowhere to land is refused by name —
/// and, again, only under the mode that deletes the field.
#[test]
fn a_manifest_field_carries_no_attribute_that_cannot_land() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions")]
    struct D { #[serde(skip)] w: u32 }
  });
  assert!(
    e.contains("is a MANIFEST entry") && e.contains("Doc comments migrate to the field's reader"),
    "{e}"
  );
  parse(&syn::parse_quote! {
    struct D { #[serde(skip)] w: u32 }
  })
  .expect("an ordinary fragment's field is a real field, and carries what its author wrote");
}

/// **A WRAPPER DOES NOT BUY AN IDENTITY SEAT.** The `id` refusal is the tier's own definition, so it
/// fires under the rewrite exactly as it fires without one — and it says the same thing, because the
/// reason has not changed.
#[test]
fn a_wrapping_fragment_still_bears_no_id() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Frame")]
    struct D { #[ingraph(id)] id: u128, #[ingraph(copy)] width: u32 }
  });
  assert!(
    e.contains("cannot be a fragment's id, because a fragment has none")
      && e.contains("bearing no identity is what this tier means"),
    "{e}"
  );
}

/// The unknown-entry sentence names the words the tier really takes — the two ACTIVATIONS first,
/// because a reader who wrote an unknown entry is a reader learning the vocabulary.
#[test]
fn an_unknown_entry_names_the_words_a_fragment_takes() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(derived(a))]
    struct D { w: u32 }
  });
  assert!(
    e.contains("it takes its HOST-KIND activations (`record[(<db>, …)]`, `entity`)")
      && e.contains(
        "`crate = \"…\"`, `remote = \"…\"`, `builder(…)`, `cursor[(…)]`, `filter = \"…\"` and \
         `delegate(fn …)`"
      ),
    "{e}"
  );
}

/// **A FRAGMENT NO HOST KIND CAN CONSUME**, which is the tier's own entry rule.
///
/// The refusal names both words and what each buys, because an author who wrote neither has not
/// decided rather than chosen wrongly.
#[test]
fn a_declaration_that_names_no_host_kind_is_refused() {
  let e = unactivated(&syn::parse_quote! {
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect_err("no host kind is a refusal")
  .to_string();
  assert!(
    e.contains("activates no host kind, so no declaration can consume it")
      && e.contains("`record[(<db>, …)]`")
      && e.contains("write `entity` to be held by the rung that bears an identity and no rows"),
    "{e}"
  );
}

/// EITHER word alone is enough, and each activates its own half.
#[test]
fn one_word_is_an_activation_and_two_are_two() {
  let stored = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, postgres))]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a record-hosted fragment");
  assert_eq!(
    stored
      .record
      .as_ref()
      .expect("the activation")
      .databases
      .iter()
      .map(|db| db.kind.as_str())
      .collect::<Vec<_>>(),
    ["sqlite", "postgres"]
  );
  assert!(!stored.entity);

  let held = unactivated(&syn::parse_quote! {
    #[ingraph(entity)]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("an entity-hosted fragment");
  assert!(held.record.is_none() && held.entity);

  let both = unactivated(&syn::parse_quote! {
    #[ingraph(record, entity)]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a fragment both kinds may hold");
  assert!(
    both
      .record
      .as_ref()
      .expect("the activation")
      .databases
      .is_empty()
      && both.entity
  );
}

/// **THE ENTITY DOOR IS NOT A HOLE** — `entity(…)` with anything in it is a named refusal.
#[test]
fn entity_hosting_has_nothing_to_configure_yet() {
  for written in [
    quote::quote!(entity(anything)),
    quote::quote!(entity = "yes"),
    quote::quote!(entity()),
  ] {
    let e = unactivated(&syn::parse_quote! {
      #[ingraph(#written, record)]
      struct D { w: u32 }
    })
    .expect_err("the door refuses a configuration")
    .to_string();
    assert!(
      e.contains("entity-hosting has nothing to configure yet")
        && e.contains("a configuration you need is a ruling away"),
      "{written}: {e}"
    );
  }
}

/// The `record(…)` namespace names DIALECTS, and the row's own words stay the holder's.
#[test]
fn the_record_namespace_names_databases_and_nothing_else() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(table = "frames"))]
    struct D { w: u32 }
  })
  .expect_err("the row's own word is refused")
  .to_string();
  assert!(
    e.contains("the namespace names DIALECTS")
      && e.contains("`table` and `schema` name where a row lives"),
    "{e}"
  );

  let twice = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, sqlite))]
    struct D { w: u32 }
  })
  .expect_err("one entry per database")
  .to_string();
  assert!(
    twice.contains("is named more than once in `record(…)`"),
    "{twice}"
  );
}

/// **THE WIRE FACE IS A THIRD ACTIVATION**, and it is not a host kind: it says the declaration has a
/// face a client can reach at all.
#[test]
fn the_wire_face_is_declared_and_names_its_two_types() {
  let silent = unactivated(&syn::parse_quote! {
    #[ingraph(record)]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a storage-only fragment");
  assert!(
    silent.wire.is_none(),
    "a fragment publishes nothing unless it asks"
  );

  let named = unactivated(&syn::parse_quote! {
    #[ingraph(record, graphql(rename = "Size", filter(rename = "SizeWhere")))]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a published fragment");
  let face = named.wire.as_ref().expect("the activation");
  assert_eq!(
    face.object.as_ref().map(|name| name.external()),
    Some("Size")
  );
  assert_eq!(
    face.filter.as_ref().map(|name| name.external()),
    Some("SizeWhere")
  );

  let bare = unactivated(&syn::parse_quote! {
    #[ingraph(record, graphql)]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a published fragment that renames nothing");
  let face = bare.wire.as_ref().expect("the activation");
  assert!(face.object.is_none() && face.filter.is_none());
}

/// A ROOT word is refused by name, because a fragment is not one — the old refusal's own sentence,
/// now the signpost inside the word that replaced it.
#[test]
fn a_fragments_wire_block_names_types_and_never_a_root() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record, graphql(plural = "sizes"))]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect_err("a root word")
  .to_string();
  assert!(
    e.contains("the queryable-root words (`plural`, `connection`, `edge`, `key`, `order_by`)")
      && e.contains("a fragment shows on the wire as a fragment of whatever holds it"),
    "{e}"
  );
}

/// **ONE FIELD, ONE NAME ON THE WIRE** — the word reaches the model, and a name on a face that does
/// not exist is refused.
#[test]
fn a_field_names_itself_only_where_there_is_a_face() {
  let m = unactivated(&syn::parse_quote! {
    #[ingraph(record, graphql)]
    struct Dimensions {
      #[ingraph(copy, graphql(rename = "w"))]
      width: u32,
    }
  })
  .expect("a renamed field");
  assert_eq!(m.fields[0].wire_name.as_deref(), Some("w"));

  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record)]
    struct Dimensions {
      #[ingraph(copy, graphql(rename = "w"))]
      width: u32,
    }
  })
  .expect_err("a name on nothing")
  .to_string();
  assert!(
    e.contains("names itself on a wire face this fragment does not have"),
    "{e}"
  );
}

/// **A PAGING POSITION IS A STORED ORDER** — `cursor` needs the kind that has rows to page.
#[test]
fn a_cursor_needs_the_record_host() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(entity, cursor)]
    struct CalendarDay { #[ingraph(copy)] year: i32 }
  })
  .expect_err("an entity-only fragment pages nothing")
  .to_string();
  assert!(
    e.contains("paging is the record host's")
      && e.contains("add `record[(<db>, …)]` beside the word"),
    "{e}"
  );
}

/// **THE BARE WORD IS THE EMPTY KEY**, which is the declared order and every field of it.
///
/// Empty rather than the field list spelled into the model, because the two would be the same list
/// twice — and the emission already walks the declaration in order.
#[test]
fn the_bare_cursor_word_is_the_declared_order() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(cursor)]
    pub struct CalendarDay {
      #[ingraph(copy)] year: i32,
      #[ingraph(copy)] month: i32,
    }
  })
  .expect("the word parses");

  assert_eq!(m.cursor.as_deref(), Some(&[][..]));
}

/// **A PINNED KEY IS KEPT AS WRITTEN**, having been checked against the declaration — and what it is
/// checked to be is that same declaration, in that same order.
#[test]
fn a_pinned_cursor_key_is_the_declaration_spelled_out() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(cursor(year, month))]
    pub struct CalendarDay {
      #[ingraph(copy)] year: i32,
      #[ingraph(copy)] month: i32,
    }
  })
  .expect("the pin holds");

  assert_eq!(
    m.cursor
      .as_ref()
      .map(|key| key.iter().map(ToString::to_string).collect::<Vec<_>>()),
    Some(vec!["year".to_owned(), "month".to_owned()])
  );
}

/// A pin that names another ORDER is refused, and the sentence writes the key out — an author who
/// meant the other order is told the one edit that gets it.
#[test]
fn a_reordered_cursor_key_is_refused_with_the_key_written_out() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(cursor(month, year))]
    struct CalendarDay {
      #[ingraph(copy)] year: i32,
      #[ingraph(copy)] month: i32,
    }
  });
  assert!(e.contains("`cursor(year, month)`"), "{e}");
  assert!(e.contains("the SQL keyset compares"), "{e}");
}

/// And one that names FEWER than all of them, for the other half of the same reason: a cursor's slot
/// is the boundary row's WHOLE value.
#[test]
fn a_partial_cursor_key_is_refused() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(cursor(year))]
    struct CalendarDay {
      #[ingraph(copy)] year: i32,
      #[ingraph(copy)] month: i32,
    }
  });
  assert!(e.contains("a pin states the declared order in full"), "{e}");
}

/// An `optional` column cannot be a position: a page resumes STRICTLY AFTER a boundary, and an
/// absent value has no place in the run it would resume.
#[test]
fn an_optional_column_is_no_cursor_position() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(cursor)]
    struct Window {
      #[ingraph(copy)] start: i64,
      #[ingraph(optional)] end: Option<i64>,
    }
  });
  assert!(e.contains("`end` is `optional`"), "{e}");
  assert!(e.contains("STRICTLY AFTER"), "{e}");
}

/// **A FRAMED CURSOR HAS NO ERROR ROAD**, so a `fallible` protocol and the word are two claims about
/// one answer wherever a framed body is still emitted — which the bare `record` word's dialect-free
/// row always is.
#[test]
fn a_fallible_protocol_is_no_cursor_position() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "up::Day", cursor, builder(fallible))]
    struct Day {
      #[ingraph(copy)] year: i32,
    }
  });
  assert!(e.contains("nowhere in that answer for an `Err`"), "{e}");
  assert!(
    e.contains("mount a codec at every dialect this fragment declares"),
    "the third exit is offered: {e}"
  );
  assert!(
    e.contains("names no dialect to mount one at"),
    "and a declaration with no dialect group is told why the exit is shut to it: {e}"
  );
}

/// …and ONE dialect that mounted nothing keeps it, that dialect's row BEING the framed body. The
/// refusal names which, so the next edit has an address rather than a search.
#[test]
fn a_partly_mounted_cursor_keeps_the_fallible_refusal() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(
      record(sqlite(cursor = "up::DayCursor"), postgres),
      remote = "up::Day",
      cursor,
      builder(fallible)
    )]
    struct Day {
      #[ingraph(copy)] year: i32,
    }
  })
  .expect_err("a framed dialect is still a framed dialect")
  .into_iter()
  .map(|one| one.to_string())
  .collect::<Vec<_>>()
  .join("\n");
  assert!(e.contains("nowhere in that answer for an `Err`"), "{e}");
  assert!(
    e.contains("No codec is mounted at `postgres`"),
    "the unmounted dialect is named: {e}"
  );
}

/// **EVERY DECLARED DIALECT MOUNTED ADMITS IT**, which is the whole narrowing: the keyset forks
/// wholly to the per-dialect rows, every one of them delegates, and no emitted read raises — so
/// there is no `Result` for an `Option` to have swallowed.
#[test]
fn a_cursor_mounted_at_every_dialect_admits_a_fallible_protocol() {
  let m = unactivated(&syn::parse_quote! {
    #[ingraph(
      record(sqlite(cursor = "up::DayCursor"), postgres(cursor = "up::PgDayCursor")),
      remote = "up::Day",
      cursor,
      builder(fallible)
    )]
    struct Day {
      #[ingraph(copy)] year: i32,
    }
  })
  .expect("no framed body is emitted, so nothing raises");
  assert!(m.construction.fallible, "the protocol is kept as written");
  assert!(m.cursor.is_some(), "and so is the paging position");
}

/// **THE CONSTRUCTION WORDS REACH THIS TIER**, both seats, and they are kept where the emission
/// spends them.
#[test]
fn a_wrapping_fragment_takes_the_construction_vocabulary() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(remote = "up::Spec", builder(entry = "open", finish = "seal"))]
    struct Spec {
      #[ingraph(copy, builder(arg))] count: u32,
      #[ingraph(builder(with = "labelled"))] label: String,
    }
  })
  .expect("the protocol parses");

  assert_eq!(m.construction.entry, "open");
  assert_eq!(
    m.construction.finish.as_ref().map(ToString::to_string),
    Some("seal".to_owned())
  );
  assert!(m.fields[0].build.seat.is_some(), "the first field's seat");
  assert!(m.fields[1].build.seat.is_some(), "and the second's");
}

/// …and are refused, by name and at both seats, on a fragment that wraps NOTHING — an ordinary
/// fragment IS its fields, so a raise writes the struct literal and there is no call to describe.
#[test]
fn a_held_fragment_takes_no_construction_word() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(builder(entry = "open"))]
    struct Spec {
      #[ingraph(copy, builder(arg))] count: u32,
    }
  });
  assert_eq!(
    e.matches("this field fragment is its own fields").count(),
    2,
    "one refusal per seat: {e}"
  );
}

/// **THE INNER MOUNT'S LAYOUT WORD REACHES THE MODEL**, and every other field keeps the default:
/// the bare type position, prefixed with the field's own name.
#[test]
fn a_flattened_inner_mount_reaches_the_model() {
  let m = parse(&syn::parse_quote! {
    pub struct ObjectDetection {
      bounds: BoundingBox,
      #[ingraph(record(flatten))]
      classification: Classification,
    }
  })
  .expect("a nesting fragment");
  assert_eq!(
    m.fields
      .iter()
      .map(|field| field.flatten)
      .collect::<Vec<_>>(),
    [false, true]
  );
}

/// **A DIALECT-SCOPED LAYOUT IS REFUSED FOR A REASON**, rather than as a round that has not arrived:
/// what a fragment publishes is one dialect-free `SEGMENTS`, and no participation model changes that.
#[test]
fn a_database_scoped_flatten_is_refused_at_a_fragments_field() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite))]
    struct ObjectDetection {
      #[ingraph(record(sqlite(flatten)))]
      classification: Classification,
    }
  })
  .expect_err("a dialect-scoped layout")
  .to_string();
  assert!(e.contains("scopes a LAYOUT to one dialect"), "{e}");
  assert!(e.contains("Write `record(flatten)`"), "{e}");
}

/// **`persist` IS RETIRED AT THIS SEAT**, and the refusal carries the whole migration.
#[test]
fn the_retired_persist_word_carries_its_migration() {
  for written in [
    quote::quote!(#[ingraph(persist)]),
    quote::quote!(#[ingraph(persist(flatten))]),
    quote::quote!(#[ingraph(persist = "flatten")]),
    quote::quote!(#[ingraph(persist(rename = "label"))]),
  ] {
    let e = refusals(syn::parse_quote! {
      struct ObjectDetection {
        #written
        classification: Classification,
      }
    });
    assert!(
      e.contains("`persist` is retired at a fragment's field")
        && e.contains("write `#[ingraph(record(flatten))]`"),
      "{written}: {e}"
    );
  }
}

/// `record` says nothing on its own at a field, and a word the namespace has never had names the two
/// it does — and why the record seat's other two are not here yet.
#[test]
fn the_record_namespace_takes_the_words_it_can_honour() {
  for written in [
    quote::quote!(#[ingraph(record)]),
    quote::quote!(#[ingraph(record())]),
    quote::quote!(#[ingraph(record = "flatten")]),
  ] {
    let e = refusals(syn::parse_quote! {
      struct ObjectDetection {
        #written
        classification: Classification,
      }
    });
    assert!(
      e.contains("`record(…)` on a field takes the storage words"),
      "{written}: {e}"
    );
  }
  // `sortable` is MIRRORED rather than waiting: it reaches the record seat's own rule, at a seat
  // where no field can meet it.
  let e = refusals(syn::parse_quote! {
    struct ObjectDetection {
      #[ingraph(record(sortable))]
      classification: Classification,
    }
  });
  assert!(
    e.contains("there is no order for a companion column to preserve on `classification`"),
    "{e}"
  );

  // And `rename` is a word this tier SPENDS, so it is read rather than refused.
  let m = parse(&syn::parse_quote! {
    struct ObjectDetection {
      #[ingraph(record(rename = "kind"))]
      classification: Classification,
    }
  })
  .expect("the column names itself where it is stored");
  assert_eq!(m.fields[0].stored_name.as_deref(), Some("kind"));
}

/// **THE DECLARED ABSENCE**, one namespace in — and the fill reaches the model with the word's own
/// span.
#[test]
fn a_skipped_column_reaches_the_model_with_its_fill() {
  let m = parse(&syn::parse_quote! {
    pub struct Detection {
      #[ingraph(copy)]
      score: u32,
      #[ingraph(record(skip(default = "crate::none")))]
      cached: String,
    }
  })
  .expect("a fragment with a skipped column");
  assert!(m.fields[0].skip.is_none());
  let fill = m.fields[1].skip.as_ref().expect("the declared absence");
  assert_eq!(
    fill
      .named
      .as_ref()
      .map(|path| quote::quote!(#path).to_string()),
    Some("crate :: none".to_owned())
  );
}

/// The dialect half is refused with the MEASUREMENT that says why: a fragment's layout, its bind
/// and its read are dialect-free by construction, and the read cannot be split at all.
#[test]
fn a_per_dialect_claim_names_the_wall_and_the_seat_that_has_one() {
  let narrowed = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, postgres))]
    struct Detection {
      #[ingraph(record(sqlite))]
      score: u32,
    }
  })
  .expect_err("a proper subset is a narrowing")
  .to_string();
  assert!(
    narrowed.contains("two `Assemble` impls constrained to different `Row::Database`s are `E0119`"),
    "the wall is a measurement rather than a wait: {narrowed}"
  );
  assert!(
    narrowed.contains("is the HOLDER's to write, on the field that mounts this fragment"),
    "and the seat that HAS a row per database is named: {narrowed}"
  );

  let absent = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, postgres))]
    struct Detection {
      #[ingraph(record(sqlite(skip(default = "crate::none"))))]
      score: u32,
    }
  })
  .expect_err("a per-dialect absence needs a per-dialect read")
  .to_string();
  assert!(
    absent.contains("withholds `score` from ONE dialect"),
    "the record seat's own per-database fill reaches this seat through the shared reader, and is \
     answered by name: {absent}"
  );

  let restated = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, postgres))]
    struct Detection {
      #[ingraph(record(sqlite, postgres))]
      score: u32,
    }
  });
  assert!(restated.is_ok(), "naming every database takes nothing away");

  let undeclared = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite))]
    struct Detection {
      #[ingraph(record(mongo))]
      score: u32,
    }
  })
  .expect_err("a database the head never named")
  .to_string();
  assert!(
    undeclared.contains("`mongo` is not a database this fragment names"),
    "{undeclared}"
  );

  let configured = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite))]
    struct Detection {
      #[ingraph(record(sqlite(rename = "s")))]
      score: u32,
    }
  })
  .expect_err("a per-dialect rendering has no list to render into")
  .to_string();
  assert!(
    configured.contains("says how ONE database renders `score`"),
    "{configured}"
  );
}

/// The namespace is read only where the host it speaks to was declared.
#[test]
fn a_column_word_needs_the_record_host() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(entity)]
    struct Detection {
      #[ingraph(record(flatten))]
      inner: Classification,
    }
  })
  .expect_err("no record host to speak to")
  .to_string();
  assert!(
    e.contains("says something to the RECORD host and this fragment declares none"),
    "{e}"
  );
}

/// One marker, one layout — a second `flatten` on one field is the same refusal a second projection
/// word gets.
#[test]
fn a_field_is_flattened_once() {
  let e = refusals(syn::parse_quote! {
    struct ObjectDetection {
      #[ingraph(record(flatten, flatten))]
      classification: Classification,
    }
  });
  assert!(e.contains("`flatten` is declared more than once"), "{e}");
}

/// **A FRAGMENT THAT HOLDS ITSELF IS REFUSED AT THE FIELD**, and the sentence names the cycle and the
/// rung that can point at another instance instead.
#[test]
fn a_fragment_that_holds_itself_is_refused() {
  for held in [quote::quote!(Detection), quote::quote!(Option<Detection>)] {
    let e = refusals(syn::parse_quote! {
      struct Detection { inner: #held }
    });
    assert!(
      e.contains("`Detection` → `Detection` is a cycle"),
      "{held}: {e}"
    );
    assert!(e.contains("has no width"), "{held}: {e}");
  }
}

/// **AND A COLLECTION OF ITSELF IS NOT ONE.** A `Vec` rides ONE column and its width row says so
/// without ever reading the element's, so there is no descent to be infinite — the refusal a
/// collection of fragments earns is a different one, and it is the holder's.
#[test]
fn a_collection_of_the_fragments_own_type_is_not_a_cycle() {
  let m = parse(&syn::parse_quote! {
    struct Detection {
      #[ingraph(repeated)]
      children: Vec<Detection>,
    }
  })
  .expect("a collection is one column");
  assert_eq!(names(&m), ["children"]);
}

/// **THE SWAP REACHES THE MODEL AS A PATH**, unresolved — the type it names is not this
/// declaration's to mint, so the check is the compiler's at the string the author wrote.
#[test]
fn the_filter_word_mounts_the_authors_predicate() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(filter = "crate::faces::DimensionsWhere")]
    pub struct Dimensions {
      #[ingraph(copy)] width: u32,
    }
  })
  .expect("a field-fragment declaration");
  assert_eq!(
    m.filter.map(|path| path.to_token_stream().to_string()),
    Some("crate :: faces :: DimensionsWhere".to_owned())
  );
}

/// One fragment is compared by ONE predicate, so a second `filter` is a second answer to one
/// question.
#[test]
fn the_filter_word_is_written_once_and_takes_a_path_in_a_string() {
  let twice = refusals(syn::parse_quote! {
    #[ingraph(filter = "A", filter = "B")]
    struct D { w: u32 }
  });
  assert!(
    twice.contains("`filter` is declared more than once"),
    "{twice}"
  );

  let bare = refusals(syn::parse_quote! {
    #[ingraph(filter)]
    struct D { w: u32 }
  });
  assert!(bare.contains("in a string literal"), "{bare}");
}

/// **THE SWAP IS ORTHOGONAL TO THE ACTIVATIONS.** It says WHICH predicate; whether one is emitted at
/// all is the host kind's answer, so a fragment that mounts one and activates nothing is refused for
/// the activation and never for the mount.
#[test]
fn a_mounted_predicate_does_not_activate_a_host_kind() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(filter = "DimensionsWhere")]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect_err("a declaration that names no host kind is refused")
  .into_iter()
  .map(|e| e.to_string())
  .collect::<Vec<_>>()
  .join("\n");
  assert!(e.contains("activates no host kind"), "{e}");
  assert!(
    !e.contains("`filter`"),
    "and the mount itself earns no sentence: {e}"
  );
}

/// **THE SEAT DOES NOT ASK WHERE A METHOD CAME FROM.** An entry names a method reachable on `Self`,
/// so an ordinary fragment reaching one the author wrote in an inherent `impl` is legal — clause ⑨
/// to the letter, and what the earlier requires-a-`remote` reading got wrong.
#[test]
fn an_own_fragment_may_publish_a_method_of_its_own() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(delegate(
      #[graphql(async_graphql)]
      fn aspect_ratio(&self) -> f64,
      #[graphql(async_graphql(rename = "wide"))]
      fn is_landscape(&self) -> bool,
    ))]
    pub struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a fragment that wraps nothing may still name its own methods");
  assert_eq!(m.delegates.len(), 2);
  assert_eq!(
    m.delegates[0].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("aspectRatio")
  );
  assert_eq!(
    m.delegates[1].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("wide")
  );
}

/// **WHAT IS REFUSED IS AN ENTRY WITH NO READER, NEVER ITS ORIGIN.**
///
/// On a wrapper a plain entry mints the inherent forwarding method a `Deref` would otherwise be
/// needed for. On a fragment that wraps nothing the method is already the author's, so an entry that
/// publishes nothing buys exactly nothing — and a word nobody reads is a rule its author believes
/// they declared.
#[test]
fn an_own_entry_that_publishes_nothing_has_no_reader() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(delegate(fn aspect(&self) -> u32))]
    struct D { w: u32 }
  });
  assert!(e.contains("`aspect` publishes nothing"), "{e}");
  assert!(
    !e.contains("forwards onto the value a declaration WRAPS"),
    "and the ORIGIN refusal is withdrawn: {e}"
  );

  let wrapped = parse(&syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(fn aspect(&self) -> u32))]
    struct D { #[ingraph(copy)] w: u32 }
  })
  .expect("a wrapper's plain entry mints the forwarding method");
  assert_eq!(wrapped.delegates.len(), 1);
}

/// The seat's grammar is #323's to the letter, read by the shared front end — the entries reach the
/// model with their receiver and their publication, and this tier's own sentences carry the
/// refusals.
#[test]
fn the_seat_reads_the_shared_grammar() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      fn aspect_ratio(&self) -> u32,
      #[graphql(async_graphql)]
      fn orientation(&self) -> u64,
      #[graphql(async_graphql(rename = "wide"))]
      fn is_landscape(&self) -> bool,
      fn normalise(&mut self),
    ))]
    struct Dimensions { w: u32 }
  })
  .expect("a wrapping fragment with a delegate seat");
  let spelled: Vec<String> = m
    .delegates
    .iter()
    .map(|delegate| delegate.signature.ident.to_string())
    .collect();
  assert_eq!(
    spelled,
    ["aspect_ratio", "orientation", "is_landscape", "normalise"]
  );
  assert!(
    m.delegates[0].wire.is_empty(),
    "a plain entry publishes nothing"
  );
  assert_eq!(
    m.delegates[1].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("orientation")
  );
  assert_eq!(
    m.delegates[2].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("wide"),
    "and `rename` moves the word a client writes"
  );
  assert!(
    m.delegates[3].exclusive,
    "an exclusive receiver is delegable — it mutates the wrapped value in place"
  );
}

/// **THE FULL FORM REACHES THE MODEL**, with the target on the entry it was written on.
///
/// The two spellings are two `delegate(…)` blocks and the seat ACCUMULATES, so one declaration says
/// both: a shorthand list of bare signatures, and a named entry beside it. What the word moves is
/// that entry alone — every other reaches the model exactly as it did.
#[test]
fn the_full_form_carries_the_target_on_its_own_entry() {
  let m = parse(&syn::parse_quote! {
    #[ingraph(
      remote = "upstream::Dimensions",
      delegate(fn label(&self) -> String),
      delegate(
        #[graphql(async_graphql(rename = "diagonal"))]
        signature = fn diagonal_pixels(&self) -> u64,
        on = self,
      ),
    )]
    struct D { #[ingraph(copy)] w: u32 }
  })
  .expect("a wrapper naming a method of its own");
  assert_eq!(m.delegates.len(), 2);
  assert_eq!(m.delegates[0].signature.ident, "label");
  assert!(
    m.delegates[0].on_self.is_none(),
    "a shorthand entry waives nothing"
  );
  assert_eq!(m.delegates[1].signature.ident, "diagonal_pixels");
  assert!(
    m.delegates[1].on_self.is_some(),
    "and the full form's own carries the word"
  );
  assert_eq!(
    m.delegates[1].word(GraphqlKind::AsyncGraphql).as_deref(),
    Some("diagonal"),
    "the LIFTED half is untouched by the waiver — `#[graphql(…)]` leads the properties and says \
     exactly what it says in the shorthand"
  );
}

/// **THE TWO SPELLINGS ARE NOT MIXED IN ONE BLOCK**, and the refusal points at the full one.
///
/// A bare signature is a POSITION; a property is a NAME. A grammar admitting both loose in one list
/// is one an author has to know the loose words of, so the moment an entry says more than its
/// signature every property it has is named — and the near-miss tooth is what carries an author who
/// wrote the obvious thing across.
#[test]
fn a_bare_signature_and_a_named_property_are_not_one_block() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(fn aspect(&self) -> u32, on = self))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(e.contains("written in ONE of two spellings"), "{e}");
  assert!(
    e.contains("delegate(signature = fn m(&self) -> T, on = self)"),
    "and the sentence spells the full form out: {e}"
  );

  let reversed = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      signature = fn aspect(&self) -> u32,
      fn ratio(&self) -> u32,
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(
    reversed.contains("written in ONE of two spellings"),
    "the other order is the same mistake: {reversed}"
  );
}

/// **THE ROSTER IS ONE WORD**, and a value off it is refused by name rather than parsed.
#[test]
fn on_admits_self_and_nothing_else() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      signature = fn aspect(&self) -> u32,
      on = remote,
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(e.contains("`on = remote` names no target"), "{e}");
  assert!(
    e.contains("`on` takes `self`, and `self` is the whole of it"),
    "and the roster is named: {e}"
  );
}

/// **A PROPERTY THE FULL FORM DOES NOT HAVE**, told the two it does.
#[test]
fn the_full_form_names_two_properties_and_no_others() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      signature = fn aspect(&self) -> u32,
      rename = "ratio",
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(e.contains("unknown property in `delegate(…)`"), "{e}");

  let headless = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(on = self))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(
    headless.contains("names no method here"),
    "and an entry without its signature restates nothing: {headless}"
  );
}

/// **A WORD WITH NO MINT TO SUPPRESS** — `on = self` on a fragment that wraps nothing.
///
/// The census verdict (2026-08-26): the word's ONE reader is the rewrite mode's forwarding mint, and
/// an ordinary fragment has none — its entries' methods are the author's already. So the expansion
/// is the same with the word and without, which is the house's own no-reader law and the sentence
/// `cursor` earns on a fragment no record may hold.
#[test]
fn a_waiver_needs_a_mint_to_waive() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(delegate(
      #[graphql(async_graphql)]
      signature = fn aspect(&self) -> u32,
      on = self,
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(
    e.contains("`on = self` suppresses the FORWARDING method"),
    "{e}"
  );
  assert!(
    e.contains("this fragment wraps nothing"),
    "and it names what the word was waiting for: {e}"
  );
  assert!(
    !e.contains("publishes nothing"),
    "the ENTRY has a reader — it publishes — so only the word beside it is refused: {e}"
  );
}

/// **A WAIVED ENTRY THAT PUBLISHES NOTHING HAS NO READER AT ALL** — the second sentence under the
/// one predicate the no-reader law now asks.
///
/// `on = self` waives the mint, so a wrapping declaration's entry then buys what an ordinary one's
/// does and no more. With nothing published there is nothing left, and the entry is refused for the
/// reason an ordinary fragment's plain one is.
#[test]
fn a_waived_entry_that_publishes_nothing_has_no_reader() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      signature = fn aspect(&self) -> u32,
      on = self,
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(
    e.contains("`on = self` waives its forwarding half, so the entry has no reader"),
    "{e}"
  );
}

/// **AN EXCLUSIVE RECEIVER IS NEVER LIFTED**, because a resolver reads.
#[test]
fn an_exclusive_delegate_is_delegable_and_never_liftable() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      #[graphql(async_graphql)]
      fn normalise(&mut self) -> u32,
    ))]
    struct D { w: u32 }
  });
  assert!(e.contains("a published delegate takes `&self`"), "{e}");
  assert!(
    e.contains("mutates the value it was called on"),
    "in THIS tier's terms — a wrapper holds what it forwards to: {e}"
  );
}

/// **ONE WORD IS ONE FIELD** of the emitted object, whether two delegates reach it or a delegate
/// meets a column.
#[test]
fn two_entries_may_not_publish_one_word() {
  let column = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      #[graphql(async_graphql(rename = "width"))]
      fn widest(&self) -> u32,
    ))]
    struct D { #[ingraph(copy)] width: u32 }
  });
  assert!(column.contains("`width` already does"), "{column}");

  let twice = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(
      #[graphql(async_graphql)]
      fn aspect(&self) -> u32,
      #[graphql(async_graphql(rename = "aspect"))]
      fn ratio(&self) -> u32,
    ))]
    struct D { #[ingraph(copy)] w: u32 }
  });
  assert!(twice.contains("`aspect` already does"), "{twice}");
}

/// A delegate whose name is a column's ACCESSOR is two methods of one name on one type — the
/// collision walk the tier already runs, now reaching the seat.
#[test]
fn a_delegate_may_not_take_an_accessors_name() {
  let e = refusals(syn::parse_quote! {
    #[ingraph(remote = "upstream::Dimensions", delegate(fn width(&self) -> u32))]
    struct D { #[ingraph(copy)] width: u32 }
  });
  assert!(e.contains("would declare `width` twice"), "{e}");
}

/// **A LIFTED ENTRY IS A FIELD OF A FACE**, so `#[graphql(…)]` on a fragment that declared none is a
/// name on nothing — the same sentence a field's own `graphql(rename = "…")` earns one seat down.
///
/// The FORWARDING half asks for no face and is untouched, which is what the refusal offers.
#[test]
fn a_published_entry_needs_a_face_to_be_a_field_of() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(entity, remote = "upstream::Dimensions", delegate(
      #[graphql(async_graphql)]
      fn label(&self) -> String,
    ))]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect_err("a published entry on a faceless fragment is refused")
  .into_iter()
  .map(|e| e.to_string())
  .collect::<Vec<_>>()
  .join("\n");
  assert!(
    e.contains("published onto a wire face this fragment does not have"),
    "{e}"
  );

  let m = unactivated(&syn::parse_quote! {
    #[ingraph(entity, remote = "upstream::Dimensions", delegate(fn label(&self) -> String))]
    struct Dimensions { #[ingraph(copy)] width: u32 }
  })
  .expect("a plain entry needs no face");
  assert_eq!(m.delegates.len(), 1);
  assert!(
    m.delegates[0].wire.is_empty(),
    "and it publishes nothing, which is why it costs nothing"
  );
}

/// **THE TWO TRANSFORM SEATS reach the model as PATHS**, and a declaration writing neither carries
/// nothing.
///
/// `write` is the way in and `read` is the way back; the ABSENCE of `read` is the identity rather
/// than a hole, which is the canonicalisation case — a reduced value is a valid domain value.
#[test]
fn the_transform_seats_reach_the_model_as_paths() {
  let m = parse(&syn::parse_quote! {
    pub struct Track {
      #[ingraph(record(write = "Rate::reduced"))]
      frame_rate: Rate,
      #[ingraph(record(write = "Codec::folded", read = "Codec::displayed"))]
      codec: Codec,
      title: String,
    }
  })
  .expect("the words are the record namespace's own");
  assert_eq!(
    rendered(m.fields[0].write.as_ref()).as_deref(),
    Some("Rate::reduced")
  );
  assert_eq!(
    m.fields[0].read.as_ref(),
    None,
    "a canonicalisation undoes nothing on the way out"
  );
  assert_eq!(
    rendered(m.fields[1].write.as_ref()).as_deref(),
    Some("Codec::folded")
  );
  assert_eq!(
    rendered(m.fields[1].read.as_ref()).as_deref(),
    Some("Codec::displayed")
  );
  assert!(
    m.fields[2].write.is_none() && m.fields[2].read.is_none(),
    "and a field that wrote neither carries neither"
  );
}

/// A path as the string a reader would recognise, or [`None`] where the declaration wrote no word.
fn rendered(path: Option<&syn::Path>) -> Option<String> {
  Some(
    path?
      .to_token_stream()
      .to_string()
      .split_whitespace()
      .collect(),
  )
}

/// **A TRANSFORM WITH NOTHING TO TRANSFORM** — the words-with-no-reader family, told at each word.
#[test]
fn a_skipped_field_has_no_boundary_for_a_transform_to_cross() {
  let e = refusals(syn::parse_quote! {
    pub struct Track {
      #[ingraph(record(skip(default = "crate::unrated"), write = "Rate::reduced", read = "Rate::spelled"))]
      frame_rate: Rate,
    }
  });
  assert!(
    e.contains("carries `skip` and `write = \"…\"`, and the word has no site left to be spent at")
      && e.contains("carries `skip` and `read = \"…\"`")
      && e.contains("hands back what `skip(default = \"…\")` named"),
    "{e}"
  );
}

/// **A LOWERING IS MOUNTED PER DIALECT**, and the model carries it beside the dialect it was written
/// at.
///
/// The seat replaces the framework's per-field product at ONE database, which is what a whole-value
/// operator needs: `overlaps` spans two columns at once and no field has it to declare. A dialect
/// written bare keeps the product, so a head that mounts at one of two databases is a head with one
/// mount and two entries.
#[test]
fn a_dialect_at_a_fragments_head_mounts_its_own_lowering() {
  let mounted = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite(comparison = "lowering::SqlSpanComparison"), postgres), entity)]
    struct Span { #[ingraph(copy)] start: i64, #[ingraph(copy)] end: i64 }
  })
  .expect("a fragment mounting a lowering");
  let host = mounted.record.as_ref().expect("the activation");
  assert_eq!(
    host
      .databases
      .iter()
      .map(|one| (
        one.kind.as_str(),
        one
          .comparison
          .as_ref()
          .map(|path| quote::quote!(#path).to_string().replace(' ', ""))
      ))
      .collect::<Vec<_>>(),
    [
      ("sqlite", Some("lowering::SqlSpanComparison".to_owned())),
      ("postgres", None),
    ],
    "the mount rides its own dialect and the bare word beside it keeps the product"
  );
}

/// **THERE IS NO BARE `comparison = "…"`**, and the refusal carries the reason rather than only the
/// shape.
///
/// A bare seat's SCOPE is implicit — a type generic over the SQL family serves three dialects and
/// not MongoDB — so the sentence names that ambiguity and the per-dialect migration out of it.
#[test]
fn a_lowering_has_no_bare_seat_to_be_mounted_at() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(comparison = "SqlSpanComparison"), entity)]
    struct Span { #[ingraph(copy)] start: i64 }
  })
  .expect_err("the bare seat is refused")
  .to_string();
  assert!(
    e.contains("there is no bare `comparison = \"…\"`")
      && e.contains("a lowering is mounted PER DIALECT")
      && e.contains("serves three dialects and not MongoDB")
      && e.contains("record(sqlite(comparison = \"…\"), postgres(comparison = \"…\"))"),
    "{e}"
  );
}

/// **THE DIALECT BLOCK TAKES THE TWO TYPE SEATS AND NOTHING ELSE**, and the three other ways to
/// write the entry wrong each earn their own sentence.
#[test]
fn a_dialects_block_at_a_fragments_head_takes_one_word() {
  for (written, expected) in [
    (
      quote::quote!(record(sqlite(collation = "nocase"))),
      "the block takes the two TYPE seats, `comparison = \"…\"` and `cursor[(codec = \"…\")]`, and \
       nothing else",
    ),
    (
      quote::quote!(record(sqlite(comparison = "One", comparison = "Two"))),
      "`comparison` is mounted more than once at `sqlite` — one dialect, one lowering",
    ),
    (
      quote::quote!(record(sqlite = "SqlSpanComparison")),
      "names the DIALECT and takes no value",
    ),
    (
      quote::quote!(record(sqlite())),
      "`sqlite()` says nothing — write the dialect BARE to name it",
    ),
  ] {
    let e = unactivated(&syn::parse_quote! {
      #[ingraph(#written, entity)]
      struct Span { #[ingraph(copy)] start: i64 }
    })
    .expect_err("the entry is refused")
    .to_string();
    assert!(e.contains(expected), "{written}: {e}");
  }
}

/// **THE HEAD's TWO SEATS reach the model as PATHS**, and a declaration writing neither carries
/// nothing.
///
/// They ride the `record` ACTIVATION rather than the head's own top level, and the placement is the
/// activation refusal: a transform is what a value crosses the storage boundary through, so a
/// fragment no record may hold has no site to spend one at — and inside `record(…)` that shape is
/// unspellable rather than refusable.
#[test]
fn the_head_transform_seats_reach_the_model_as_paths() {
  let m = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite, write = "Ratio::reduced", read = "Ratio::spread"), entity)]
    pub struct Ratio {
      num: u32,
      den: u32,
    }
  })
  .expect("the words are the activation's own");
  let host = m.record.as_ref().expect("the activation");
  assert_eq!(
    rendered(host.write.as_ref()).as_deref(),
    Some("Ratio::reduced")
  );
  assert_eq!(
    rendered(host.read.as_ref()).as_deref(),
    Some("Ratio::spread")
  );
  assert_eq!(
    host.databases.len(),
    1,
    "and the dialect beside them is read exactly as it was"
  );

  let canonical = unactivated(&syn::parse_quote! {
    #[ingraph(record(write = "Ratio::reduced"), entity)]
    pub struct Ratio {
      num: u32,
      den: u32,
    }
  })
  .expect("the bare activation takes the word too");
  let host = canonical.record.as_ref().expect("the activation");
  assert!(
    host.read.is_none(),
    "a canonicalisation undoes nothing on the way out, which is what the absent mirror means"
  );

  let plain = unactivated(&syn::parse_quote! {
    #[ingraph(record, entity)]
    pub struct Ratio {
      num: u32,
      den: u32,
    }
  })
  .expect("a fragment may write neither");
  let host = plain.record.as_ref().expect("the activation");
  assert!(host.write.is_none() && host.read.is_none());
}

/// **THE HEAD's WORDS ARE THE ACTIVATION'S**, so a fragment that no record may hold cannot spell
/// one — and a near miss is told which two words the namespace now has.
#[test]
fn the_head_transform_words_live_inside_the_activation() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(writes = "Ratio::reduced"), entity)]
    pub struct Ratio {
      num: u32,
      den: u32,
    }
  })
  .expect_err("the declaration is refused")
  .to_string();
  assert!(
    e.contains("the WHOLE VALUE's two paths across the storage boundary") && e.contains("`write`"),
    "{e}"
  );

  let e = unactivated(&syn::parse_quote! {
    #[ingraph(entity, write = "Ratio::reduced")]
    pub struct Ratio {
      num: u32,
      den: u32,
    }
  })
  .expect_err("the declaration is refused")
  .to_string();
  assert!(
    !e.contains("WHOLE VALUE"),
    "the word at the head's TOP level is not this seat at all — it never reaches the activation's \
     namespace, so it earns the head's own unknown-word row: {e}"
  );
}

/// **THE SHORTHAND IS THE GROUP, EXACTLY** — `cursor = "X"` ≡ `cursor(codec = "X")`.
///
/// The equivalence is the law that keeps the short form safe to keep as the block grows: it is the
/// block with its one required entry written inline, never a second grammar. Asserted as an
/// equality of the two parsed models rather than as two separate expectations, so a spelling that
/// starts reading differently fails here rather than somewhere downstream.
#[test]
fn the_codec_shorthand_is_the_group_form_written_inline() {
  let parsed = |written: proc_macro2::TokenStream| {
    let m = unactivated(&syn::parse_quote! {
      #[ingraph(#written, entity, cursor)]
      struct Rate { #[ingraph(copy)] num: u32, #[ingraph(copy)] den: u32 }
    })
    .expect("a fragment mounting a codec");
    m.record
      .as_ref()
      .expect("the activation")
      .databases
      .iter()
      .map(|one| (one.kind.as_str(), rendered(one.cursor.as_ref())))
      .collect::<Vec<_>>()
  };

  let shorthand = parsed(quote::quote!(record(
    sqlite(cursor = "codecs::RateCursor"),
    postgres
  )));
  let group = parsed(quote::quote!(record(
    sqlite(cursor(codec = "codecs::RateCursor")),
    postgres
  )));
  assert_eq!(
    shorthand, group,
    "one reader, one refusal, one model — the shorthand is the block's required entry written \
     inline"
  );
  assert_eq!(
    shorthand,
    [
      ("sqlite", Some("codecs::RateCursor".to_owned())),
      ("postgres", None),
    ],
    "and the mount rides its own dialect, the bare word beside it keeping the frame"
  );
}

/// **EVERY DIALECT MAY MOUNT ITS OWN CODEC**, and differing ones are the ordinary case rather than a
/// refusal.
///
/// A page cursor is session-lived pagination state, so the only engine that ever has to read a token
/// is the one that minted it — which is what frees a household to keep a dense form per store. Three
/// dialects, three answers, all legal in one declaration.
#[test]
fn each_dialect_carries_the_codec_it_named() {
  let m = unactivated(&syn::parse_quote! {
    #[ingraph(
      record(
        sqlite(cursor = "codecs::RateSqlite"),
        postgres(cursor = "codecs::RatePostgres"),
        mysql
      ),
      entity,
      cursor
    )]
    struct Rate { #[ingraph(copy)] num: u32, #[ingraph(copy)] den: u32 }
  })
  .expect("differing codecs are legal");
  assert_eq!(
    m.record
      .as_ref()
      .expect("the activation")
      .databases
      .iter()
      .map(|one| (one.kind.as_str(), rendered(one.cursor.as_ref())))
      .collect::<Vec<_>>(),
    [
      ("sqlite", Some("codecs::RateSqlite".to_owned())),
      ("postgres", Some("codecs::RatePostgres".to_owned())),
      ("mysql", None),
    ],
    "each store keeps the byte form it named, and one that named none rides the frame"
  );
}

/// **THE TWO SEATS IN ONE GROUP ARE INDEPENDENT** — a dialect may mount a lowering, a codec, or both.
#[test]
fn a_dialect_group_holds_both_type_seats_at_once() {
  let m = unactivated(&syn::parse_quote! {
    #[ingraph(
      record(sqlite(comparison = "lowering::SqlRateComparison", cursor = "codecs::RateCursor")),
      entity,
      cursor
    )]
    struct Rate { #[ingraph(copy)] num: u32, #[ingraph(copy)] den: u32 }
  })
  .expect("a fragment mounting both");
  let built = &m.record.as_ref().expect("the activation").databases[0];
  assert_eq!(
    rendered(built.comparison.as_ref()).as_deref(),
    Some("lowering::SqlRateComparison")
  );
  assert_eq!(
    rendered(built.cursor.as_ref()).as_deref(),
    Some("codecs::RateCursor"),
    "what a predicate LOWERS INTO and what a boundary is WRITTEN BY are two questions, and one \
     group answers both without either word reading the other"
  );
}

/// **A CODEC IS A POSITION'S BYTES**, so one mounted on a fragment that asserted no order is a name
/// on nothing — the `graphql`-entry-without-a-face family, at the storage seat.
#[test]
fn a_codec_mounted_on_no_position_has_no_reader() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(sqlite(cursor = "codecs::RateCursor")), entity)]
    struct Rate { #[ingraph(copy)] num: u32, #[ingraph(copy)] den: u32 }
  })
  .expect_err("the mount is refused")
  .to_string();
  assert!(
    e.contains("this fragment is no paging position")
      && e.contains("only the bare `cursor` word at the head emits any")
      && e.contains("Write `cursor` beside `record(…)`"),
    "the refusal names the row a codec is spent at and the word that emits it: {e}"
  );
}

/// **THERE IS NO BARE `cursor = "…"` IN `record(…)`**, and the refusal separates it from the head's
/// own word rather than only naming a shape.
#[test]
fn a_codec_has_no_bare_seat_to_be_mounted_at() {
  let e = unactivated(&syn::parse_quote! {
    #[ingraph(record(cursor = "codecs::RateCursor"), entity)]
    struct Rate { #[ingraph(copy)] num: u32 }
  })
  .expect_err("the bare seat is refused")
  .to_string();
  assert!(
    e.contains("there is no bare `cursor = \"…\"` in `record(…)`")
      && e.contains("record(sqlite(cursor = \"…\"), postgres(cursor = \"…\"))")
      && e.contains("A codec's bytes are that STORE's")
      && e.contains("The bare `cursor` at the HEAD, outside `record(…)`, is a different word"),
    "{e}"
  );
}

/// **THE MIXED AND MALFORMED SPELLINGS each earn a near miss pointing at the right form** — and
/// `rename`, the word this block was surveyed for, is refused with what the census found.
#[test]
fn a_codec_mount_written_wrong_is_told_which_form_it_nearly_is() {
  for (written, expected) in [
    (
      quote::quote!(record(sqlite(cursor))),
      "`cursor` says nothing on its own at `sqlite`",
    ),
    (
      quote::quote!(record(sqlite(cursor()))),
      "`cursor` says nothing on its own at `sqlite`",
    ),
    (
      quote::quote!(record(sqlite(cursor(rename = "RateCursor")))),
      "unknown entry in `cursor(…)` at `sqlite` — `cursor(…)` knows `codec`",
    ),
    (
      quote::quote!(record(sqlite(cursor(comparison = "X")))),
      "unknown entry in `cursor(…)` at `sqlite` — `cursor(…)` knows `codec`",
    ),
    (
      quote::quote!(record(sqlite(cursor(codec)))),
      "`cursor` names the type that WRITES AND READS this fragment's cursor bytes",
    ),
    (
      quote::quote!(record(sqlite(cursor = "One", cursor = "Two"))),
      "`cursor` is mounted more than once at `sqlite` — one dialect, one codec",
    ),
    (
      quote::quote!(record(sqlite(cursor(codec = "One", codec = "Two")))),
      "`codec` is declared more than once in `cursor(…)` at `sqlite` — one option, one value",
    ),
  ] {
    let e = unactivated(&syn::parse_quote! {
      #[ingraph(#written, entity, cursor)]
      struct Rate { #[ingraph(copy)] num: u32 }
    })
    .expect_err("the entry is refused")
    .to_string();
    assert!(e.contains(expected), "{written}: {e}");
  }
}