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
//! =============================================================================
//! Antithesis Assertion Macros
//! =============================================================================
//!
//! These macros define correctness properties for [Antithesis](https://antithesis.com/)
//! autonomous testing. They wrap the [Antithesis SDK](https://docs.rs/antithesis_sdk)
//! assertion macros and double as standard Rust assertions, giving us a single assertion
//! layer that works both in normal builds and under Antithesis fuzzing.
//!
//! ## The `antithesis` feature flag
//!
//! All macros compile to different code depending on whether `--features antithesis`
//! is enabled:
//!
//! - **Without** the feature: macros behave like their `std` counterparts (`assert!`,
//! `debug_assert!`, `unreachable!`, etc.), or are no-ops for observational macros.
//! - **With** the feature: macros additionally report to the Antithesis SDK. On failure,
//! "always" assertions print an error to stderr and call `std::process::exit(0)` instead
//! of panicking. This clean exit lets Antithesis properly process the property violation.
//!
//! ## Five categories of assertions
//!
//! 1. **Condition assertions** ([`turso_assert!`], [`turso_debug_assert!`])
//! Drop-in replacements for `assert!`/`debug_assert!` that also report to Antithesis.
//!
//! 2. **Sometimes assertions** ([`turso_assert_sometimes!`],
//! [`turso_assert_sometimes_greater_than!`], [`turso_assert_sometimes_less_than!`],
//! [`turso_assert_sometimes_greater_than_or_equal!`],
//! [`turso_assert_sometimes_less_than_or_equal!`])
//! Observational only — never panic. Tell Antithesis "this condition should be true at
//! least once across all test runs." Useful for verifying the fuzzer explores both sides
//! of a branch.
//!
//! 3. **Boolean guidance** ([`turso_assert_some!`], [`turso_assert_all!`])
//! Multi-condition assertions that provide better guidance to the Antithesis fuzzer.
//! `some` = at least one condition must be true (OR), `all` = every condition must be true (AND).
//! Panics on failure (or exit(0) with antithesis feature).
//!
//! 4. **Reachability assertions** ([`turso_assert_reachable!`],
//! [`turso_assert_unreachable!`], [`turso_soft_unreachable!`])
//! Verify whether code paths are or aren't hit during testing.
//!
//! 5. **Comparison assertions** ([`turso_assert_eq!`], [`turso_assert_ne!`],
//! [`turso_assert_greater_than!`], [`turso_assert_greater_than_or_equal!`],
//! [`turso_assert_less_than!`], [`turso_assert_less_than_or_equal!`])
//! Typed comparison assertions that provide richer information to Antithesis than a
//! plain `turso_assert!(a > b)`.
//!
//! ## Note: fuzzer guidance temporarily disabled
//!
//! The Antithesis SDK provides specialized `numeric_guidance_helper!` and
//! `boolean_guidance_helper!` macros that give the fuzzer detailed numeric/boolean
//! values to guide exploration. These were previously used by comparison and boolean
//! macros but are currently disabled (replaced with plain `assert_always_or_unreachable!`
//! / `assert_sometimes!`) while Antithesis investigates an issue.
//!
//! The macros still work correctly as assertions — they just don't give the fuzzer
//! as much detail to work with. Guidance will be restored when the issue is resolved.
//!
//! ## Quick reference
//!
//! | Macro | Antithesis SDK | Panics? | Notes |
//! |-------|---------------|---------|-------|
//! | `turso_assert!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | Drop-in for `assert!` |
//! | `turso_debug_assert!` | `assert_always_or_unreachable!` | Debug only (exit(0) w/ feature) | Drop-in for `debug_assert!` |
//! | `turso_assert_sometimes!` | `assert_sometimes!` | Never | Observational only |
//! | `turso_assert_some!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | OR of named conditions |
//! | `turso_assert_all!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | AND of named conditions |
//! | `turso_assert_reachable!` | *(no-op)* | Never | Pending better SQL generation |
//! | `turso_assert_unreachable!` | `assert_unreachable!` | Yes (exit(0) w/ feature) | Hard unreachable |
//! | `turso_soft_unreachable!` | `assert_unreachable!` | Never | Soft signal, no-op w/o feature |
//! | `turso_assert_eq!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | Drop-in for `assert_eq!` |
//! | `turso_assert_ne!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | Drop-in for `assert_ne!` |
//! | `turso_assert_greater_than!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | `left > right` |
//! | `turso_assert_greater_than_or_equal!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | `left >= right` |
//! | `turso_assert_less_than!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | `left < right` |
//! | `turso_assert_less_than_or_equal!` | `assert_always_or_unreachable!` | Yes (exit(0) w/ feature) | `left <= right` |
//! | `turso_assert_sometimes_greater_than!` | `assert_sometimes!` | Never | Observational `left > right` |
//! | `turso_assert_sometimes_less_than!` | `assert_sometimes!` | Never | Observational `left < right` |
//! | `turso_assert_sometimes_greater_than_or_equal!` | `assert_sometimes!` | Never | Observational `left >= right` |
//! | `turso_assert_sometimes_less_than_or_equal!` | `assert_sometimes!` | Never | Observational `left <= right` |
extern crate proc_macro;
// Import assertion proc macro implementations
use ;
use ;
use quote;
use HashMap;
use ;
/// Generate a runtime check that panics if `ANTITHESIS_OUTPUT_DIR` is not set.
/// Uses `std::sync::Once` so the actual env var lookup only happens once per call site.
/// A procedural macro that derives a `Description` trait for enums.
/// This macro extracts documentation comments (specified with `/// Description...`) for enum variants
/// and generates an implementation for `get_description`, which returns the associated description.
/// Processes a Rust docs to extract the description string.
/// Processes the payload of an enum variant to extract variable names (ignoring types).
/// Generates the `get_description` implementation for the processed enum.
/// Register your extension with 'core' by providing the relevant functions
///```ignore
///use turso_ext::{register_extension, scalar, Value, AggregateDerive, AggFunc};
///
/// register_extension!{ scalars: { return_one }, aggregates: { SumPlusOne } }
///
///#[scalar(name = "one")]
///fn return_one(args: &[Value]) -> Value {
/// return Value::from_integer(1);
///}
///
///#[derive(AggregateDerive)]
///struct SumPlusOne;
///
///impl AggFunc for SumPlusOne {
/// type State = i64;
/// const NAME: &'static str = "sum_plus_one";
/// const ARGS: i32 = 1;
///
/// fn step(state: &mut Self::State, args: &[Value]) {
/// let Some(val) = args[0].to_integer() else {
/// return;
/// };
/// *state += val;
/// }
///
/// fn finalize(state: Self::State) -> Value {
/// Value::from_integer(state + 1)
/// }
///}
///
/// ```
/// Declare a scalar function for your extension. This requires the name:
/// #[scalar(name = "example")] of what you wish to call your function with.
/// ```ignore
/// use turso_ext::{scalar, Value};
/// #[scalar(name = "double", alias = "twice")] // you can provide an <optional> alias
/// fn double(args: &[Value]) -> Value {
/// let arg = args.get(0).unwrap();
/// match arg.value_type() {
/// ValueType::Float => {
/// let val = arg.to_float().unwrap();
/// Value::from_float(val * 2.0)
/// }
/// ValueType::Integer => {
/// let val = arg.to_integer().unwrap();
/// Value::from_integer(val * 2)
/// }
/// }
/// } else {
/// Value::null()
/// }
/// }
/// ```
/// Derive a context-aware scalar function for your extension by deriving
/// `ScalarDerive` on a struct that implements the `ScalarFunc` trait.
///
/// The associated `State` is built once per registration via `init`, shared by
/// reference across every call, and dropped when the function is unregistered or
/// the owning connection is dropped. The derived `register_<Struct>` entry point
/// can be listed directly in the `scalars: { .. }` section of `register_extension!`.
/// ```ignore
/// use turso_ext::{register_extension, ScalarDerive, ScalarFunc, Value};
///
/// #[derive(ScalarDerive)]
/// struct Multiply;
///
/// impl ScalarFunc for Multiply {
/// type State = i64;
/// const NAME: &'static str = "ctx_multiply";
/// fn init() -> Self::State {
/// 3
/// }
/// fn call(state: &Self::State, args: &[Value]) -> Value {
/// Value::from_integer(args[0].to_integer().unwrap_or_default() * *state)
/// }
/// }
/// ```
/// Define an aggregate function for your extension by deriving
/// AggregateDerive on a struct that implements the AggFunc trait.
/// ```ignore
/// use turso_ext::{register_extension, Value, AggregateDerive, AggFunc};
///
///#[derive(AggregateDerive)]
///struct SumPlusOne;
///
///impl AggFunc for SumPlusOne {
/// type State = i64;
/// type Error = &'static str;
/// const NAME: &'static str = "sum_plus_one";
/// const ARGS: i32 = 1;
/// fn step(state: &mut Self::State, args: &[Value]) {
/// let Some(val) = args[0].to_integer() else {
/// return;
/// };
/// *state += val;
/// }
/// fn finalize(state: Self::State) -> Result<Value, Self::Error> {
/// Ok(Value::from_integer(state + 1))
/// }
///}
/// ```
/// Macro to derive a VTabModule for your extension. This macro will generate
/// the necessary functions to register your module with core. You must implement
/// the VTabModule, VTable, and VTabCursor traits.
/// ```ignore
/// #[derive(Debug, VTabModuleDerive)]
/// struct CsvVTabModule;
///
/// impl VTabModule for CsvVTabModule {
/// type Table = CsvTable;
/// const NAME: &'static str = "csv_data";
/// const VTAB_KIND: VTabKind = VTabKind::VirtualTable;
///
/// /// Declare your virtual table and its schema
/// fn create(args: &[Value]) -> Result<(String, Self::Table), ResultCode> {
/// let schema = "CREATE TABLE csv_data (
/// name TEXT,
/// age TEXT,
/// city TEXT
/// )".into();
/// Ok((schema, CsvTable {}))
/// }
/// }
///
/// struct CsvTable {}
///
/// // Implement the VTable trait for your virtual table
/// impl VTable for CsvTable {
/// type Cursor = CsvCursor;
/// type Error = &'static str;
///
/// /// Open the virtual table and return a cursor
/// fn open(&self) -> Result<Self::Cursor, Self::Error> {
/// let csv_content = fs::read_to_string("data.csv").unwrap_or_default();
/// let rows: Vec<Vec<String>> = csv_content
/// .lines()
/// .skip(1)
/// .map(|line| {
/// line.split(',')
/// .map(|s| s.trim().to_string())
/// .collect()
/// })
/// .collect();
/// Ok(CsvCursor { rows, index: 0 })
/// }
///
/// /// **Optional** methods for non-readonly tables:
///
/// /// Update the row with the provided values, return the new rowid
/// fn update(&mut self, rowid: i64, args: &[Value]) -> Result<Option<i64>, Self::Error> {
/// Ok(None)// return Ok(None) for read-only
/// }
///
/// /// Insert a new row with the provided values, return the new rowid
/// fn insert(&mut self, args: &[Value]) -> Result<(), Self::Error> {
/// Ok(()) //
/// }
///
/// /// Delete the row with the provided rowid
/// fn delete(&mut self, rowid: i64) -> Result<(), Self::Error> {
/// Ok(())
/// }
///
/// /// Destroy the virtual table. Any cleanup logic for when the table is deleted comes heres
/// fn destroy(&mut self) -> Result<(), Self::Error> {
/// Ok(())
/// }
/// }
///
/// #[derive(Debug)]
/// struct CsvCursor {
/// rows: Vec<Vec<String>>,
/// index: usize,
/// }
///
/// impl CsvCursor {
/// /// Returns the value for a given column index.
/// fn column(&self, idx: u32) -> Result<Value, Self::Error> {
/// let row = &self.rows[self.index];
/// if (idx as usize) < row.len() {
/// Value::from_text(&row[idx as usize])
/// } else {
/// Value::null()
/// }
/// }
/// }
///
/// // Implement the VTabCursor trait for your virtual cursor
/// impl VTabCursor for CsvCursor {
/// type Error = &'static str;
///
/// /// Filter the virtual table based on arguments (omitted here for simplicity)
/// fn filter(&mut self, _args: &[Value], _idx_info: Option<(&str, i32)>) -> ResultCode {
/// ResultCode::OK
/// }
///
/// /// Move the cursor to the next row
/// fn next(&mut self) -> ResultCode {
/// if self.index < self.rows.len() - 1 {
/// self.index += 1;
/// ResultCode::OK
/// } else {
/// ResultCode::EOF
/// }
/// }
///
/// fn eof(&self) -> bool {
/// self.index >= self.rows.len()
/// }
///
/// /// Return the value for a given column index
/// fn column(&self, idx: u32) -> Result<Value, Self::Error> {
/// self.column(idx)
/// }
///
/// fn rowid(&self) -> i64 {
/// self.index as i64
/// }
/// }
///
/// ```ignore
/// use turso_ext::{ExtResult as Result, VfsDerive, VfsExtension, VfsFile};
///
/// // Your struct must also impl Default
/// #[derive(VfsDerive, Default)]
/// struct ExampleFS;
///
///
/// struct ExampleFile {
/// file: std::fs::File,
///
///
/// impl VfsExtension for ExampleFS {
/// /// The name of your vfs module
/// const NAME: &'static str = "example";
///
/// type File = ExampleFile;
///
/// fn open(&self, path: &str, flags: i32, _direct: bool) -> Result<Self::File> {
/// let file = OpenOptions::new()
/// .read(true)
/// .write(true)
/// .create(flags & 1 != 0)
/// .open(path)
/// .map_err(|_| ResultCode::Error)?;
/// Ok(TestFile { file })
/// }
///
/// fn run_once(&self) -> Result<()> {
/// // (optional) method to cycle/advance IO, if your extension is asynchronous
/// Ok(())
/// }
///
/// fn close(&self, file: Self::File) -> Result<()> {
/// // (optional) method to close or drop the file
/// Ok(())
/// }
///
/// fn generate_random_number(&self) -> i64 {
/// // (optional) method to generate random number. Used for testing
/// let mut buf = [0u8; 8];
/// getrandom::fill(&mut buf).unwrap();
/// i64::from_ne_bytes(buf)
/// }
///
/// fn get_current_time(&self) -> String {
/// // (optional) method to generate random number. Used for testing
/// chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
/// }
///
///
/// impl VfsFile for ExampleFile {
/// fn read(
/// &mut self,
/// buf: &mut [u8],
/// count: usize,
/// offset: i64,
/// ) -> Result<i32> {
/// if file.file.seek(SeekFrom::Start(offset as u64)).is_err() {
/// return Err(ResultCode::Error);
/// }
/// file.file
/// .read(&mut buf[..count])
/// .map_err(|_| ResultCode::Error)
/// .map(|n| n as i32)
/// }
///
/// fn write(&mut self, buf: &[u8], count: usize, offset: i64) -> Result<i32> {
/// if self.file.seek(SeekFrom::Start(offset as u64)).is_err() {
/// return Err(ResultCode::Error);
/// }
/// self.file
/// .write(&buf[..count])
/// .map_err(|_| ResultCode::Error)
/// .map(|n| n as i32)
/// }
///
/// fn sync(&self) -> Result<()> {
/// self.file.sync_all().map_err(|_| ResultCode::Error)
/// }
///
/// fn size(&self) -> i64 {
/// self.file.metadata().map(|m| m.len() as i64).unwrap_or(-1)
/// }
///}
///
///```
/// match_ignore_ascii_case will generate trie-like tree matching from normal match expression.
/// example:
/// ```ignore
/// match_ignore_ascii_case!(match input {
/// b"AB" => TokenType::TK_ABORT,
/// b"AC" => TokenType::TK_ACTION,
/// _ => TokenType::TK_ID,
/// })
/// ```
/// Derive macro for creating atomic wrappers for enums
///
/// Supports:
/// - Unit variants
/// - Variants with single bool/u8/i8 fields
/// - Named or unnamed fields
///
/// Algorithm:
/// - Uses u8 representation, splitting bits for variant discriminant and field data
/// - For bool fields: high bit for bool, lower 7 bits for discriminant
/// - For u8/i8 fields: uses u16 internally (8 bits discriminant, 8 bits data)
///
/// Example:
/// ```ignore
/// #[derive(AtomicEnum)]
/// enum TransactionState {
/// Write { schema_did_change: bool },
/// Read,
/// PendingUpgrade,
/// None,
/// }
/// ```
/// Test macro for `core_tester` crate
///
/// Generates a runnable Rust test from the following function signature
///
/// ```ignore
/// fn test_x(db: TempDatabase) -> Result<()> {}
/// // Or
/// fn test_y(db: TempDatabase) {}
/// ```
///
/// Macro accepts the following arguments
///
/// - `mvcc` flag: creates an additional test that will run the same code with MVCC enabled
/// - `encryption` flag: creates an additional `_encrypted` variant that passes
/// `Some(EncryptionOpts)` to the test function (the plain variant passes `None`).
/// The function parameter must be `Option<EncryptionOpts>`.
/// - `path` arg: specifies the name of the database to be created
/// - `init_sql` arg: specifies the SQL query that will be run by `rusqlite` before initializing the Turso database
///
/// Example (TempDatabase):
/// ```no_run,rust
/// #[turso_macros::test(mvcc, path = "test.db", init_sql = "CREATE TABLE test_rowid (id INTEGER PRIMARY KEY);")]
/// fn test_integer_primary_key(tmp_db: TempDatabase) -> anyhow::Result<()> {
/// // Code goes here to test
/// Ok(())
/// }
/// ```
///
/// Example (encryption):
/// ```no_run,rust
/// #[turso_macros::test(encryption)]
/// fn test_restart() {
/// // `encrypted` is injected by the macro: false for the plain variant,
/// // true for the _encrypted variant.
/// let mut db = MvccTestDbNoConn::new_maybe_encrypted(encrypted);
/// // test body
/// }
/// ```
/// Wrap a function body in a stack trace guard and a `turso_stack` tracing span.
///
/// With no arguments, the label is inferred as `module_path!()::function_name`
/// and the span name is the function name.
/// A string literal argument overrides the label.
///
/// ```ignore
/// #[turso_macros::trace_stack]
/// fn prepare_select_plan(...) { ... }
///
/// #[turso_macros::trace_stack("select:translate")]
/// fn translate_select(...) { ... }
///
/// #[turso_macros::trace_stack(detail = stmt_kind(&stmt))]
/// fn translate_inner(stmt: ast::Stmt, ...) { ... }
/// ```
/// Wrap a function body in an allocation-site scope.
///
/// The argument must be an expression that converts into
/// `crate::alloc::AllocationSite`.
/// Controls the `#[cfg(not(antithesis))]` fallback in "always" comparison macros.
/// Drop-in replacement for [`assert!`] that additionally reports to the
/// [Antithesis SDK](https://docs.rs/antithesis_sdk) when compiled with
/// `--features antithesis`.
///
/// Maps to `antithesis_sdk::assert_always_or_unreachable!` — the condition must be
/// true every time this line is reached, but it is OK if the line is never reached.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves exactly like [`assert!`] (panics on failure).
/// - **With `antithesis` feature**: reports the property to Antithesis via
/// `assert_always_or_unreachable!`. On failure, prints the error to stderr and calls
/// `std::process::exit(0)` instead of panicking. The clean exit lets Antithesis properly
/// process the property violation. The normal `assert!` is skipped in this path.
///
/// # Parameters
///
/// - `condition` — boolean expression to check.
/// - `"message"` *(optional)* — human-readable description.
/// Auto-generated from the condition expression if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details forwarded to Antithesis
/// as JSON and included in the panic/exit message.
///
/// # Usage
///
/// ```ignore
/// turso_assert!(condition);
/// turso_assert!(condition, "message");
/// turso_assert!(condition, "message", { "key": value });
/// ```
///
/// # Examples
///
/// ```ignore
/// // Simple condition (auto-generates message from expression)
/// turso_assert_less_than_or_equal!(value, PageSize::MAX as usize);
///
/// // With explicit message
/// turso_assert_greater_than!(page_idx, 0, "page index must be positive");
///
/// // With structured details for Antithesis
/// turso_assert_greater_than_or_equal!(
/// available_space, required_space,
/// "not enough space on page",
/// { "available": available_space, "required": required_space }
/// );
/// ```
///
/// # When to use
///
/// Use `turso_assert!` anywhere you would use `assert!`. It is the default choice for
/// invariants that must always hold. Prefer [`turso_debug_assert!`] for expensive checks
/// that should only run in debug builds.
/// Drop-in replacement for [`debug_assert!`] that additionally reports to the
/// [Antithesis SDK](https://docs.rs/antithesis_sdk) when compiled with
/// `--features antithesis`.
///
/// Maps to `antithesis_sdk::assert_always_or_unreachable!`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves exactly like [`debug_assert!`] — panics
/// on failure in debug builds, compiled out in release builds.
/// - **With `antithesis` feature**: reports the property to Antithesis via
/// `assert_always_or_unreachable!`. On failure, prints the error to stderr and calls
/// `std::process::exit(0)` instead of panicking. The clean exit lets Antithesis properly
/// process the property violation. The normal `debug_assert!` is skipped in this path.
///
/// # Parameters
///
/// Same as [`turso_assert!`]:
/// - `condition` — boolean expression to check.
/// - `"message"` *(optional)* — human-readable description.
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_debug_assert!(condition);
/// turso_debug_assert!(condition, "message");
/// turso_debug_assert!(condition, "message", { "key": value });
/// ```
///
/// # Examples
///
/// ```ignore
/// turso_debug_assert!(value <= PageSize::MAX as usize);
/// turso_debug_assert!(matches!(self.page_type(), Ok(PageType::TableInterior)));
/// ```
///
/// # When to use
///
/// Use `turso_debug_assert!` for invariant checks that are too expensive for release
/// builds (e.g., scanning a list to verify sorted order).
/// Observational assertion: tells Antithesis that a condition should be true
/// **at least once** across all test runs. Never panics.
///
/// Maps to `antithesis_sdk::assert_sometimes!`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: evaluates the condition expression (preserving any
/// side effects) but discards the result. Effectively a no-op.
/// - **With `antithesis` feature**: reports to Antithesis via `assert_sometimes!`.
/// Antithesis will flag it if the condition is *never* true across the entire test
/// campaign, indicating the fuzzer failed to explore that state.
///
/// This macro **never panics or exits** — it is purely observational.
///
/// # Parameters
///
/// - `condition` — boolean expression to observe.
/// - `"message"` *(optional)* — human-readable description.
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_assert_sometimes!(condition);
/// turso_assert_sometimes!(condition, "message");
/// turso_assert_sometimes!(condition, "message", { "key": value });
/// ```
///
/// # When to use
///
/// Use `turso_assert_sometimes!` to verify the fuzzer explores both branches of a
/// condition. For example, if a cache can be either hit or miss, place a
/// `turso_assert_sometimes!` on each branch to ensure Antithesis tests both paths.
/// Asserts that **at least one** of multiple named conditions is true whenever this
/// line is reached (logical OR). All conditions are evaluated.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: panics if none of the conditions are true (like `assert!`).
/// - **With `antithesis` feature**: reports the property to Antithesis via
/// `assert_always_or_unreachable!`. On failure, prints the error to stderr and calls
/// `std::process::exit(0)` instead of panicking.
///
/// # Parameters
///
/// - `{name: condition, ...}` — named boolean conditions in curly braces. Names are
/// labels for Antithesis reporting.
/// - `"message"` — human-readable description (required).
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_assert_some!(
/// {is_leaf: page.is_leaf(), is_interior: page.is_interior()},
/// "page must be either leaf or interior"
/// );
///
/// turso_assert_some!(
/// {has_data: !row.is_empty(), has_rowid: row.rowid().is_some()},
/// "row must have data or a rowid",
/// { "table": table_name }
/// );
/// ```
///
/// # When to use
///
/// Use whenever a condition has a logical OR.
/// Asserts that **all** named conditions are true whenever this line is reached
/// (logical AND).
///
/// # Behavior
///
/// - **Without `antithesis` feature**: panics if any condition is false (like `assert!`).
/// - **With `antithesis` feature**: reports the property to Antithesis via
/// `assert_always_or_unreachable!`. On failure, prints the error to stderr and calls
/// `std::process::exit(0)` instead of panicking.
///
/// # Parameters
///
/// - `{name: condition, ...}` — named boolean conditions in curly braces.
/// - `"message"` — human-readable description (required).
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_assert_all!(
/// {valid_size: page_size > 0, within_bounds: offset < page_size},
/// "page header fields must all be valid"
/// );
///
/// // With structured details
/// turso_assert_all!(
/// {has_header: header.is_some(), correct_magic: magic == EXPECTED_MAGIC},
/// "database file must be well-formed",
/// { "magic": magic }
/// );
/// ```
///
/// # When to use
///
/// Use whenever a condition has a logical AND.
/// Asserts that a code path is reached **at least once** during Antithesis testing. No-op in
/// non-antithesis builds.
///
/// # Parameters
///
/// - `"message"` — human-readable description of the code path (required).
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_assert_reachable!("opcode: Init");
/// turso_assert_reachable!("checkpoint", { "frames": frame_count });
/// ```
///
/// # Examples
///
/// ```ignore
/// turso_assert_reachable!("opcode: Add");
/// turso_assert_reachable!("checkpoint");
/// ```
///
/// # When to use
///
/// Place at code paths that should be exercised by the fuzzer.
/// Asserts that a code path is **never** reached. This is a hard assertion — it will
/// terminate the program if the path is executed.
///
/// Maps to `antithesis_sdk::assert_unreachable!`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: calls [`unreachable!`] (panics with the message).
/// - **With `antithesis` feature**: reports to Antithesis via `assert_unreachable!`,
/// prints the error, then calls `exit(0)`.
///
/// # Parameters
///
/// - `"message"` — human-readable description of why this path is unreachable (required).
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis and the
/// panic/exit message.
///
/// # Usage
///
/// ```ignore
/// turso_assert_unreachable!("message");
/// turso_assert_unreachable!("message", { "key": value });
/// ```
///
/// # When to use
///
/// Use for code paths that represent logic errors — places that should genuinely never
/// execute. For paths that are unexpected but not impossible (e.g., fallback branches
/// that indicate a likely bug but shouldn't panic), prefer [`turso_soft_unreachable!`] instead.
/// Soft unreachable: signals to Antithesis that this code path should never be reached,
/// but does **not** panic or exit. Without the `antithesis` feature, this is a no-op.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: complete no-op — no evaluation, no side effects.
/// - **With `antithesis` feature**: reports to Antithesis, then execution continues normally.
///
/// This is the key difference from [`turso_assert_unreachable!`]: soft_unreachable only
/// *reports* to Antithesis, while the hard version terminates the process.
///
/// # Parameters
///
/// - `"message"` — human-readable description (required).
/// - `{ "key": value, ... }` *(optional)* — structured details for Antithesis.
///
/// # Usage
///
/// ```ignore
/// turso_soft_unreachable!("message");
/// turso_soft_unreachable!("message", { "key": value });
/// ```
///
/// # Examples
///
/// ```ignore
/// // In the pager, marking unexpected-but-recoverable states
/// turso_soft_unreachable!("wal_state() called on database without WAL");
/// turso_soft_unreachable!(
/// "Cannot set ptrmap entry for header/ptrmap page or invalid page",
/// { "page": db_page_no_to_update }
/// );
/// ```
///
/// # When to use
///
/// Use for code paths that are unexpected but not impossible — places where you want
/// Antithesis to flag the issue but don't want to crash the program, for example in error
/// handling paths and fallback branches that indicate a likely bug but should degrade
/// gracefully in production.
/// Asserts that `left > right`, providing richer comparison information to Antithesis
/// than a plain `turso_assert!(a > b)`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves like `assert!(left > right, ...)`.
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left` — left-hand operand.
/// - `right` — right-hand operand.
/// - `"message"` *(optional)* — auto-generated as `"left > right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_greater_than!(left, right);
/// turso_assert_greater_than!(left, right, "message");
/// turso_assert_greater_than!(left, right, "message", { "key": value });
/// ```
///
/// # Examples
///
/// ```ignore
/// turso_assert_greater_than!(page_idx, 0);
/// turso_assert_greater_than!(
/// root_page_num, 0,
/// "Largest root page number cannot be 0"
/// );
/// ```
/// Asserts that `left >= right`, providing richer comparison information to Antithesis
/// than a plain `turso_assert!(a >= b)`.
///
/// Maps to `antithesis_sdk::assert_always_or_unreachable!` with `left >= right`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves like `assert!(left >= right, ...)`.
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left >= right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_greater_than_or_equal!(left, right);
/// turso_assert_greater_than_or_equal!(left, right, "message");
/// turso_assert_greater_than_or_equal!(left, right, "message", { "key": value });
/// ```
/// Asserts that `left < right`, providing richer comparison information to Antithesis
/// than a plain `turso_assert!(a < b)`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves like `assert!(left < right, ...)`.
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left < right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_less_than!(left, right);
/// turso_assert_less_than!(left, right, "message");
/// turso_assert_less_than!(left, right, "message", { "key": value });
/// ```
/// Asserts that `left <= right`, providing richer comparison information to Antithesis
/// than a plain `turso_assert!(a <= b)`.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves like `assert!(left <= right, ...)`.
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left <= right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_less_than_or_equal!(left, right);
/// turso_assert_less_than_or_equal!(left, right, "message");
/// turso_assert_less_than_or_equal!(left, right, "message", { "key": value });
/// ```
/// Drop-in replacement for [`assert_eq!`] that additionally reports to the
/// [Antithesis SDK](https://docs.rs/antithesis_sdk) in Antithesis builds (`--cfg=antithesis`).
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves exactly like [`assert_eq!`].
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left`, `right` — values to compare for equality.
/// - `"message"` *(optional)* — auto-generated as `"left == right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_eq!(left, right);
/// turso_assert_eq!(left, right, "message");
/// turso_assert_eq!(left, right, "message", { "key": value });
/// ```
///
/// # Examples
///
/// ```ignore
/// turso_assert_eq!(QueryMode::new(&cmd), mode);
/// turso_assert_eq!(joined_tables.len(), 1, "expected only one joined table");
/// ```
/// Drop-in replacement for [`assert_ne!`] that additionally reports to the
/// [Antithesis SDK](https://docs.rs/antithesis_sdk) in Antithesis builds (`--cfg=antithesis`).
///
/// # Behavior
///
/// - **Without `antithesis` feature**: behaves exactly like [`assert_ne!`].
/// - **With `antithesis` feature**: reports to Antithesis, then on failure prints the
/// error and calls `std::process::exit(0)`.
///
/// # Parameters
///
/// - `left`, `right` — values to compare for inequality.
/// - `"message"` *(optional)* — auto-generated as `"left != right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_ne!(left, right);
/// turso_assert_ne!(left, right, "message");
/// turso_assert_ne!(left, right, "message", { "key": value });
/// ```
/// Observational assertion: tells Antithesis that `left > right` should be true
/// **at least once** across all test runs. Never panics.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: evaluates both operands, then discards the result. No-op.
/// - **With `antithesis` feature**: reports the failure to Antithesis, then continues execution.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left > right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_sometimes_greater_than!(left, right);
/// turso_assert_sometimes_greater_than!(left, right, "message");
/// turso_assert_sometimes_greater_than!(left, right, "message", { "key": value });
/// ```
///
/// # When to use
///
/// Use to verify the fuzzer explores states where one value exceeds another. For example,
/// ensuring the WAL sometimes grows beyond a certain threshold.
/// Observational assertion: tells Antithesis that `left < right` should be true
/// **at least once** across all test runs. Never panics.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: evaluates both operands, then discards the result. No-op.
/// - **With `antithesis` feature**: reports to Antithesis via `assert_sometimes!`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left < right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_sometimes_less_than!(left, right);
/// turso_assert_sometimes_less_than!(left, right, "message");
/// turso_assert_sometimes_less_than!(left, right, "message", { "key": value });
/// ```
/// Observational assertion: tells Antithesis that `left >= right` should be true
/// **at least once** across all test runs. Never panics.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: evaluates both operands, then discards the result. No-op.
/// - **With `antithesis` feature**: reports to Antithesis via `assert_sometimes!`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left >= right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_sometimes_greater_than_or_equal!(left, right);
/// turso_assert_sometimes_greater_than_or_equal!(left, right, "message");
/// turso_assert_sometimes_greater_than_or_equal!(left, right, "message", { "key": value });
/// ```
/// Observational assertion: tells Antithesis that `left <= right` should be true
/// **at least once** across all test runs. Never panics.
///
/// # Behavior
///
/// - **Without `antithesis` feature**: evaluates both operands, then discards the result. No-op.
/// - **With `antithesis` feature**: reports to Antithesis via `assert_sometimes!`.
///
/// # Parameters
///
/// - `left`, `right` — operands to compare.
/// - `"message"` *(optional)* — auto-generated as `"left <= right"` if omitted.
/// - `{ "key": value, ... }` *(optional)* — structured details.
///
/// # Usage
///
/// ```ignore
/// turso_assert_sometimes_less_than_or_equal!(left, right);
/// turso_assert_sometimes_less_than_or_equal!(left, right, "message");
/// turso_assert_sometimes_less_than_or_equal!(left, right, "message", { "key": value });
/// ```