interstellar 0.2.0

A high-performance graph database with Gremlin-style traversals and GQL query language
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
//! Reusable test graph fixtures.
//!
//! Provides standardized test graphs used across integration tests:
//! - `create_small_graph()` - 4 vertices (3 person, 1 software) with 5 edges
//! - `create_medium_graph()` - 5 vertices (adds Redis software)
//! - `create_social_graph()` - Larger graph for complex traversal tests
//! - `create_gql_test_graph()` - Graph for GQL tests with Person/Company vertices
//! - `TestGraphBuilder` - Builder pattern for custom test graphs
//!
//! ## Unified API (Spec 33)
//!
//! All graphs now use the unified COW-based API:
//! - `Graph` - In-memory graph with COW semantics and O(1) snapshots
//! - `GraphSnapshot` - Immutable snapshot for read operations

use std::collections::HashMap;
use std::sync::Arc;

use interstellar::storage::{Graph, GraphSnapshot, GraphStorage};
use interstellar::value::{EdgeId, Value, VertexId};

/// Standard test graph with vertices and their IDs for assertions.
///
/// The graph structure allows testing most traversal patterns including:
/// - Navigation (out, in, both)
/// - Filtering (by label, properties)
/// - Paths and cycles
/// - Aggregations
#[allow(dead_code)]
pub struct TestGraph {
    pub graph: Arc<Graph>,
    // Person vertices
    pub alice: VertexId,
    pub bob: VertexId,
    pub charlie: VertexId,
    // Software vertices
    pub graphdb: VertexId,
    // Optional vertices for extended graphs
    pub redis: Option<VertexId>,
    pub eve: Option<VertexId>,
    // Edge IDs (commonly used in tests)
    pub alice_knows_bob: EdgeId,
    pub bob_knows_charlie: EdgeId,
    pub alice_uses_graphdb: Option<EdgeId>,
    pub bob_uses_graphdb: Option<EdgeId>,
    pub charlie_knows_alice: Option<EdgeId>,
}

impl TestGraph {
    /// Access the graph traversal source via a snapshot.
    ///
    /// # Example
    /// ```ignore
    /// let tg = create_small_graph();
    /// let snapshot = tg.graph.snapshot();
    /// let results = snapshot.gremlin().v().has_label("person").to_list();
    /// ```
    pub fn snapshot(&self) -> GraphSnapshot {
        self.graph.snapshot()
    }
}

/// Builder for creating custom test graphs with specific configurations.
///
/// # Example
/// ```ignore
/// let tg = TestGraphBuilder::new()
///     .add_person("alice", 30)
///     .add_person("bob", 25)
///     .add_software("graphdb", "rust")
///     .add_edge(0, 1, "knows")
///     .add_edge(0, 2, "created")
///     .build();
/// ```
pub struct TestGraphBuilder {
    graph: Arc<Graph>,
    vertices: Vec<VertexId>,
}

#[allow(dead_code)]
impl TestGraphBuilder {
    pub fn new() -> Self {
        TestGraphBuilder {
            graph: Arc::new(Graph::new()),
            vertices: Vec::new(),
        }
    }

    /// Add a person vertex with name and age properties.
    pub fn add_person(mut self, name: &str, age: i64) -> Self {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String(name.to_string()));
        props.insert("age".to_string(), Value::Int(age));
        let id = self.graph.add_vertex("person", props);
        self.vertices.push(id);
        self
    }

    /// Add a person vertex with name, age, and additional status property.
    pub fn add_person_with_status(mut self, name: &str, age: i64, status: &str) -> Self {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String(name.to_string()));
        props.insert("age".to_string(), Value::Int(age));
        props.insert("status".to_string(), Value::String(status.to_string()));
        let id = self.graph.add_vertex("person", props);
        self.vertices.push(id);
        self
    }

    /// Add a software vertex with name and language properties.
    pub fn add_software(mut self, name: &str, lang: &str) -> Self {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String(name.to_string()));
        props.insert("lang".to_string(), Value::String(lang.to_string()));
        let id = self.graph.add_vertex("software", props);
        self.vertices.push(id);
        self
    }

    /// Add a software vertex with name and version properties.
    #[allow(dead_code)]
    pub fn add_software_with_version(mut self, name: &str, version: f64) -> Self {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String(name.to_string()));
        props.insert("version".to_string(), Value::Float(version));
        let id = self.graph.add_vertex("software", props);
        self.vertices.push(id);
        self
    }

    /// Add an edge between vertices by their builder index.
    pub fn add_edge(self, from_idx: usize, to_idx: usize, label: &str) -> Self {
        let from = self.vertices[from_idx];
        let to = self.vertices[to_idx];
        self.graph
            .add_edge(from, to, label, HashMap::new())
            .unwrap();
        self
    }

    /// Add an edge with properties between vertices by their builder index.
    #[allow(dead_code)]
    pub fn add_edge_with_props(
        self,
        from_idx: usize,
        to_idx: usize,
        label: &str,
        props: HashMap<String, Value>,
    ) -> Self {
        let from = self.vertices[from_idx];
        let to = self.vertices[to_idx];
        self.graph.add_edge(from, to, label, props).unwrap();
        self
    }

    /// Build the graph and return it.
    pub fn build(self) -> Arc<Graph> {
        self.graph
    }

    /// Get the vertex ID at a specific index (for assertions).
    #[allow(dead_code)]
    pub fn vertex_id(&self, idx: usize) -> VertexId {
        self.vertices[idx]
    }

    /// Get all vertex IDs.
    #[allow(dead_code)]
    pub fn vertex_ids(&self) -> &[VertexId] {
        &self.vertices
    }
}

impl Default for TestGraphBuilder {
    fn default() -> Self {
        Self::new()
    }
}

/// Creates an empty graph for testing edge cases.
#[allow(dead_code)]
pub fn create_empty_graph() -> Arc<Graph> {
    Arc::new(Graph::new())
}

/// Creates a small test graph with 4 vertices and 5 edges.
///
/// Graph structure:
/// ```text
///     Alice ----knows----> Bob ----knows----> Charlie
///       |                   |                   |
///       |                   |                   |
///      uses                uses              knows
///       |                   |                   |
///       v                   v                   |
///     GraphDB <-------------+                   |
///       ^                                       |
///       |                                       |
///       +---------------------------------------+
///                    (Charlie knows Alice)
/// ```
///
/// Vertices:
/// - Alice (person): name="Alice", age=30
/// - Bob (person): name="Bob", age=25
/// - Charlie (person): name="Charlie", age=35
/// - GraphDB (software): name="GraphDB", version=1.0
///
/// Edges:
/// - Alice -[knows]-> Bob (since=2020)
/// - Bob -[knows]-> Charlie (since=2021)
/// - Alice -[uses]-> GraphDB (skill="expert")
/// - Bob -[uses]-> GraphDB (skill="beginner")
/// - Charlie -[knows]-> Alice (since=2019) - creates cycle
pub fn create_small_graph() -> TestGraph {
    let graph = Arc::new(Graph::new());

    // Add vertices with properties
    let alice = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props.insert("age".to_string(), Value::Int(30));
        props
    });

    let bob = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        props.insert("age".to_string(), Value::Int(25));
        props
    });

    let charlie = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Charlie".to_string()));
        props.insert("age".to_string(), Value::Int(35));
        props
    });

    let graphdb = graph.add_vertex("software", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("GraphDB".to_string()));
        props.insert("version".to_string(), Value::Float(1.0));
        props
    });

    // Add edges with properties
    let alice_knows_bob = graph
        .add_edge(alice, bob, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2020));
            props
        })
        .unwrap();

    let bob_knows_charlie = graph
        .add_edge(bob, charlie, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2021));
            props
        })
        .unwrap();

    let alice_uses_graphdb = graph
        .add_edge(alice, graphdb, "uses", {
            let mut props = HashMap::new();
            props.insert("skill".to_string(), Value::String("expert".to_string()));
            props
        })
        .unwrap();

    let bob_uses_graphdb = graph
        .add_edge(bob, graphdb, "uses", {
            let mut props = HashMap::new();
            props.insert("skill".to_string(), Value::String("beginner".to_string()));
            props
        })
        .unwrap();

    let charlie_knows_alice = graph
        .add_edge(charlie, alice, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2019));
            props
        })
        .unwrap();

    TestGraph {
        graph,
        alice,
        bob,
        charlie,
        graphdb,
        redis: None,
        eve: None,
        alice_knows_bob,
        bob_knows_charlie,
        alice_uses_graphdb: Some(alice_uses_graphdb),
        bob_uses_graphdb: Some(bob_uses_graphdb),
        charlie_knows_alice: Some(charlie_knows_alice),
    }
}

/// Creates a medium test graph with 5 vertices (adds Redis software).
///
/// Extends `create_small_graph()` with:
/// - Redis (software): name="Redis", version=7.0
/// - Charlie -[created]-> Redis edge
pub fn create_medium_graph() -> TestGraph {
    let graph = Arc::new(Graph::new());

    // Add person vertices with status property (used by branch tests)
    let alice = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props.insert("age".to_string(), Value::Int(30));
        props.insert("status".to_string(), Value::String("active".to_string()));
        props.insert("priority".to_string(), Value::Int(1));
        props
    });

    let bob = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        props.insert("age".to_string(), Value::Int(25));
        props.insert("status".to_string(), Value::String("inactive".to_string()));
        props.insert("priority".to_string(), Value::Int(2));
        props
    });

    let charlie = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Charlie".to_string()));
        props.insert("age".to_string(), Value::Int(35));
        props.insert("status".to_string(), Value::String("active".to_string()));
        props.insert("priority".to_string(), Value::Int(1));
        props
    });

    // Add software vertices
    let graphdb = graph.add_vertex("software", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("GraphDB".to_string()));
        props.insert("version".to_string(), Value::Float(2.0));
        props.insert("priority".to_string(), Value::Int(3));
        props
    });

    let redis = graph.add_vertex("software", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Redis".to_string()));
        props.insert("version".to_string(), Value::Float(7.0));
        props.insert("priority".to_string(), Value::Int(2));
        props
    });

    // Add edges
    let alice_knows_bob = graph
        .add_edge(alice, bob, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2020));
            props
        })
        .unwrap();

    let bob_knows_charlie = graph
        .add_edge(bob, charlie, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2021));
            props
        })
        .unwrap();

    // Alice created GraphDB
    graph
        .add_edge(alice, graphdb, "created", HashMap::new())
        .unwrap();

    // Bob created Redis
    graph
        .add_edge(bob, redis, "created", HashMap::new())
        .unwrap();

    TestGraph {
        graph,
        alice,
        bob,
        charlie,
        graphdb,
        redis: Some(redis),
        eve: None,
        alice_knows_bob,
        bob_knows_charlie,
        alice_uses_graphdb: None,
        bob_uses_graphdb: None,
        charlie_knows_alice: None,
    }
}

/// Creates a social network graph with more vertices for complex path tests.
///
/// Graph structure includes:
/// - 5 people: Alice, Bob, Charlie, Diana, Eve
/// - 2 software: GraphDB, Redis
/// - Multiple relationship types: knows, created, uses
pub fn create_social_graph() -> TestGraph {
    let graph = Arc::new(Graph::new());

    // People
    let alice = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props.insert("age".to_string(), Value::Int(30));
        props.insert("city".to_string(), Value::String("NYC".to_string()));
        props
    });

    let bob = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        props.insert("age".to_string(), Value::Int(25));
        props.insert("city".to_string(), Value::String("SF".to_string()));
        props
    });

    let charlie = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Charlie".to_string()));
        props.insert("age".to_string(), Value::Int(35));
        props.insert("city".to_string(), Value::String("NYC".to_string()));
        props
    });

    let _diana = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Diana".to_string()));
        props.insert("age".to_string(), Value::Int(28));
        props.insert("city".to_string(), Value::String("LA".to_string()));
        props
    });

    let eve = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Eve".to_string()));
        props.insert("age".to_string(), Value::Int(32));
        props.insert("city".to_string(), Value::String("SF".to_string()));
        props
    });

    // Software
    let graphdb = graph.add_vertex("software", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("GraphDB".to_string()));
        props.insert("version".to_string(), Value::Float(2.0));
        props.insert("lang".to_string(), Value::String("rust".to_string()));
        props
    });

    let redis = graph.add_vertex("software", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Redis".to_string()));
        props.insert("version".to_string(), Value::Float(7.0));
        props.insert("lang".to_string(), Value::String("c".to_string()));
        props
    });

    // Edges - knows relationships
    let alice_knows_bob = graph
        .add_edge(alice, bob, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2020));
            props
        })
        .unwrap();

    let bob_knows_charlie = graph
        .add_edge(bob, charlie, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2021));
            props
        })
        .unwrap();

    graph
        .add_edge(charlie, alice, "knows", {
            let mut props = HashMap::new();
            props.insert("since".to_string(), Value::Int(2019));
            props
        })
        .unwrap();

    // Edges - created relationships
    graph
        .add_edge(alice, graphdb, "created", HashMap::new())
        .unwrap();

    graph
        .add_edge(bob, redis, "created", HashMap::new())
        .unwrap();

    // Edges - uses relationships
    graph
        .add_edge(charlie, graphdb, "uses", HashMap::new())
        .unwrap();

    graph.add_edge(eve, redis, "uses", HashMap::new()).unwrap();

    TestGraph {
        graph,
        alice,
        bob,
        charlie,
        graphdb,
        redis: Some(redis),
        eve: Some(eve),
        alice_knows_bob,
        bob_knows_charlie,
        alice_uses_graphdb: None,
        bob_uses_graphdb: None,
        charlie_knows_alice: None,
    }
}

/// Creates a test graph optimized for GQL tests.
///
/// Uses PascalCase labels (Person, Company) matching GQL conventions.
/// Includes Person and Company vertices for label filtering tests.
pub fn create_gql_test_graph() -> Arc<Graph> {
    let graph = Arc::new(Graph::new());

    // Create Person vertices
    let mut alice_props = HashMap::new();
    alice_props.insert("name".to_string(), Value::from("Alice"));
    alice_props.insert("age".to_string(), Value::from(30i64));
    graph.add_vertex("Person", alice_props);

    let mut bob_props = HashMap::new();
    bob_props.insert("name".to_string(), Value::from("Bob"));
    bob_props.insert("age".to_string(), Value::from(25i64));
    graph.add_vertex("Person", bob_props);

    let mut charlie_props = HashMap::new();
    charlie_props.insert("name".to_string(), Value::from("Charlie"));
    charlie_props.insert("age".to_string(), Value::from(35i64));
    graph.add_vertex("Person", charlie_props);

    // Create Company vertices
    let mut acme_props = HashMap::new();
    acme_props.insert("name".to_string(), Value::from("Acme Corp"));
    graph.add_vertex("Company", acme_props);

    let mut globex_props = HashMap::new();
    globex_props.insert("name".to_string(), Value::from("Globex"));
    graph.add_vertex("Company", globex_props);

    graph
}

// =============================================================================
// Phase 6: Additional Test Fixtures
// =============================================================================

/// Organizational hierarchy test graph for recursive pattern testing.
///
/// Structure:
/// ```text
///   CEO (level=0)
///   ├── CTO (level=1)
///   │   ├── Eng Manager 1 (level=2)
///   │   │   ├── Developer 1 (level=3)
///   │   │   └── Developer 2 (level=3)
///   │   └── Eng Manager 2 (level=2)
///   │       └── Developer 3 (level=3)
///   └── CFO (level=1)
///       └── Finance Manager (level=2)
///           └── Accountant (level=3)
/// ```
///
/// Edges use "reports_to" label (child -> parent direction).
#[allow(dead_code)]
pub struct OrgTestGraph {
    pub graph: Arc<Graph>,
    pub ceo: VertexId,
    pub cto: VertexId,
    pub cfo: VertexId,
    pub eng_mgr1: VertexId,
    pub eng_mgr2: VertexId,
    pub fin_mgr: VertexId,
    pub dev1: VertexId,
    pub dev2: VertexId,
    pub dev3: VertexId,
    pub accountant: VertexId,
}

impl OrgTestGraph {
    /// Access the graph traversal source via a snapshot.
    ///
    /// # Example
    /// ```ignore
    /// let org = create_org_graph();
    /// let snapshot = org.snapshot();
    /// let results = snapshot.gremlin().v().has_label("employee").to_list();
    /// ```
    pub fn snapshot(&self) -> GraphSnapshot {
        self.graph.snapshot()
    }
}

/// Creates an organizational hierarchy for testing recursive patterns.
#[allow(dead_code)]
pub fn create_org_graph() -> OrgTestGraph {
    let graph = Arc::new(Graph::new());

    // Level 0: CEO
    let ceo = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("CEO".to_string()));
        props.insert("level".to_string(), Value::Int(0));
        props.insert(
            "title".to_string(),
            Value::String("Chief Executive Officer".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(500000));
        props
    });

    // Level 1: CTO and CFO
    let cto = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("CTO".to_string()));
        props.insert("level".to_string(), Value::Int(1));
        props.insert(
            "title".to_string(),
            Value::String("Chief Technology Officer".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(350000));
        props
    });

    let cfo = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("CFO".to_string()));
        props.insert("level".to_string(), Value::Int(1));
        props.insert(
            "title".to_string(),
            Value::String("Chief Financial Officer".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(350000));
        props
    });

    // Level 2: Managers
    let eng_mgr1 = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert(
            "name".to_string(),
            Value::String("Eng Manager 1".to_string()),
        );
        props.insert("level".to_string(), Value::Int(2));
        props.insert(
            "title".to_string(),
            Value::String("Engineering Manager".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(200000));
        props
    });

    let eng_mgr2 = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert(
            "name".to_string(),
            Value::String("Eng Manager 2".to_string()),
        );
        props.insert("level".to_string(), Value::Int(2));
        props.insert(
            "title".to_string(),
            Value::String("Engineering Manager".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(200000));
        props
    });

    let fin_mgr = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert(
            "name".to_string(),
            Value::String("Finance Manager".to_string()),
        );
        props.insert("level".to_string(), Value::Int(2));
        props.insert(
            "title".to_string(),
            Value::String("Finance Manager".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(180000));
        props
    });

    // Level 3: Individual contributors
    let dev1 = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Developer 1".to_string()));
        props.insert("level".to_string(), Value::Int(3));
        props.insert(
            "title".to_string(),
            Value::String("Senior Developer".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(150000));
        props
    });

    let dev2 = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Developer 2".to_string()));
        props.insert("level".to_string(), Value::Int(3));
        props.insert("title".to_string(), Value::String("Developer".to_string()));
        props.insert("salary".to_string(), Value::Int(120000));
        props
    });

    let dev3 = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Developer 3".to_string()));
        props.insert("level".to_string(), Value::Int(3));
        props.insert("title".to_string(), Value::String("Developer".to_string()));
        props.insert("salary".to_string(), Value::Int(120000));
        props
    });

    let accountant = graph.add_vertex("employee", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Accountant".to_string()));
        props.insert("level".to_string(), Value::Int(3));
        props.insert(
            "title".to_string(),
            Value::String("Staff Accountant".to_string()),
        );
        props.insert("salary".to_string(), Value::Int(90000));
        props
    });

    // reports_to edges (child -> parent)
    graph
        .add_edge(cto, ceo, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(cfo, ceo, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(eng_mgr1, cto, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(eng_mgr2, cto, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(fin_mgr, cfo, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(dev1, eng_mgr1, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(dev2, eng_mgr1, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(dev3, eng_mgr2, "reports_to", HashMap::new())
        .unwrap();
    graph
        .add_edge(accountant, fin_mgr, "reports_to", HashMap::new())
        .unwrap();

    OrgTestGraph {
        graph,
        ceo,
        cto,
        cfo,
        eng_mgr1,
        eng_mgr2,
        fin_mgr,
        dev1,
        dev2,
        dev3,
        accountant,
    }
}

/// Creates a densely connected graph for stress testing.
///
/// - `vertex_count` vertices labeled "node"
/// - Each vertex connects to approximately `edge_probability * vertex_count` other vertices
/// - Uses deterministic edge creation based on modular arithmetic
///
/// # Example
/// ```ignore
/// let graph = create_dense_graph(100, 0.2); // 100 vertices, ~20 edges each
/// ```
#[allow(dead_code)]
pub fn create_dense_graph(vertex_count: usize, edges_per_vertex: usize) -> Arc<Graph> {
    let graph = Arc::new(Graph::new());
    let mut ids = Vec::with_capacity(vertex_count);

    // Create vertices
    for i in 0..vertex_count {
        let mut props = HashMap::new();
        props.insert("index".to_string(), Value::Int(i as i64));
        props.insert("name".to_string(), Value::String(format!("node_{}", i)));
        let id = graph.add_vertex("node", props);
        ids.push(id);
    }

    // Create edges deterministically
    for i in 0..vertex_count {
        for j in 1..=edges_per_vertex {
            let target = (i + j) % vertex_count;
            if target != i {
                let mut props = HashMap::new();
                props.insert(
                    "weight".to_string(),
                    Value::Float((j as f64) / (edges_per_vertex as f64)),
                );
                let _ = graph.add_edge(ids[i], ids[target], "connects", props);
            }
        }
    }

    graph
}

/// Creates a graph with diverse property types for type handling tests.
///
/// Includes vertices with:
/// - String, Integer, Float, Boolean properties
/// - Null values
/// - Missing properties (some vertices lack certain keys)
/// - Lists and Maps as property values
#[allow(dead_code)]
pub fn create_property_test_graph() -> Arc<Graph> {
    let graph = Arc::new(Graph::new());

    // Vertex with all property types
    graph.add_vertex("complete", {
        let mut props = HashMap::new();
        props.insert(
            "string_prop".to_string(),
            Value::String("hello".to_string()),
        );
        props.insert("int_prop".to_string(), Value::Int(42));
        props.insert("float_prop".to_string(), Value::Float(2.718));
        props.insert("bool_prop".to_string(), Value::Bool(true));
        props.insert("null_prop".to_string(), Value::Null);
        props.insert(
            "list_prop".to_string(),
            Value::List(vec![Value::Int(1), Value::Int(2), Value::Int(3)]),
        );
        props.insert(
            "map_prop".to_string(),
            Value::Map({
                let mut map = interstellar::value::ValueMap::new();
                map.insert(
                    "nested_key".to_string(),
                    Value::String("nested_value".to_string()),
                );
                map
            }),
        );
        props
    });

    // Vertex with only string properties
    graph.add_vertex("strings_only", {
        let mut props = HashMap::new();
        props.insert(
            "name".to_string(),
            Value::String("StringVertex".to_string()),
        );
        props.insert(
            "description".to_string(),
            Value::String("A vertex with only strings".to_string()),
        );
        props.insert("empty_string".to_string(), Value::String("".to_string()));
        props.insert(
            "unicode".to_string(),
            Value::String("こんにちは 🌍".to_string()),
        );
        props
    });

    // Vertex with only numeric properties
    graph.add_vertex("numbers_only", {
        let mut props = HashMap::new();
        props.insert("positive_int".to_string(), Value::Int(100));
        props.insert("negative_int".to_string(), Value::Int(-50));
        props.insert("zero".to_string(), Value::Int(0));
        props.insert("large_int".to_string(), Value::Int(i64::MAX));
        props.insert("small_int".to_string(), Value::Int(i64::MIN));
        props.insert("positive_float".to_string(), Value::Float(123.456));
        props.insert("negative_float".to_string(), Value::Float(-789.012));
        props.insert("tiny_float".to_string(), Value::Float(0.000001));
        props
    });

    // Vertex with boolean properties
    graph.add_vertex("booleans", {
        let mut props = HashMap::new();
        props.insert("is_active".to_string(), Value::Bool(true));
        props.insert("is_deleted".to_string(), Value::Bool(false));
        props.insert("flag".to_string(), Value::Bool(true));
        props
    });

    // Vertex with null/missing properties
    graph.add_vertex("sparse", {
        let mut props = HashMap::new();
        props.insert("only_one".to_string(), Value::String("value".to_string()));
        props.insert("null_value".to_string(), Value::Null);
        props
    });

    // Vertex with nested structures
    graph.add_vertex("nested", {
        let mut props = HashMap::new();
        props.insert(
            "deep_list".to_string(),
            Value::List(vec![
                Value::List(vec![Value::Int(1), Value::Int(2)]),
                Value::List(vec![Value::Int(3), Value::Int(4)]),
            ]),
        );
        props.insert(
            "deep_map".to_string(),
            Value::Map({
                let mut outer = interstellar::value::ValueMap::new();
                outer.insert(
                    "inner".to_string(),
                    Value::Map({
                        let mut inner = interstellar::value::ValueMap::new();
                        inner.insert("value".to_string(), Value::Int(999));
                        inner
                    }),
                );
                outer
            }),
        );
        props
    });

    // Add edges between vertices
    let vertices: Vec<_> = graph.snapshot().all_vertices().map(|v| v.id).collect();
    for i in 0..vertices.len() {
        for j in (i + 1)..vertices.len() {
            let mut props = HashMap::new();
            props.insert("edge_index".to_string(), Value::Int((i * 10 + j) as i64));
            let _ = graph.add_edge(vertices[i], vertices[j], "relates_to", props);
        }
    }

    graph
}

/// Creates a parameterized large graph for performance testing.
///
/// # Arguments
/// * `vertex_count` - Number of vertices to create
/// * `edges_per_vertex` - Average number of outgoing edges per vertex
///
/// # Returns
/// A graph with the specified number of vertices and edges.
///
/// # Example
/// ```ignore
/// let graph = create_large_graph(10_000, 5); // 10k vertices, ~50k edges
/// ```
#[allow(dead_code)]
pub fn create_large_graph(vertex_count: usize, edges_per_vertex: usize) -> Arc<Graph> {
    let graph = Arc::new(Graph::new());
    let mut ids = Vec::with_capacity(vertex_count);

    // Create vertices with varied properties
    for i in 0..vertex_count {
        let mut props = HashMap::new();
        props.insert("index".to_string(), Value::Int(i as i64));
        props.insert("name".to_string(), Value::String(format!("vertex_{}", i)));
        props.insert(
            "group".to_string(),
            Value::String(format!("group_{}", i % 10)),
        );
        props.insert("priority".to_string(), Value::Int((i % 5) as i64));
        props.insert("score".to_string(), Value::Float((i as f64) * 0.1));
        props.insert("active".to_string(), Value::Bool(i % 2 == 0));

        let label = match i % 3 {
            0 => "type_a",
            1 => "type_b",
            _ => "type_c",
        };
        let id = graph.add_vertex(label, props);
        ids.push(id);
    }

    // Create edges with deterministic pattern
    for i in 0..vertex_count {
        for j in 1..=edges_per_vertex {
            let target = (i + j * 7) % vertex_count; // Prime multiplier for better distribution
            if target != i {
                let mut props = HashMap::new();
                props.insert("weight".to_string(), Value::Float((j as f64) / 10.0));

                let label = match j % 3 {
                    0 => "edge_a",
                    1 => "edge_b",
                    _ => "edge_c",
                };
                let _ = graph.add_edge(ids[i], ids[target], label, props);
            }
        }
    }

    graph
}

// =============================================================================
// Deprecated: Legacy COW Type Aliases
// =============================================================================
//
// These types are now deprecated. Use the unified types instead:
// - `Graph` instead of `CowGraph`
// - `GraphSnapshot` instead of `CowSnapshot`
// - `TestGraph` instead of `CowTestGraph`

/// Deprecated: Use `TestGraph` instead.
///
/// COW-based test graph with vertices and their IDs for assertions.
/// Now that `Graph` uses COW semantics by default, this is an alias for `TestGraph`.
#[deprecated(note = "Use TestGraph instead - Graph now uses COW semantics by default")]
#[allow(dead_code)]
pub type CowTestGraph = TestGraph;

/// Creates an empty COW graph for testing edge cases.
///
/// Deprecated: Use `create_empty_graph()` instead - now uses COW semantics.
#[deprecated(note = "Use create_empty_graph() instead")]
#[allow(dead_code)]
pub fn create_empty_cow_graph() -> Arc<Graph> {
    Arc::new(Graph::new())
}

/// Creates a small COW test graph with 4 vertices and 5 edges.
///
/// Deprecated: Use `create_small_graph()` instead - now uses COW semantics.
#[deprecated(note = "Use create_small_graph() instead")]
#[allow(dead_code)]
pub fn create_small_cow_graph() -> TestGraph {
    create_small_graph()
}

/// Creates a COW test graph optimized for GQL tests.
///
/// Deprecated: Use `create_gql_test_graph()` instead - now uses COW semantics.
#[deprecated(note = "Use create_gql_test_graph() instead")]
#[allow(dead_code)]
pub fn create_gql_cow_test_graph() -> Arc<Graph> {
    create_gql_test_graph()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn small_graph_has_expected_structure() {
        let tg = create_small_graph();
        let snapshot = tg.snapshot();
        let g = snapshot.gremlin();

        assert_eq!(g.v().to_list().len(), 4);
        assert_eq!(g.e().to_list().len(), 5);
        assert_eq!(g.v().has_label("person").to_list().len(), 3);
        assert_eq!(g.v().has_label("software").to_list().len(), 1);
    }

    #[test]
    fn medium_graph_has_expected_structure() {
        let tg = create_medium_graph();
        let snapshot = tg.snapshot();
        let g = snapshot.gremlin();

        assert_eq!(g.v().to_list().len(), 5);
        assert_eq!(g.v().has_label("person").to_list().len(), 3);
        assert_eq!(g.v().has_label("software").to_list().len(), 2);
        assert!(tg.redis.is_some());
    }

    #[test]
    fn social_graph_has_expected_structure() {
        let tg = create_social_graph();
        let snapshot = tg.snapshot();
        let g = snapshot.gremlin();

        assert_eq!(g.v().to_list().len(), 7); // 5 people + 2 software
        assert_eq!(g.v().has_label("person").to_list().len(), 5);
        assert_eq!(g.v().has_label("software").to_list().len(), 2);
    }

    #[test]
    #[cfg(feature = "gql")]
    fn gql_test_graph_has_expected_structure() {
        let graph = create_gql_test_graph();
        let _snapshot = graph.snapshot();

        let results = graph.gql("MATCH (n:Person) RETURN n").unwrap();
        assert_eq!(results.len(), 3);

        let results = graph.gql("MATCH (c:Company) RETURN c").unwrap();
        assert_eq!(results.len(), 2);
    }

    #[test]
    fn builder_creates_custom_graph() {
        let graph = TestGraphBuilder::new()
            .add_person("Alice", 30)
            .add_person("Bob", 25)
            .add_software("GraphDB", "rust")
            .add_edge(0, 1, "knows")
            .add_edge(0, 2, "created")
            .build();

        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        assert_eq!(g.v().to_list().len(), 3);
        assert_eq!(g.e().to_list().len(), 2);
    }

    #[test]
    fn snapshot_is_owned_and_independent() {
        let graph = Arc::new(Graph::new());
        let alice = graph.add_vertex("person", {
            let mut props = HashMap::new();
            props.insert("name".to_string(), Value::String("Alice".to_string()));
            props
        });

        // Take a snapshot
        let snap1 = graph.snapshot();

        // Mutate the graph after snapshot
        graph
            .set_vertex_property(alice, "age", Value::Int(30))
            .unwrap();

        // Original snapshot doesn't see the change
        let v1 = snap1.get_vertex(alice).unwrap();
        assert!(!v1.properties.contains_key("age"));

        // New snapshot sees the change
        let snap2 = graph.snapshot();
        let v2 = snap2.get_vertex(alice).unwrap();
        assert_eq!(v2.properties.get("age"), Some(&Value::Int(30)));
    }

    // =========================================================================
    // Phase 6: Additional Test Fixture Tests
    // =========================================================================

    #[test]
    fn org_graph_has_expected_structure() {
        let org = create_org_graph();
        let snapshot = org.snapshot();
        let g = snapshot.gremlin();

        // Verify vertex count: 10 employees total
        assert_eq!(g.v().to_list().len(), 10);
        assert_eq!(g.v().has_label("employee").to_list().len(), 10);

        // Verify edge count: 9 reports_to edges (tree structure)
        assert_eq!(g.e().to_list().len(), 9);
        assert_eq!(g.e().has_label("reports_to").to_list().len(), 9);
    }

    #[test]
    fn org_graph_has_correct_hierarchy_levels() {
        let org = create_org_graph();
        let snapshot = org.snapshot();
        let g = snapshot.gremlin();

        // Level 0: 1 CEO
        let level0 = g.v().has_value("level", 0i64).to_list();
        assert_eq!(level0.len(), 1);

        // Level 1: 2 executives (CTO, CFO)
        let level1 = g.v().has_value("level", 1i64).to_list();
        assert_eq!(level1.len(), 2);

        // Level 2: 3 managers
        let level2 = g.v().has_value("level", 2i64).to_list();
        assert_eq!(level2.len(), 3);

        // Level 3: 4 individual contributors
        let level3 = g.v().has_value("level", 3i64).to_list();
        assert_eq!(level3.len(), 4);
    }

    #[test]
    fn org_graph_reports_to_edges_correct() {
        let org = create_org_graph();
        let snapshot = org.snapshot();
        let g = snapshot.gremlin();

        // CTO reports to CEO
        let cto_reports = g.v_ids([org.cto]).out_labels(&["reports_to"]).to_list();
        assert_eq!(cto_reports.len(), 1);
        assert_eq!(cto_reports[0].as_vertex_id(), Some(org.ceo));

        // Developers report to managers
        let dev1_reports = g.v_ids([org.dev1]).out_labels(&["reports_to"]).to_list();
        assert_eq!(dev1_reports.len(), 1);
        assert_eq!(dev1_reports[0].as_vertex_id(), Some(org.eng_mgr1));
    }

    #[test]
    fn org_graph_recursive_traversal() {
        let org = create_org_graph();
        let snapshot = org.snapshot();
        let g = snapshot.gremlin();

        // Developer 1 -> Eng Manager 1 -> CTO -> CEO (3 hops)
        let chain = g
            .v_ids([org.dev1])
            .out_labels(&["reports_to"])
            .out_labels(&["reports_to"])
            .out_labels(&["reports_to"])
            .to_list();
        assert_eq!(chain.len(), 1);
        assert_eq!(chain[0].as_vertex_id(), Some(org.ceo));
    }

    #[test]
    fn dense_graph_has_expected_structure() {
        let vertex_count = 50;
        let edges_per_vertex = 5;
        let graph = create_dense_graph(vertex_count, edges_per_vertex);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // Verify vertex count
        assert_eq!(g.v().to_list().len(), vertex_count);
        assert_eq!(g.v().has_label("node").to_list().len(), vertex_count);

        // Verify edge count: each vertex has edges_per_vertex outgoing edges
        // (assuming no self-loops eliminated)
        let edge_count = g.e().to_list().len();
        assert!(edge_count > 0);
        assert!(edge_count <= vertex_count * edges_per_vertex);
    }

    #[test]
    fn dense_graph_vertices_have_properties() {
        let graph = create_dense_graph(10, 3);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // All vertices should have index and name properties
        let indices = g.v().values("index").to_list();
        assert_eq!(indices.len(), 10);

        let names = g.v().values("name").to_list();
        assert_eq!(names.len(), 10);

        // Verify index values are 0..10
        let mut index_vals: Vec<i64> = indices.iter().filter_map(|v| v.as_i64()).collect();
        index_vals.sort();
        assert_eq!(index_vals, (0..10).collect::<Vec<i64>>());
    }

    #[test]
    fn dense_graph_edges_have_weights() {
        let graph = create_dense_graph(10, 3);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // All edges should have weight properties
        let weights = g.e().values("weight").to_list();
        let edge_count = g.e().to_list().len();
        assert_eq!(weights.len(), edge_count);

        // Weights should be floats between 0 and 1
        for weight in &weights {
            let w = weight.as_f64().expect("weight should be float");
            assert!(w > 0.0 && w <= 1.0, "weight {} out of range", w);
        }
    }

    #[test]
    fn property_test_graph_has_expected_structure() {
        let graph = create_property_test_graph();
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // 6 vertices with different property configurations
        assert_eq!(g.v().to_list().len(), 6);

        // Verify label diversity
        assert_eq!(g.v().has_label("complete").to_list().len(), 1);
        assert_eq!(g.v().has_label("strings_only").to_list().len(), 1);
        assert_eq!(g.v().has_label("numbers_only").to_list().len(), 1);
        assert_eq!(g.v().has_label("booleans").to_list().len(), 1);
        assert_eq!(g.v().has_label("sparse").to_list().len(), 1);
        assert_eq!(g.v().has_label("nested").to_list().len(), 1);
    }

    #[test]
    fn property_test_graph_complete_vertex_has_all_types() {
        let graph = create_property_test_graph();
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // Get the complete vertex
        let complete = g.v().has_label("complete").to_list();
        assert_eq!(complete.len(), 1);

        let vid = complete[0].as_vertex_id().unwrap();
        let vertex = snapshot.get_vertex(vid).unwrap();

        // Verify all property types present
        assert!(matches!(
            vertex.properties.get("string_prop"),
            Some(Value::String(_))
        ));
        assert!(matches!(
            vertex.properties.get("int_prop"),
            Some(Value::Int(_))
        ));
        assert!(matches!(
            vertex.properties.get("float_prop"),
            Some(Value::Float(_))
        ));
        assert!(matches!(
            vertex.properties.get("bool_prop"),
            Some(Value::Bool(_))
        ));
        assert!(matches!(
            vertex.properties.get("null_prop"),
            Some(Value::Null)
        ));
        assert!(matches!(
            vertex.properties.get("list_prop"),
            Some(Value::List(_))
        ));
        assert!(matches!(
            vertex.properties.get("map_prop"),
            Some(Value::Map(_))
        ));
    }

    #[test]
    fn property_test_graph_numbers_vertex_has_edge_cases() {
        let graph = create_property_test_graph();
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        let numbers = g.v().has_label("numbers_only").to_list();
        assert_eq!(numbers.len(), 1);

        let vid = numbers[0].as_vertex_id().unwrap();
        let vertex = snapshot.get_vertex(vid).unwrap();

        // Verify numeric edge cases
        assert_eq!(
            vertex.properties.get("positive_int"),
            Some(&Value::Int(100))
        );
        assert_eq!(
            vertex.properties.get("negative_int"),
            Some(&Value::Int(-50))
        );
        assert_eq!(vertex.properties.get("zero"), Some(&Value::Int(0)));
        assert_eq!(
            vertex.properties.get("large_int"),
            Some(&Value::Int(i64::MAX))
        );
        assert_eq!(
            vertex.properties.get("small_int"),
            Some(&Value::Int(i64::MIN))
        );
    }

    #[test]
    fn property_test_graph_sparse_vertex_has_missing_properties() {
        let graph = create_property_test_graph();
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        let sparse = g.v().has_label("sparse").to_list();
        assert_eq!(sparse.len(), 1);

        let vid = sparse[0].as_vertex_id().unwrap();
        let vertex = snapshot.get_vertex(vid).unwrap();

        // Should have only 2 properties
        assert_eq!(vertex.properties.len(), 2);
        assert!(vertex.properties.contains_key("only_one"));
        assert!(vertex.properties.contains_key("null_value"));
    }

    #[test]
    fn large_graph_has_expected_structure() {
        let vertex_count = 100;
        let edges_per_vertex = 3;
        let graph = create_large_graph(vertex_count, edges_per_vertex);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // Verify vertex count
        assert_eq!(g.v().to_list().len(), vertex_count);

        // Verify label distribution (3 types evenly distributed)
        let type_a = g.v().has_label("type_a").to_list().len();
        let type_b = g.v().has_label("type_b").to_list().len();
        let type_c = g.v().has_label("type_c").to_list().len();
        assert_eq!(type_a + type_b + type_c, vertex_count);

        // Each type should have roughly 1/3 of vertices
        assert!(type_a >= vertex_count / 4);
        assert!(type_b >= vertex_count / 4);
        assert!(type_c >= vertex_count / 4);
    }

    #[test]
    fn large_graph_vertices_have_varied_properties() {
        let graph = create_large_graph(50, 2);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // All vertices should have these properties
        assert_eq!(g.v().values("index").to_list().len(), 50);
        assert_eq!(g.v().values("name").to_list().len(), 50);
        assert_eq!(g.v().values("group").to_list().len(), 50);
        assert_eq!(g.v().values("priority").to_list().len(), 50);
        assert_eq!(g.v().values("score").to_list().len(), 50);
        assert_eq!(g.v().values("active").to_list().len(), 50);

        // Verify priority distribution (0-4)
        for p in 0..5 {
            let count = g.v().has_value("priority", p as i64).to_list().len();
            assert_eq!(count, 10, "Expected 10 vertices with priority {}", p);
        }
    }

    #[test]
    fn large_graph_edge_labels_distributed() {
        let graph = create_large_graph(30, 3);
        let snapshot = graph.snapshot();
        let g = snapshot.gremlin();

        // Should have 3 different edge labels
        let edge_a = g.e().has_label("edge_a").to_list().len();
        let edge_b = g.e().has_label("edge_b").to_list().len();
        let edge_c = g.e().has_label("edge_c").to_list().len();

        let total = edge_a + edge_b + edge_c;
        assert!(total > 0);
        assert_eq!(total, g.e().to_list().len());
    }

    #[test]
    fn large_graph_scales_correctly() {
        // Test with different sizes to ensure scaling works
        for (v_count, e_per_v) in [(10, 2), (100, 5), (500, 10)] {
            let graph = create_large_graph(v_count, e_per_v);
            let snapshot = graph.snapshot();
            let g = snapshot.gremlin();

            assert_eq!(
                g.v().to_list().len(),
                v_count,
                "Vertex count mismatch for size {}",
                v_count
            );

            let edge_count = g.e().to_list().len();
            // Edge count should be approximately v_count * e_per_v
            // (may be less due to self-loop prevention)
            assert!(
                edge_count > 0 && edge_count <= v_count * e_per_v,
                "Edge count {} out of expected range for {} vertices with {} edges each",
                edge_count,
                v_count,
                e_per_v
            );
        }
    }
}