libgraphql-core 0.0.8

Core libraries provided by the `libgraphql` crate.
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
use crate::ast;
use crate::operation::ExecutableDocumentBuilder;
use crate::operation::FragmentRegistry;
use crate::operation::FragmentRegistryBuilder;
use crate::schema::Schema;
use crate::schema::SchemaBuilder;
use crate::test::snapshot_tests::utils;
use crate::test::snapshot_tests::ExpectedErrorPattern;
use crate::test::snapshot_tests::OperationSnapshotTestCase;
use rayon::prelude::IntoParallelRefIterator;
use rayon::prelude::ParallelIterator;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use super::snapshot_test_case::SchemaSnapshotTestCase;

/// Number of context lines to show in schema error snippets
const SCHEMA_ERROR_SNIPPET_LINES: usize = 3;

/// Number of context lines to show in operation error snippets
const OPERATION_ERROR_SNIPPET_LINES: usize = 5;

/// Number of lines to preview when showing expected errors that didn't occur
const EXPECTED_ERROR_PREVIEW_LINES: usize = 10;

/// Format an expected vs actual error message
fn format_expected_actual_error(expected: &str, actual: &str) -> String {
    format!("Expected: {expected}\nGot: {actual}")
}

/// Format a false negative error with expected patterns
fn format_false_negative_error(what: &str, expected_patterns: &[ExpectedErrorPattern]) -> String {
    let patterns_text = if expected_patterns.is_empty() {
        String::new()
    } else {
        format!(
            "\n\nExpected error patterns:\n{}",
            expected_patterns
                .iter()
                .map(|p| format!("  - {p}"))
                .collect::<Vec<_>>()
                .join("\n")
        )
    };

    format!("Expected: Should fail validation{patterns_text}\nGot: {what} validated successfully (false negative!)")
}

/// Format an unmatched patterns error
fn format_unmatched_patterns_error(unmatched: &[&ExpectedErrorPattern], actual_errors: &[String]) -> String {
    format!(
        "Expected: All error patterns must match\nGot: Not all expected errors matched\n\nUnmatched patterns:\n{}\n\nActual errors:\n{}",
        unmatched
            .iter()
            .map(|p| format!("{p}"))
            .collect::<Vec<_>>()
            .join("\n"),
        actual_errors
            .iter()
            .map(|e| format!("  - {e}"))
            .collect::<Vec<_>>()
            .join("\n")
    )
}

/// Result of a single snapshot test execution.
///
/// Contains the outcome of testing a single schema or operation file,
/// including whether it passed, any error messages, and code snippets
/// showing the error location.
#[derive(Debug)]
pub struct SnapshotTestResult {
    /// Name of the test (e.g., "simple/schema" or "swapi/valid_operations/get_user.graphql")
    pub test_name: String,
    /// Whether the test passed
    pub passed: bool,
    /// Error message if the test failed
    pub error_message: Option<String>,
    /// Path to the test fixture file
    pub file_path: PathBuf,
    /// Code snippet showing error context with line numbers
    pub file_snippet: Option<String>,
}

/// Collection of snapshot test results with reporting capabilities.
///
/// Aggregates results from multiple snapshot tests and provides methods
/// for checking overall success and generating failure reports.
#[derive(Debug)]
pub struct SnapshotTestResults {
    /// Individual test results
    pub results: Vec<SnapshotTestResult>,
}

impl SnapshotTestResults {
    pub fn new() -> Self {
        Self {
            results: Vec::new(),
        }
    }

    pub fn all_passed(&self) -> bool {
        self.results.iter().all(|r| r.passed)
    }

    pub fn extend(&mut self, results: Vec<SnapshotTestResult>) {
        self.results.extend(results);
    }

    pub fn failure_report(&self) -> String {
        let failures: Vec<_> = self.results.iter().filter(|r| !r.passed).collect();
        let failures_len = failures.len();
        let results_len = self.results.len();
        let failures_text = failures
            .iter()
            .map(|r| format_detailed_failure(r))
            .collect::<Vec<_>>()
            .join("\n\n");

        format!("{failures_len} of {results_len} snapshot tests failed:\n\n{failures_text}")
    }

    pub fn summary(&self) -> String {
        let all_passed = self.all_passed();
        let emoji = if all_passed { "" } else { "" };
        let banner = format!("{emoji} ========================================");
        let header = format!("{emoji} GOLDEN TEST SUMMARY");
        let total = self.results.len();

        if all_passed {
            format!("{banner}\n{header}\n{banner}\nTotal tests: {total}\nPassed: {total}\nFailed: 0\n\nAll snapshot tests passed!\n{banner}")
        } else {
            let failures: Vec<_> = self.results.iter().filter(|r| !r.passed).collect();
            let failures_len = failures.len();
            let passed = total - failures_len;
            let failed_list = failures
                .iter()
                .map(|r| {
                    let test_name = &r.test_name;
                    let error = r.error_message.as_deref().unwrap_or("error");
                    format!("  - {test_name} ({error})")
                })
                .collect::<Vec<_>>()
                .join("\n");

            format!("{banner}\n{header}\n{banner}\nTotal tests: {total}\nPassed: {passed}\nFailed: {failures_len}\n\nFailed snapshot tests:\n{failed_list}\n\nSee details above for each failure.\n{banner}")
        }
    }
}

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

/// Format a detailed failure message with file path, snippet, and error location
fn format_detailed_failure(result: &SnapshotTestResult) -> String {
    let mut output = String::new();
    let test_name = &result.test_name;
    let file_path = result.file_path.display();

    // Header with test name
    output.push_str(&format!("{test_name}\n"));

    // Absolute file path
    output.push_str(&format!("   File: {file_path}\n"));

    // Error message
    if let Some(msg) = &result.error_message {
        output.push_str(&format!("   {msg}\n"));
    }

    // File snippet with line numbers and error markers
    if let Some(snippet) = &result.file_snippet {
        output.push('\n');
        output.push_str(snippet);
    }

    output
}

/// Run all schema validation snapshot tests.
///
/// Discovers and executes all schema snapshot tests from the fixtures directory.
/// Tests both valid schemas (which should build successfully) and invalid schemas
/// (which should fail with specific error patterns).
///
/// Returns aggregated test results for all schema tests.
pub fn run_schema_tests(fixtures_dir: &Path) -> SnapshotTestResults {
    let test_cases = SchemaSnapshotTestCase::discover_all(fixtures_dir);

    let test_results: Vec<SnapshotTestResult> = test_cases
        .par_iter()
        .map(|test_case| {
            if test_case.schema_expected_errors.is_empty() {
                test_valid_schema(test_case)
            } else {
                test_invalid_schema(test_case)
            }
        })
        .collect();

    let mut results = SnapshotTestResults::new();
    results.extend(test_results);
    results
}

/// Test a single valid schema (single or multi-file)
fn test_valid_schema(test_case: &SchemaSnapshotTestCase) -> SnapshotTestResult {
    let name = &test_case.name;
    let test_name = format!("{name}/schema");

    // Build schema from all schema files
    let mut builder = SchemaBuilder::new();

    for schema_path in &test_case.schema_paths {
        builder = match builder.load_file(schema_path) {
            Ok(b) => b,
            Err(e) => {
                return SnapshotTestResult {
                    test_name,
                    passed: false,
                    error_message: Some(format_expected_actual_error("Valid schema", &format!("{e:?}"))),
                    file_path: schema_path.clone(),
                    file_snippet: None,
                };
            }
        };
    }

    match builder.build() {
        Ok(_) => SnapshotTestResult {
            test_name,
            passed: true,
            error_message: None,
            file_path: test_case.schema_paths[0].clone(),
            file_snippet: None,
        },
        Err(e) => {
            let error_str = format!("{e:?}");
            let file_path = test_case.schema_paths[0].clone();

            let (snippet, snippet_error) = match extract_snippet_with_error_marker(&file_path, SCHEMA_ERROR_SNIPPET_LINES) {
                Ok(s) => (Some(s), None),
                Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
            };

            let mut error_message = format_expected_actual_error("Valid schema", &error_str);
            if let Some(snip_err) = snippet_error {
                error_message = format!("{error_message}\n\n{snip_err}");
            }

            SnapshotTestResult {
                test_name,
                passed: false,
                error_message: Some(error_message),
                file_path,
                file_snippet: snippet,
            }
        }
    }
}

/// Test a single invalid schema (single or multi-file)
fn test_invalid_schema(test_case: &SchemaSnapshotTestCase) -> SnapshotTestResult {
    let name = &test_case.name;
    let test_name = format!("{name}/schema");

    // Build schema from all schema files
    let mut builder = SchemaBuilder::new();

    for schema_path in &test_case.schema_paths {
        builder = match builder.load_file(schema_path) {
            Ok(b) => b,
            Err(e) => {
                // Early error during loading - check if it matches expected patterns
                let error_str = format!("{e:?}");
                let errors = [error_str.clone()];

                if !test_case.schema_expected_errors.is_empty() {
                    let all_match = test_case
                        .schema_expected_errors
                        .iter()
                        .all(|pattern| errors.iter().any(|e| utils::error_matches_pattern(e, pattern)));

                    if all_match {
                        return SnapshotTestResult {
                            test_name,
                            passed: true,
                            error_message: None,
                            file_path: schema_path.clone(),
                            file_snippet: None,
                        };
                    }
                }

                // Error occurred but didn't match expected
                return SnapshotTestResult {
                    test_name,
                    passed: false,
                    error_message: Some(format!(
                        "Expected: Specific error patterns\nGot: Error occurred but didn't match expected patterns\n\nActual error:\n{error_str}"
                    )),
                    file_path: schema_path.clone(),
                    file_snippet: None,
                };
            }
        };
    }

    match builder.build() {
        Ok(_) => {
            // Schema should have failed but didn't
            let file_path = test_case.schema_paths[0].clone();

            let (snippet, snippet_error) = match create_missing_error_snippet(&file_path) {
                Ok(s) => (Some(s), None),
                Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
            };

            let mut error_message = format_false_negative_error("Schema", &test_case.schema_expected_errors);
            if let Some(snip_err) = snippet_error {
                error_message = format!("{error_message}\n\n{snip_err}");
            }

            SnapshotTestResult {
                test_name,
                passed: false,
                error_message: Some(error_message),
                file_path,
                file_snippet: snippet,
            }
        }
        Err(e) => {
            // Schema failed - check if error matches expected patterns
            let error_str = format!("{e:?}");
            let errors = [error_str.clone()];

            if test_case.schema_expected_errors.is_empty() {
                // No specific expectation - any error is fine
                return SnapshotTestResult {
                    test_name,
                    passed: true,
                    error_message: None,
                    file_path: test_case.schema_paths[0].clone(),
                    file_snippet: None,
                };
            }

            // Check if all expected patterns match
            let all_match = test_case
                .schema_expected_errors
                .iter()
                .all(|pattern| errors.iter().any(|e| utils::error_matches_pattern(e, pattern)));

            if all_match {
                SnapshotTestResult {
                    test_name,
                    passed: true,
                    error_message: None,
                    file_path: test_case.schema_paths[0].clone(),
                    file_snippet: None,
                }
            } else {
                // Not all patterns matched
                let unmatched: Vec<_> = test_case
                    .schema_expected_errors
                    .iter()
                    .filter(|pattern| !errors.iter().any(|e| utils::error_matches_pattern(e, pattern)))
                    .collect();

                let file_path = test_case.schema_paths[0].clone();

                let (snippet, snippet_error) = match create_missing_error_snippet(&file_path) {
                    Ok(s) => (Some(s), None),
                    Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
                };

                let mut error_message = format!(
                    "{}\n\nActual error:\n{error_str}",
                    format_unmatched_patterns_error(&unmatched, &errors)
                );
                if let Some(snip_err) = snippet_error {
                    error_message = format!("{error_message}\n\n{snip_err}");
                }

                SnapshotTestResult {
                    test_name,
                    passed: false,
                    error_message: Some(error_message),
                    file_path,
                    file_snippet: snippet,
                }
            }
        }
    }
}

/// Extract a code snippet from a file with line numbers and error markers
fn extract_snippet_with_error_marker(
    file_path: &Path,
    context_lines: usize,
) -> Result<String, std::io::Error> {
    let content = fs::read_to_string(file_path)?;
    let lines: Vec<&str> = content.lines().collect();

    let start_line = 0;
    let end_line = context_lines.min(lines.len());

    let mut snippet = String::new();
    let line_num_width = (end_line + 1).to_string().len();

    for (idx, line) in lines[start_line..end_line].iter().enumerate() {
        let line_num = start_line + idx + 1;
        snippet.push_str(&format!("   {line_num:>line_num_width$} │ {line}\n"));
    }

    Ok(snippet)
}

/// Create a snippet showing where an error was expected but didn't occur
fn create_missing_error_snippet(file_path: &Path) -> Result<String, std::io::Error> {
    let content = fs::read_to_string(file_path)?;
    let lines: Vec<&str> = content.lines().collect();

    let mut snippet = String::new();
    snippet.push_str("   Expected errors based on comments:\n");

    for (idx, line) in lines.iter().enumerate().take(EXPECTED_ERROR_PREVIEW_LINES) {
        let line_num = idx + 1;
        let trimmed = line.trim_start();
        if trimmed.starts_with("# EXPECTED_ERROR_TYPE:") || trimmed.starts_with("# EXPECTED_ERROR_CONTAINS:") {
            snippet.push_str(&format!("   {line_num:>3}{line} ⚠️ (error not raised!)\n"));
        } else if idx < 5 {
            snippet.push_str(&format!("   {line_num:>3}{line}\n"));
        }
    }

    Ok(snippet)
}

/// Run all operation validation snapshot tests.
///
/// Discovers and executes all operation snapshot tests from the fixtures directory.
/// Tests both valid operations (which should validate successfully) and invalid
/// operations (which should fail with specific error patterns).
///
/// Only tests operations against valid schemas. Invalid schemas are skipped.
///
/// Returns aggregated test results for all operation tests.
pub fn run_operation_tests(fixtures_dir: &Path) -> SnapshotTestResults {
    let test_cases = SchemaSnapshotTestCase::discover_all(fixtures_dir);

    let test_results: Vec<SnapshotTestResult> = test_cases
        .par_iter()
        .filter(|test_case| test_case.schema_expected_errors.is_empty())
        .filter_map(|test_case| {
            // Build the schema first
            let schema = try_build_schema(&test_case.schema_paths)?;

            // Build fragment registry once for the suite from all valid operations
            let fragment_registry = match build_suite_fragment_registry(&schema, &test_case.valid_operations) {
                Ok(reg) => reg,
                Err(err) => {
                    // If we can't build the fragment registry, return an error result
                    return Some(vec![SnapshotTestResult {
                        test_name: format!("{}/fragment_registry", test_case.name),
                        passed: false,
                        error_message: Some(format!("Failed to build suite fragment registry: {err}")),
                        file_path: test_case.schema_paths.first().cloned().unwrap_or_default(),
                        file_snippet: None,
                    }]);
                }
            };

            // Test valid operations with the suite registry
            let mut results = test_valid_operations(test_case, &schema, &fragment_registry);

            // Test invalid operations with the suite registry
            let invalid_results = test_invalid_operations(test_case, &schema, &fragment_registry);
            results.extend(invalid_results);

            Some(results)
        })
        .flatten()
        .collect();

    let mut results = SnapshotTestResults::new();
    results.extend(test_results);
    results
}

/// Helper to try building a schema from multiple files
fn try_build_schema(schema_paths: &[PathBuf]) -> Option<Schema> {
    let mut builder = SchemaBuilder::new();

    for schema_path in schema_paths {
        builder = match builder.load_file(schema_path) {
            Ok(b) => b,
            Err(_) => return None,
        };
    }

    builder.build().ok()
}

/// Test valid operations against a schema with a shared fragment registry
fn test_valid_operations(
    test_case: &SchemaSnapshotTestCase,
    schema: &Schema,
    fragment_registry: &FragmentRegistry,
) -> Vec<SnapshotTestResult> {
    let mut results = Vec::new();

    if test_case.valid_operations.is_empty() {
        return results;
    }

    // Test each valid operation using the suite-level fragment registry
    for op_test in &test_case.valid_operations {
        let test_name = format!(
            "{}/valid_operations/{}",
            test_case.name,
            op_test.path.file_name().unwrap().to_str().unwrap()
        );

        let exec_doc_result =
            ExecutableDocumentBuilder::from_file(schema, fragment_registry, &op_test.path);

        match exec_doc_result {
            Ok(_) => {
                results.push(SnapshotTestResult {
                    test_name,
                    passed: true,
                    error_message: None,
                    file_path: op_test.path.clone(),
                    file_snippet: None,
                });
            }
            Err(errors) => {
                let error_str = format!("{errors:?}");

                let (snippet, snippet_error) = match extract_snippet_with_error_marker(&op_test.path, OPERATION_ERROR_SNIPPET_LINES) {
                    Ok(s) => (Some(s), None),
                    Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
                };

                let mut error_message = format_expected_actual_error("Valid operation", &error_str);
                if let Some(snip_err) = snippet_error {
                    error_message = format!("{error_message}\n\n{snip_err}");
                }

                results.push(SnapshotTestResult {
                    test_name,
                    passed: false,
                    error_message: Some(error_message),
                    file_path: op_test.path.clone(),
                    file_snippet: snippet,
                });
            }
        }
    }

    results
}

/// Test invalid operations against a schema with a shared fragment registry
fn test_invalid_operations(
    test_case: &SchemaSnapshotTestCase,
    schema: &Schema,
    fragment_registry: &FragmentRegistry,
) -> Vec<SnapshotTestResult> {
    let mut results = Vec::new();

    if test_case.invalid_operations.is_empty() {
        return results;
    }

    // Test each invalid operation using the suite-level fragment registry
    for op_test in &test_case.invalid_operations {
        let test_name = format!(
            "{}/invalid_operations/{}",
            test_case.name,
            op_test.path.file_name().unwrap().to_str().unwrap()
        );

        let exec_doc_result =
            ExecutableDocumentBuilder::from_file(schema, fragment_registry, &op_test.path);

        match exec_doc_result {
            Ok(_) => {
                // Operation should have failed but didn't
                let (snippet, snippet_error) = match create_missing_error_snippet(&op_test.path) {
                    Ok(s) => (Some(s), None),
                    Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
                };

                let mut error_message = format_false_negative_error("Operation", &op_test.expected_errors);
                if let Some(snip_err) = snippet_error {
                    error_message = format!("{error_message}\n\n{snip_err}");
                }

                results.push(SnapshotTestResult {
                    test_name,
                    passed: false,
                    error_message: Some(error_message),
                    file_path: op_test.path.clone(),
                    file_snippet: snippet,
                });
            }
            Err(errors) => {
                // Operation failed - check if expected errors match
                let error_strs: Vec<String> = errors.iter().map(|e| format!("{e:?}")).collect();

                if op_test.all_expected_errors_match(&error_strs) {
                    results.push(SnapshotTestResult {
                        test_name,
                        passed: true,
                        error_message: None,
                        file_path: op_test.path.clone(),
                        file_snippet: None,
                    });
                } else {
                    // Errors don't match expected
                    let unmatched: Vec<_> = op_test
                        .expected_errors
                        .iter()
                        .filter(|pattern| !error_strs.iter().any(|e| utils::error_matches_pattern(e, pattern)))
                        .collect();

                    let (snippet, snippet_error) = match create_missing_error_snippet(&op_test.path) {
                        Ok(s) => (Some(s), None),
                        Err(e) => (None, Some(format!("Could not extract code snippet: {e}"))),
                    };

                    let mut error_message = format!(
                        "{}\n\nActual errors:\n{}",
                        format_unmatched_patterns_error(&unmatched, &error_strs),
                        error_strs.iter().map(|e| format!("  - {e}")).collect::<Vec<_>>().join("\n")
                    );
                    if let Some(snip_err) = snippet_error {
                        error_message = format!("{error_message}\n\n{snip_err}");
                    }

                    results.push(SnapshotTestResult {
                        test_name,
                        passed: false,
                        error_message: Some(error_message),
                        file_path: op_test.path.clone(),
                        file_snippet: snippet,
                    });
                }
            }
        }
    }

    results
}

/// Build FragmentRegistry for an entire test suite from all valid operations.
///
/// This builds a single fragment registry from all valid operation files in the suite,
/// which is then shared across all operation tests. This matches the design where
/// fragments are meant to be reusable across operations within a suite.
fn build_suite_fragment_registry<'schema>(
    schema: &'schema Schema,
    valid_operations: &[OperationSnapshotTestCase],
) -> Result<FragmentRegistry<'schema>, String> {
    let mut registry_builder = FragmentRegistryBuilder::new();

    for op_test in valid_operations {
        // Read the file content
        let content = fs::read_to_string(&op_test.path)
            .map_err(|e| format!("Failed to read file {}: {}", op_test.path.display(), e))?;

        // Parse as AST
        let ast_doc = graphql_parser::query::parse_query::<String>(&content)
            .map_err(|e| format!("Failed to parse GraphQL in {}: {}", op_test.path.display(), e))?
            .into_static();

        // Add fragments from this document
        registry_builder
            .add_from_document_ast(
                schema,
                &ast::operation::Document::from(ast_doc),
                Some(&op_test.path),
            )
            .map_err(|e| {
                format!(
                    "Failed to add fragments from {}: {:?}",
                    op_test.path.display(),
                    e
                )
            })?;
    }

    registry_builder
        .build()
        .map_err(|e| format!("Failed to build suite fragment registry: {e:?}"))
}