mpstthree 0.1.17

A library implementing Multiparty Session Types for 2 or more participants
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
#![allow(unused_imports)]

use petgraph::graph::NodeIndex;
use petgraph::Graph;

use regex::Regex;

use core::panic;
use std::collections::hash_map::RandomState;
use std::collections::HashMap;
use std::error::Error;
use std::fmt::Write;

type VecOfStr = Vec<String>;
type HashMapStrVecOfStr = HashMap<String, VecOfStr>;
type GraphOfStrStr = Graph<String, String>;
type VecOfTuple = Vec<(String, usize)>;

/// Clean the provided session, which should be stringified.
///
/// From
///     "&&mpstthree::meshedchannels::MeshedChannels<mpstthree::\
///     binary::struct_trait::recv::Recv<checking_recursion::\
///     Branches0AtoB, mpstthree::binary::struct_trait::end::End>, mpstthree\
///     ::binary::struct_trait::recv::Recv<i32, mpstthree::binary::\
///     struct_trait::send::Send<i32, mpstthree::binary::struct_trait::end::\
///     End>>, mpstthree::role::c::RoleC<mpstthree::role::c::RoleC<\
///     mpstthree::role::b::RoleB<mpstthree::role::end::RoleEnd>>>, mpstthree\
///     ::name::a::NameA>"
///
/// to
///
/// [
///     "Recv<Branches0AtoB, End>",
///     "Recv<i32, Send<i32, End>>",
///     "RoleC<RoleC<RoleB<RoleEnd>>>",
///     "RoleA<RoleEnd>",
///     "RoleA"
/// ]
///
/// /!\ Mixing former and new naming: moving from new to former
#[doc(hidden)]
pub(crate) fn clean_session(session: &str) -> Result<VecOfStr, Box<dyn Error>> {
    let mut double_colon_less = session.replace('&', "");

    // The main regex expression
    let double_colon_regex = Regex::new(r"([^<,>\s]+)::([^<,>\s]+)")?;

    // Replace with regex expression -> term1::term2::term3 by term3
    for caps in double_colon_regex.captures_iter(session) {
        double_colon_less = double_colon_less.replace(&caps[0], &caps[caps.len() - 1]);
    }

    // The name regex expression
    let name_regex = Regex::new(r"Name([[:alpha:]]+)")?;

    let mut name_to_role = double_colon_less.clone();

    // Replace with regex expression -> term1::term2::term3 by term3
    for caps in name_regex.captures_iter(&double_colon_less) {
        name_to_role =
            name_to_role.replace(&caps[0], &format!("Role{}<RoleEnd>", &caps[caps.len() - 1]));
    }

    // Remove whitespaces
    name_to_role.retain(|c| !c.is_whitespace());

    // Get each field of the MeshedChannels
    let mut full_block = get_blocks(&name_to_role)?;

    // Get the name of the role
    let name = full_block[full_block.len() - 1]
        .split(['<', '>'].as_ref())
        .filter(|s| !s.is_empty())
        .map(String::from)
        .collect::<Vec<_>>()[0]
        .to_string();

    full_block.push(name);

    Ok(full_block)
}

// Clean the sessions received and returns a Hashmap of the cleaned sessions and their respective
// role.
//
// Remove the unnecessary terms before each :: (such as mpstthree in mpstthree::Session),
// and link each new String with its respective role.
// Uses the clean_session() function to achieve the result
#[doc(hidden)]
pub(crate) fn clean_sessions(
    sessions: VecOfStr,
) -> Result<(HashMapStrVecOfStr, VecOfStr), Box<dyn Error>> {
    // The hasher of the HashMap
    let state_branches_receivers = RandomState::new();

    // All the roles
    let mut roles = Vec::new();

    // The result
    let mut all_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branches_receivers);

    let mut size_sessions = 0;

    for session in sessions {
        let full_block = clean_session(&session)?;

        // The number of expected roles
        size_sessions = full_block.len() - 2;

        // Collect the last field of the meshedChannels (the name field)
        let name = &full_block[full_block.len() - 1];

        // Collect the names of the roles
        roles.push(name.to_string());

        // Insert the vec of fields (minus the name's role) linked to the name of the role
        all_sessions.insert(
            name.to_string(),
            full_block[..(full_block.len() - 2)].to_vec(),
        );
    }

    // If the number of roles is different from the number of sessions
    if roles.len() != size_sessions {
        panic!("The numbers of roles and sessions are not equal")
    }

    // Sort
    roles.sort();

    // Remove duplicates
    roles.dedup();

    Ok((all_sessions, roles))
}

// Separate the different _fields_ of a stringified type.
//
// From
//     "MeshedChannels<Send<Branches0AtoB, End>, Send\
//     <i32, Recv<i32, Send<Branches0CtoB, End>>>, RoleC\
//     <RoleC<RoleBroadcast>>, RoleB<RoleEnd>>"
//
// to
//
// [
//     "Send<Branches0AtoB, End>",
//     "Send<i32, Recv<i32, Send<Branches0CtoB, End>>>",
//     "RoleC<RoleC<RoleBroadcast>>",
//     "RoleB<RoleEnd>",
// ]
#[doc(hidden)]
pub(crate) fn get_blocks(full_block: &str) -> Result<VecOfStr, Box<dyn Error>> {
    let mut result = Vec::new();
    let mut temp = "".to_string();

    // Start at -1 because we want to remove the first `<` and the term before
    let mut index = -1;

    for i in full_block.chars() {
        if i == '&' || i.is_whitespace() {
        } else if i == '>' && index == 0 {
            result.push(temp.to_string());
            temp = "".to_string();
        } else if i == '<' && index >= 0 {
            temp = format!("{temp}{i}");
            index += 1;
        } else if i == '>' && index >= 0 {
            temp = format!("{temp}{i}");
            index -= 1;
        } else if i == ',' && index == 0 {
            result.push(temp);
            temp = "".to_string();
        } else if index >= 0 {
            temp = format!("{temp}{i}");
        } else if i == '<' {
            index += 1;
        } else if i == '>' {
            index -= 1;
        }
    }

    if !temp.is_empty() {
        let mut chars = temp.chars();
        chars.next_back();

        result.push(chars.as_str().to_string());
    }

    Ok(result)
}

// Get the head of a Recv/Send session, its payload and its continuation.
#[doc(hidden)]
pub(crate) fn get_head_payload_continuation(full_block: &str) -> Result<VecOfStr, Box<dyn Error>> {
    if full_block == "End" {
        // If the full block is a `End` type
        Ok(vec!["End".to_string()])
    } else if full_block == "RoleEnd" {
        // If the full block is a `End` type
        Ok(vec!["RoleEnd".to_string()])
    } else {
        let mut result = vec![full_block.split('<').collect::<Vec<_>>()[0].to_string()];
        result.append(&mut get_blocks(full_block)?);

        Ok(result)
    }
}

// Extract the correct label for a node from the index_node and the depth of the current node.
//
// From [0, 1, 0, 5] and 2 to "0.1.0".
#[doc(hidden)]
pub(crate) fn extract_index_node(
    index_node: &[usize],
    depth_level: usize,
) -> Result<String, Box<dyn Error>> {
    if index_node.len() < depth_level {
        panic!("Error in extract_index_node: lenght of index_node < depth_level")
    } else if index_node.len() == 1 {
        Ok(index_node[0].to_string())
    } else {
        let first_elt = index_node[0].to_string();

        Ok(index_node[1..=depth_level]
            .iter()
            .fold(first_elt, |mut s, &n| {
                write!(s, ".{}", n).ok();
                s
            }))
    }
}

// Switch all Send and Recv at the head of each session
#[doc(hidden)]
pub(crate) fn build_dual(session: &str) -> Result<String, Box<dyn Error>> {
    if session == "End" {
        Ok(session.to_string())
    } else {
        let all_fields = get_head_payload_continuation(session)?;
        match all_fields[0].as_str() {
            "Recv" => Ok(format!(
                "Send<{},{}>",
                all_fields[1],
                build_dual(&all_fields[2])?
            )),
            "Send" => Ok(format!(
                "Recv<{},{}>",
                all_fields[1],
                build_dual(&all_fields[2])?
            )),
            _ => panic!("Wrong head"),
        }
    }
}

#[doc(hidden)]
#[allow(clippy::too_many_arguments)]
pub(crate) fn aux_get_graph(
    current_role: &str,
    mut full_session: VecOfStr,
    roles: &[String],
    mut index_node: Vec<usize>,
    mut previous_node: NodeIndex<u32>,
    compare_end: VecOfStr,
    mut depth_level: usize,
    index_current_role: usize,
    mut g: GraphOfStrStr,
    branches_receivers: HashMap<String, HashMapStrVecOfStr>,
    mut branches_already_seen: HashMap<String, NodeIndex<u32>>,
    branching_sessions: HashMapStrVecOfStr,
    group_branches: HashMap<String, i32>,
    mut cfsm: VecOfTuple,
) -> Result<(GraphOfStrStr, VecOfTuple), Box<dyn Error>> {
    if compare_end == full_session {
        index_node[depth_level] += 1;
        let new_node = g.add_node(extract_index_node(&index_node, depth_level)?);
        g.add_edge(previous_node, new_node, "0".to_string());

        Ok((g, cfsm))
    } else {
        // Get the size of the full_session
        let size_full_session = full_session.len() - 1;

        // Get the head of the stack
        let stack = &get_head_payload_continuation(&full_session[size_full_session])?;

        if stack.len() == 3 {
            // If it is a simple choice

            let mut number_of_send = 0;
            let mut number_of_recv = 0;
            let mut pos_recv = 0;

            let mut choice_left = Vec::new();
            let mut choice_right = Vec::new();

            for (pos, session) in full_session[..(full_session.len() - 1)]
                .to_vec()
                .iter()
                .enumerate()
            {
                match (
                    get_head_payload_continuation(session)?[0].as_str(),
                    number_of_send,
                    number_of_recv,
                    pos,
                ) {
                    ("Send", n_send, 0, n_pos) if n_send == n_pos => {
                        number_of_send += 1;

                        // Should be `Either<MC, MC>`
                        let payload_either = &get_head_payload_continuation(session)?[1];

                        // Should be `[Either, MC, MC]`
                        let choices = get_head_payload_continuation(payload_either)?;

                        // Split the new session
                        let blocks_left = get_blocks(&choices[1])?;
                        let blocks_right = get_blocks(&choices[2])?;

                        // Get the index of the receiver
                        let receiver =
                            &get_head_payload_continuation(&blocks_left[blocks_left.len() - 1])?[0];

                        let index_receiver =
                            if let Some(elt) = roles.iter().position(|r| r == receiver) {
                                elt
                            } else {
                                panic!("Issue with roles {:?} and receiver {:?}", roles, receiver)
                            };

                        // The offset depending on the relative positions of the roles
                        let offset = (index_current_role > index_receiver) as usize;

                        // Push the choice
                        choice_left.push(build_dual(&blocks_left[index_current_role - offset])?);
                        choice_right.push(build_dual(&blocks_right[index_current_role - offset])?);
                    }
                    ("Recv", 0, 0, new_pos) => {
                        number_of_recv += 1;
                        pos_recv = new_pos;
                    }
                    ("End", 0, _, _) => {}
                    _ => panic!("Wrong session heads"),
                }
            }

            if number_of_recv == 0 && number_of_send == 0 {
                panic!("Expected choose or offer, only found End")
            }

            // Increase the index for the nodes
            index_node.push(0);

            // Increase the depth level
            depth_level += 1;

            if number_of_recv == 1 {
                // If this is a passive role

                // Should be `Either<MC, MC>`
                let payload_either = &get_head_payload_continuation(&full_session[pos_recv])?[1];

                // Should be `[Either, MC, MC]`
                let offers = get_head_payload_continuation(payload_either)?;

                // The left offer
                let offer_left = clean_session(&offers[1])?;

                let result = aux_get_graph(
                    current_role,
                    offer_left[..(offer_left.len() - 2)].to_vec(),
                    roles,
                    index_node.clone(),
                    previous_node,
                    compare_end.clone(),
                    depth_level,
                    index_current_role,
                    g,
                    branches_receivers.clone(),
                    branches_already_seen.clone(),
                    branching_sessions.clone(),
                    group_branches.clone(),
                    cfsm,
                )?;

                g = result.0;
                cfsm = result.1;

                let offer_right = clean_session(&offers[2])?;

                aux_get_graph(
                    current_role,
                    offer_right[..(offer_right.len() - 2)].to_vec(),
                    roles,
                    index_node,
                    previous_node,
                    compare_end,
                    depth_level,
                    index_current_role,
                    g,
                    branches_receivers,
                    branches_already_seen,
                    branching_sessions,
                    group_branches,
                    cfsm,
                )
            } else {
                // If this is the active role

                // Add the corresponding stacks
                choice_left.push(stack[1].to_string());
                choice_right.push(stack[2].to_string());

                let result = aux_get_graph(
                    current_role,
                    choice_left,
                    roles,
                    index_node.clone(),
                    previous_node,
                    compare_end.clone(),
                    depth_level,
                    index_current_role,
                    g,
                    branches_receivers.clone(),
                    branches_already_seen.clone(),
                    branching_sessions.clone(),
                    group_branches.clone(),
                    cfsm,
                )?;

                g = result.0;
                cfsm = result.1;

                aux_get_graph(
                    current_role,
                    choice_right,
                    roles,
                    index_node,
                    previous_node,
                    compare_end,
                    depth_level,
                    index_current_role,
                    g,
                    branches_receivers,
                    branches_already_seen,
                    branching_sessions,
                    group_branches,
                    cfsm,
                )
            }
        } else if stack.len() == 2 {
            // If it is a simple interaction
            let head_stack = &stack[0];

            // The index of the head_stack among the roles
            let index_head = if let Some(elt) = roles.iter().position(|r| r == head_stack) {
                elt
            } else {
                panic!(
                    "Issue with roles {:?} and head_stack {:?}",
                    roles, head_stack
                )
            };

            // The offset depending on the relative positions of the roles
            let offset = (index_current_role < index_head) as usize;

            // The running session
            let running_session =
                get_head_payload_continuation(&full_session[index_head - offset])?;

            // If Send/Recv, everything is good, else, panic
            if running_session[0] == *"Send" {
                // If send simple payload

                // Increase the index for the nodes
                index_node[depth_level] += 1;

                // Add the new `step`
                let new_node = g.add_node(extract_index_node(&index_node, depth_level)?);

                // Add the new edge between the previous and the new node,
                // and label it with the corresponding interaction
                g.add_edge(
                    previous_node,
                    new_node,
                    format!("{current_role}!{head_stack}: {}", &running_session[1]),
                );

                cfsm.push((
                    format!(
                        "{}{} {} ! {} {}",
                        current_role,
                        previous_node.index(),
                        index_head,
                        &running_session[1],
                        current_role
                    ),
                    new_node.index(),
                ));

                // Replace the old binary session with the new one
                full_session[index_head - offset] = running_session[2].to_string();

                // Replace the old stack with the new one
                full_session[size_full_session] = stack[1].to_string();

                // Update the previous node
                previous_node = new_node;
            } else if running_session[0] == *"Recv" {
                if let Some(choice) = branches_receivers.get(&running_session[1]) {
                    // If receive recursive choice
                    let mut all_branches = Vec::new();
                    let mut all_branches_vec = Vec::new();

                    for (branch, session) in choice {
                        all_branches.push((
                            format!("{}::{}", &running_session[1], &branch),
                            session.to_vec(),
                        ));

                        all_branches_vec.push(format!("{}::{}", &running_session[1], &branch));
                    }

                    all_branches_vec.sort();
                    all_branches.sort();

                    let mut node_added = false;

                    for (current_branch, session) in all_branches.clone() {
                        if let Some(new_node) = branches_already_seen.get(&current_branch) {
                            if !g.contains_edge(previous_node, *new_node)
                                && previous_node != *new_node
                            {
                                g.add_edge(previous_node, *new_node, "µ".to_string());

                                if let Some(elt) = cfsm.pop() {
                                    cfsm.push((elt.0, new_node.index()));
                                }
                            }
                        } else {
                            // If the node was not added
                            if !node_added {
                                // Increase the index for the nodes
                                index_node.push(0);

                                // Increase the depth level
                                depth_level += 1;

                                node_added = true;
                            }

                            let mut temp_branches_already_seen = branches_already_seen.clone();

                            for temp_current_branch in all_branches.clone() {
                                temp_branches_already_seen
                                    .insert(temp_current_branch.0.clone(), previous_node);
                            }

                            let result = aux_get_graph(
                                current_role,
                                session[..(session.len() - 2)].to_vec(),
                                roles,
                                index_node.clone(),
                                previous_node,
                                compare_end.clone(),
                                depth_level,
                                index_current_role,
                                g,
                                branches_receivers.clone(),
                                temp_branches_already_seen.clone(),
                                branching_sessions.clone(),
                                group_branches.clone(),
                                cfsm,
                            )?;

                            g = result.0;
                            cfsm = result.1;

                            // Insert the new node/branch in the list of the ones already seen
                            let index_group =
                                if let Some(index) = group_branches.get(&current_branch) {
                                    index
                                } else {
                                    panic!("Missing index")
                                };

                            for (temp_current_branch, temp_index) in group_branches.clone() {
                                if temp_index == *index_group {
                                    branches_already_seen
                                        .insert(temp_current_branch.clone(), previous_node);
                                }
                            }
                        }
                    }

                    return Ok((g, cfsm));
                } else {
                    // If receive simple payload

                    index_node[depth_level] += 1;

                    let new_node = g.add_node(extract_index_node(&index_node, depth_level)?);

                    g.add_edge(
                        previous_node,
                        new_node,
                        format!("{current_role}?{head_stack}: {}", &running_session[1]),
                    );

                    cfsm.push((
                        format!(
                            "{}{} {} ? {} {}",
                            current_role,
                            previous_node.index(),
                            index_head,
                            &running_session[1],
                            current_role
                        ),
                        new_node.index(),
                    ));

                    full_session[index_head - offset] = running_session[2].to_string();
                    full_session[size_full_session] = stack[1].to_string();
                    previous_node = new_node;
                }
            } else {
                panic!(
                    "Did not found a correct session for role {:?}. Found session: {:?}",
                    current_role, full_session
                )
            }

            aux_get_graph(
                current_role,
                full_session,
                roles,
                index_node,
                previous_node,
                compare_end,
                depth_level,
                index_current_role,
                g,
                branches_receivers,
                branches_already_seen,
                branching_sessions,
                group_branches,
                cfsm,
            )
        } else if stack.len() == 1 && stack[0] == "RoleBroadcast" {
            // If it is a broadcasting role

            let mut number_of_send = 0;

            let mut all_branches = Vec::new();

            // Check all the sessions
            for (pos, session) in full_session[..(full_session.len() - 1)]
                .to_vec()
                .iter()
                .enumerate()
            {
                match (
                    get_head_payload_continuation(session)?[0].as_str(),
                    number_of_send,
                    pos,
                ) {
                    ("Send", n_send, n_pos) if n_send == n_pos => {
                        number_of_send += 1;

                        // Should be a specific `enum`
                        let payload = &get_head_payload_continuation(session)?[1];

                        // Update all_choices
                        if let Some(choice) = branches_receivers.get(payload) {
                            for branch in choice.keys() {
                                all_branches.push(format!("{payload}::{branch}"));
                            }
                        } else {
                            panic!("Missing the enum {:?} in branches_receivers", payload)
                        }
                    }
                    _ => panic!("Wrong session heads"),
                }
            }

            let mut node_added = false;

            all_branches.sort();

            for current_branch in all_branches.clone() {
                if let Some(new_node) = branches_already_seen.get(&current_branch) {
                    if !g.contains_edge(previous_node, *new_node) && previous_node != *new_node {
                        g.add_edge(previous_node, *new_node, "µ".to_string());

                        if let Some(elt) = cfsm.pop() {
                            cfsm.push((elt.0, new_node.index()));
                        }
                    }
                } else {
                    // If the node was not added
                    if !node_added {
                        // Increase the index for the nodes
                        index_node.push(0);

                        // Increase the depth level
                        depth_level += 1;

                        node_added = true;
                    }

                    let session = if let Some(session) = branching_sessions.get(&current_branch) {
                        session[..(session.len() - 1)].to_vec()
                    } else {
                        panic!("Missing session")
                    };

                    let mut temp_branches_already_seen = branches_already_seen.clone();

                    for temp_current_branch in all_branches.clone() {
                        temp_branches_already_seen
                            .insert(temp_current_branch.clone(), previous_node);
                    }

                    let result = aux_get_graph(
                        current_role,
                        session,
                        roles,
                        index_node.clone(),
                        previous_node,
                        compare_end.clone(),
                        depth_level,
                        index_current_role,
                        g,
                        branches_receivers.clone(),
                        temp_branches_already_seen.clone(),
                        branching_sessions.clone(),
                        group_branches.clone(),
                        cfsm,
                    )?;

                    g = result.0;
                    cfsm = result.1;

                    // Insert the new node/branch in the list of the ones already seen
                    let index_group = if let Some(index) = group_branches.get(&current_branch) {
                        index
                    } else {
                        panic!("Missing index")
                    };

                    for (temp_current_branch, temp_index) in group_branches.clone() {
                        if temp_index == *index_group {
                            branches_already_seen
                                .insert(temp_current_branch.clone(), previous_node);
                        }
                    }
                }
            }

            Ok((g, cfsm))
        } else {
            panic!(
                "Did not found a correct stack for role {}. \
                Found stack and session: {:?} / {:?}",
                current_role, stack, full_session
            )
        }
    }
}

// Build the digraphs.
#[doc(hidden)]
pub(crate) fn get_graph_session(
    current_role: &str,
    full_session: VecOfStr,
    roles: &[String],
    branches_receivers: HashMap<String, HashMapStrVecOfStr>,
    branching_sessions: HashMapStrVecOfStr,
    group_branches: HashMap<String, i32>,
) -> Result<(GraphOfStrStr, VecOfStr), Box<dyn Error>> {
    // Create the new graph that will be returned in the end
    let mut g = Graph::<String, String>::new();

    // Start the index for the different `steps` of the choreography
    let index_node = vec![0];

    // Add the first node for the graph
    let previous_node = g.add_node(index_node[0].to_string());

    // The `End` vec that we will compare to `full_session`
    let mut compare_end = vec!["End".to_string(); full_session.len() - 1];
    compare_end.push("RoleEnd".to_string());

    // The index of the current_role among the roles

    let index_current_role = if let Some(elt) = roles.iter().position(|r| r == current_role) {
        elt
    } else {
        panic!(
            "Issue with roles {:?} and current_role {:?}",
            roles, current_role
        )
    };

    // The index of the current_role among the roles
    let start_depth_level = 0;

    // The branches already seen
    let state_branches_already_seen = RandomState::new();
    let branches_already_seen: HashMap<String, NodeIndex<u32>> =
        HashMap::with_hasher(state_branches_already_seen);

    let cfsm: VecOfTuple = Vec::new();

    let (result, cfsm) = aux_get_graph(
        current_role,
        full_session,
        roles,
        index_node,
        previous_node,
        compare_end,
        start_depth_level,
        index_current_role,
        g,
        branches_receivers,
        branches_already_seen,
        branching_sessions,
        group_branches,
        cfsm,
    )?;

    // The missing strings for starting cfsm
    let mut cfsm_result = vec![".outputs".to_string(), ".state graph".to_string()];

    // Format the tuples into strings and add them to cfsm_result
    let mut clean_cfsm = cfsm
        .iter()
        .map(|(s, i)| format!("{s}{i}"))
        .collect::<Vec<String>>();

    cfsm_result.append(&mut clean_cfsm);

    // The missing strings for ending cfsm
    cfsm_result.push(format!(".marking {current_role}0"));
    cfsm_result.push(".end".to_string());

    Ok((result, cfsm_result))
}

///////////////////////

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

    use std::collections::hash_map::RandomState;
    use std::collections::HashMap;

    #[test]
    fn test_clean_session() {
        let dirty_session = "&&mpstthree::meshedchannels::MeshedChannels<mpstthree::\
            binary::struct_trait::recv::Recv<checking_recursion::\
            Branches0AtoB, mpstthree::binary::struct_trait::end::End>, mpstthree\
            ::binary::struct_trait::recv::Recv<i32, mpstthree::binary::\
            struct_trait::send::Send<i32, mpstthree::binary::struct_trait::end::\
            End>>, mpstthree::role::c::RoleC<mpstthree::role::c::RoleC<\
            mpstthree::role::b::RoleB<mpstthree::role::end::RoleEnd>>>, mpstthree\
            ::name::a::NameA>";

        let clean_session_compare = vec![
            "Recv<Branches0AtoB,End>",
            "Recv<i32,Send<i32,End>>",
            "RoleC<RoleC<RoleB<RoleEnd>>>",
            "RoleA<RoleEnd>",
            "RoleA",
        ];

        assert_eq!(clean_session(dirty_session).unwrap(), clean_session_compare);
    }

    #[test]
    fn test_clean_sessions() {
        let dirty_sessions = vec![
            "mpstthree::meshedchannels::MeshedChannels<mpstthree::binary::\
            struct_trait::recv::Recv<checking_recursion::Branches0AtoB, mpstthree\
            ::binary::struct_trait::end::End>, mpstthree::binary::\
            struct_trait::end::End, mpstthree::role::b::RoleB<mpstthree::role\
            ::end::RoleEnd>, mpstthree::name::a::NameA>"
                .to_string(),
            "mpstthree::meshedchannels::MeshedChannels<mpstthree::\
            binary::struct_trait::end::End, mpstthree::binary::struct_trait::\
            recv::Recv<i32, mpstthree::binary::struct_trait::send::Send<\
            i32, mpstthree::binary::struct_trait::recv::Recv<checking_recursion\
            ::Branches0CtoB, mpstthree::binary::struct_trait::end::End>>>, mpstthree\
            ::role::b::RoleB<mpstthree::role::b::RoleB<mpstthree::role::b::RoleB\
            <mpstthree::role::end::RoleEnd>>>, mpstthree::name::c::NameC>"
                .to_string(),
            "mpstthree::meshedchannels::\
            MeshedChannels<mpstthree::binary::struct_trait::send::Send<\
            checking_recursion::Branches0AtoB, mpstthree::binary::struct_trait\
            ::end::End>, mpstthree::binary::struct_trait::send::Send<i32, mpstthree\
            ::binary::struct_trait::recv::Recv<i32, mpstthree::binary::struct_trait\
            ::send::Send<checking_recursion::Branches0CtoB, mpstthree::binary::\
            struct_trait::end::End>>>, mpstthree::role::c::RoleC<mpstthree::\
            role::c::RoleC<mpstthree::role::broadcast::RoleBroadcast>>, mpstthree\
            ::name::b::NameB>"
                .to_string(),
        ];

        // The hasher of the HashMap
        let state_clean_sessions_compare = RandomState::new();

        // The result
        let mut clean_sessions_compare: HashMapStrVecOfStr =
            HashMap::with_hasher(state_clean_sessions_compare);

        clean_sessions_compare.insert(
            "RoleC".to_string(),
            vec![
                "End".to_string(),
                "Recv<i32,Send<i32,Recv<Branches0CtoB,End>>>".to_string(),
                "RoleB<RoleB<RoleB<RoleEnd>>>".to_string(),
            ],
        );
        clean_sessions_compare.insert(
            "RoleA".to_string(),
            vec![
                "Recv<Branches0AtoB,End>".to_string(),
                "End".to_string(),
                "RoleB<RoleEnd>".to_string(),
            ],
        );
        clean_sessions_compare.insert(
            "RoleB".to_string(),
            vec![
                "Send<Branches0AtoB,End>".to_string(),
                "Send<i32,Recv<i32,Send<Branches0CtoB,End>>>".to_string(),
                "RoleC<RoleC<RoleBroadcast>>".to_string(),
            ],
        );

        let clean_roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        assert_eq!(
            (clean_sessions_compare, clean_roles),
            clean_sessions(dirty_sessions).unwrap()
        );
    }

    #[test]
    #[should_panic]
    fn test_clean_sessions_panic() {
        let dirty_sessions = vec![
            "mpstthree::meshedchannels::MeshedChannels<mpstthree::binary::\
            struct_trait::recv::Recv<checking_recursion::Branches0AtoB, mpstthree\
            ::binary::struct_trait::end::End>, mpstthree::binary::\
            struct_trait::end::End, mpstthree::role::b::RoleB<mpstthree::role\
            ::end::RoleEnd>, mpstthree::role::a::RoleA<mpstthree::role::end::\
            RoleEnd>>"
                .to_string(),
            "mpstthree::meshedchannels::MeshedChannels<mpstthree::\
            binary::struct_trait::end::End, mpstthree::binary::struct_trait::\
            recv::Recv<i32, mpstthree::binary::struct_trait::send::Send<\
            i32, mpstthree::binary::struct_trait::recv::Recv<checking_recursion\
            ::Branches0CtoB, mpstthree::binary::struct_trait::end::End>>>, mpstthree\
            ::role::b::RoleB<mpstthree::role::b::RoleB<mpstthree::role::b::RoleB\
            <mpstthree::role::end::RoleEnd>>>, mpstthree::role::c::RoleC<\
            mpstthree::role::end::RoleEnd>>"
                .to_string(),
        ];

        clean_sessions(dirty_sessions).unwrap();
    }

    #[test]
    fn test_get_blocks() {
        let dirty_blocks = "MeshedChannels<Send<Branches0AtoB, End>, Send\
        <i32, Recv<i32, Send<Branches0CtoB, End>>>, RoleC\
        <RoleC<RoleBroadcast>>, RoleB<RoleEnd>>";

        let clean_blocks = vec![
            "Send<Branches0AtoB,End>",
            "Send<i32,Recv<i32,Send<Branches0CtoB,End>>>",
            "RoleC<RoleC<RoleBroadcast>>",
            "RoleB<RoleEnd>",
        ];

        assert_eq!(clean_blocks, get_blocks(dirty_blocks).unwrap());
    }

    #[test]
    fn test_get_head_payload_continuation() {
        // End
        let dirty_end = "End";

        let clean_end = vec!["End"];

        assert_eq!(clean_end, get_head_payload_continuation(dirty_end).unwrap());

        // RoleEnd
        let dirty_role_end = "RoleEnd";

        let clean_role_end = vec!["RoleEnd"];

        assert_eq!(
            clean_role_end,
            get_head_payload_continuation(dirty_role_end).unwrap()
        );

        // Random
        let dirty_random = "Recv<i32, Send<i32, Recv<Branches0CtoB, End>>>";

        let clean_random = vec!["Recv", "i32", "Send<i32,Recv<Branches0CtoB,End>>"];

        assert_eq!(
            clean_random,
            get_head_payload_continuation(dirty_random).unwrap()
        );
    }

    #[test]
    fn test_extract_index_node() {
        assert_eq!("0.1.4.5", extract_index_node(&[0, 1, 4, 5], 3).unwrap());

        assert_eq!("0.1.4", extract_index_node(&[0, 1, 4, 5], 2).unwrap());

        assert_eq!("0", extract_index_node(&[0, 1, 4, 5], 0).unwrap());
    }

    #[test]
    fn test_build_dual() {
        let session = "Recv<i32, Send<Branches0CtoB, End>>";

        assert_eq!(
            "Send<i32,Recv<Branches0CtoB,End>>",
            build_dual(session).unwrap()
        );
    }

    #[test]
    #[should_panic]
    fn test_build_dual_panic() {
        let session = "Coco<i32, Banana<Branches0CtoB, End>>";

        build_dual(session).unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_stack() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let branching_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branching_sessions);

        let state_group_branches = RandomState::new();
        let group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        let current_role = "RoleA";

        let full_session = vec!["Recv<(), End>".to_string(), "RoleEnd".to_string()];

        let roles = vec!["RoleA".to_string(), "RoleB".to_string()];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_session() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let branching_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branching_sessions);

        let state_group_branches = RandomState::new();
        let group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        let current_role = "RoleB";

        let full_session = vec!["End".to_string(), "RoleA<RoleEnd>".to_string()];

        let roles = vec!["RoleA".to_string(), "RoleB".to_string()];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_choice_end() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let branching_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branching_sessions);

        let state_group_branches = RandomState::new();
        let group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        let current_role = "RoleA";

        let full_session = vec![
            "End".to_string(),
            "End".to_string(),
            "RoleAtoAll<RoleEnd, RoleEnd>".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_choice_end_send() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let branching_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branching_sessions);

        let state_group_branches = RandomState::new();
        let group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        let current_role = "RoleA";

        let full_session = vec![
            "End".to_string(),
            "Send<(), End>".to_string(),
            "RoleAtoAll<RoleEnd, RoleEnd>".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_choice_recv_recv() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let branching_sessions: HashMapStrVecOfStr = HashMap::with_hasher(state_branching_sessions);

        let state_group_branches = RandomState::new();
        let group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        let current_role = "RoleA";

        let full_session = vec![
            "Recv<(), End>".to_string(),
            "Recv<(), End>".to_string(),
            "RoleAlltoB<RoleEnd, RoleEnd>".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_enum_choice_index() {
        let state_branches = RandomState::new();
        let mut branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branches_choice_end = RandomState::new();
        let mut branches_receivers_choice_end: HashMapStrVecOfStr =
            HashMap::with_hasher(state_branches_choice_end);

        branches_receivers_choice_end.insert(
            "End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );

        branches_receivers.insert(
            "Branching0AtoB".to_string(),
            branches_receivers_choice_end.clone(),
        );
        branches_receivers.insert(
            "Branching0AtoC".to_string(),
            branches_receivers_choice_end.clone(),
        );

        let state_branching_sessions = RandomState::new();
        let mut branching_sessions: HashMapStrVecOfStr =
            HashMap::with_hasher(state_branching_sessions);

        branching_sessions.insert(
            "Branching0AtoB::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );
        branching_sessions.insert(
            "Branching0AtoC::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );

        let state_group_branches = RandomState::new();
        let mut group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        group_branches.insert("Branching0AtoB::End".to_string(), 0);
        group_branches.insert("Branching0AtoC::End".to_string(), 0);

        let current_role = "RoleA";

        let full_session = vec![
            "Send<Branching0AtoB, End>".to_string(),
            "Send<Branching0AtoC, End>".to_string(),
            "RoleBroadcast".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_enum_offer_index() {
        let state_branches = RandomState::new();
        let mut branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branches_choice_end = RandomState::new();
        let mut branches_receivers_choice_end: HashMapStrVecOfStr =
            HashMap::with_hasher(state_branches_choice_end);

        branches_receivers_choice_end.insert(
            "End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );

        branches_receivers.insert(
            "Branching0AtoB".to_string(),
            branches_receivers_choice_end.clone(),
        );
        branches_receivers.insert(
            "Branching0AtoC".to_string(),
            branches_receivers_choice_end.clone(),
        );

        let state_branching_sessions = RandomState::new();
        let mut branching_sessions: HashMapStrVecOfStr =
            HashMap::with_hasher(state_branching_sessions);

        branching_sessions.insert(
            "Branching0AtoB::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );
        branching_sessions.insert(
            "Branching0AtoC::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );

        let state_group_branches = RandomState::new();
        let mut group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        group_branches.insert("Branching0AtoB::End".to_string(), 0);
        group_branches.insert("Branching0AtoC::End".to_string(), 0);

        let current_role = "RoleA";

        let full_session = vec![
            "Recv<Branching0AtoB, End>".to_string(),
            "End".to_string(),
            "RoleB<RoleEnd>".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }

    #[test]
    #[should_panic]
    fn test_aux_graph_panic_enum_missing() {
        let state_branches = RandomState::new();
        let branches_receivers: HashMap<String, HashMapStrVecOfStr> =
            HashMap::with_hasher(state_branches);

        let state_branching_sessions = RandomState::new();
        let mut branching_sessions: HashMapStrVecOfStr =
            HashMap::with_hasher(state_branching_sessions);

        branching_sessions.insert(
            "Branching0AtoB::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );
        branching_sessions.insert(
            "Branching0AtoC::End".to_string(),
            vec!["End".to_string(), "End".to_string(), "RoleEnd".to_string()],
        );

        let state_group_branches = RandomState::new();
        let mut group_branches: HashMap<String, i32> = HashMap::with_hasher(state_group_branches);

        group_branches.insert("Branching0AtoB::End".to_string(), 0);
        group_branches.insert("Branching0AtoC::End".to_string(), 0);

        let current_role = "RoleA";

        let full_session = vec![
            "Send<Branching0AtoB, End>".to_string(),
            "Send<Branching0AtoC, End>".to_string(),
            "RoleBroadcast".to_string(),
        ];

        let roles = vec![
            "RoleA".to_string(),
            "RoleB".to_string(),
            "RoleC".to_string(),
        ];

        get_graph_session(
            current_role,
            full_session,
            &roles,
            branches_receivers,
            branching_sessions,
            group_branches,
        )
        .unwrap();
    }
}