depyler-oracle 4.1.1

ML-powered compile error classification and auto-fixing using aprender models
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
//! Corpus-Based CITL Pattern Mining
//!
//! Mines error→fix patterns from the reprorusted corpus using
//! entrenar's DecisionCITL for Tarantula fault localization.
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────┐     ┌──────────────────┐
//! │  Parquet Corpus     │────►│  CorpusCITL      │
//! │  (606 pairs)        │     │  Pattern Mining  │
//! └─────────────────────┘     └──────────────────┘
//!//!//!                              ┌──────────────────┐
//!                              │  DecisionCITL    │
//!                              │  (Tarantula)     │
//!                              └──────────────────┘
//!//!//!                              ┌──────────────────┐
//!                              │  PatternStore    │
//!                              │  (BM25+Dense)    │
//!                              └──────────────────┘
//! ```
//!
//! # References
//!
//! - Jones & Harrold (2005): Tarantula Fault Localization
//! - Zeller (2002): Isolating Cause-Effect Chains

use crate::OracleError;
use arrow::array::Array; // Required for is_null() method
use entrenar::citl::{
    CITLConfig, CompilationOutcome, DecisionCITL, DecisionPatternStore, DecisionTrace,
    FixSuggestion, PatternStoreConfig, SourceSpan,
};
use std::collections::HashMap;
use std::path::Path;

/// Statistics for corpus ingestion
#[derive(Debug, Clone, Default)]
pub struct IngestionStats {
    /// Total pairs processed
    pub total_pairs: usize,
    /// Pairs with successful Rust transpilation
    pub success_pairs: usize,
    /// Pairs that failed transpilation
    pub failed_pairs: usize,
    /// Unique error patterns discovered
    pub unique_patterns: usize,
    /// Categories processed
    pub categories: usize,
}

/// Corpus-based CITL trainer for pattern mining
///
/// Ingests the reprorusted Python-Rust corpus and builds
/// a pattern library for fix suggestions.
pub struct CorpusCITL {
    /// DecisionCITL trainer for fault localization
    trainer: DecisionCITL,
    /// Pattern store for fix retrieval
    pattern_store: DecisionPatternStore,
    /// Ingestion statistics
    stats: IngestionStats,
    /// Error code to category mapping
    error_categories: HashMap<String, Vec<String>>,
}

impl CorpusCITL {
    /// Create a new CorpusCITL trainer
    ///
    /// # Errors
    ///
    /// Returns error if entrenar CITL initialization fails.
    pub fn new() -> Result<Self, OracleError> {
        Self::with_config(CITLConfig::default(), PatternStoreConfig::default())
    }

    /// Create with custom configuration
    ///
    /// # Errors
    ///
    /// Returns error if initialization fails.
    pub fn with_config(
        citl_config: CITLConfig,
        pattern_config: PatternStoreConfig,
    ) -> Result<Self, OracleError> {
        let trainer = DecisionCITL::with_config(citl_config)
            .map_err(|e| OracleError::Model(e.to_string()))?;
        let pattern_store = DecisionPatternStore::with_config(pattern_config)
            .map_err(|e| OracleError::Model(e.to_string()))?;

        Ok(Self {
            trainer,
            pattern_store,
            stats: IngestionStats::default(),
            error_categories: HashMap::new(),
        })
    }

    /// Ingest corpus from parquet file
    ///
    /// # Arguments
    ///
    /// * `path` - Path to parquet file with columns:
    ///   - `category`: Example category name
    ///   - `python_code`: Original Python source
    ///   - `rust_code`: Transpiled Rust (null if failed)
    ///   - `has_rust`: Boolean indicating success
    ///
    /// # Errors
    ///
    /// Returns error if file cannot be read or parsed.
    pub fn ingest_from_parquet(&mut self, path: &Path) -> Result<IngestionStats, OracleError> {
        use arrow::array::{BooleanArray, StringArray};
        use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
        use std::fs::File;

        let file = File::open(path).map_err(OracleError::Io)?;
        let builder = ParquetRecordBatchReaderBuilder::try_new(file)
            .map_err(|e| OracleError::Model(format!("Parquet read error: {}", e)))?;

        let reader = builder
            .build()
            .map_err(|e| OracleError::Model(format!("Parquet build error: {}", e)))?;

        let mut categories_seen = std::collections::HashSet::new();

        for batch_result in reader {
            let batch =
                batch_result.map_err(|e| OracleError::Model(format!("Batch read error: {}", e)))?;

            // Get columns
            let category_col = batch
                .column_by_name("category")
                .and_then(|c| c.as_any().downcast_ref::<StringArray>());
            let python_col = batch
                .column_by_name("python_code")
                .and_then(|c| c.as_any().downcast_ref::<StringArray>());
            let rust_col = batch
                .column_by_name("rust_code")
                .and_then(|c| c.as_any().downcast_ref::<StringArray>());
            let has_rust_col = batch
                .column_by_name("has_rust")
                .and_then(|c| c.as_any().downcast_ref::<BooleanArray>());

            let (category_col, python_col) = match (category_col, python_col) {
                (Some(c), Some(p)) => (c, p),
                _ => continue,
            };

            for i in 0..batch.num_rows() {
                let category = category_col.value(i).to_string();
                let python_code = python_col.value(i).to_string();
                let rust_code = rust_col.and_then(|c| {
                    if c.is_null(i) {
                        None
                    } else {
                        Some(c.value(i).to_string())
                    }
                });
                let has_rust = has_rust_col.is_some_and(|c| c.value(i));

                categories_seen.insert(category.clone());
                self.stats.total_pairs += 1;

                if let (true, Some(rust)) = (has_rust, rust_code) {
                    // Successful transpilation - record as success session
                    self.stats.success_pairs += 1;

                    let traces = self.extract_decision_traces(&python_code, &rust);
                    let outcome = CompilationOutcome::success();

                    // Create fix pattern from the diff
                    let diff = self.create_diff(&python_code, &rust);

                    self.trainer
                        .ingest_session(traces, outcome, Some(diff))
                        .map_err(|e| OracleError::Model(e.to_string()))?;
                } else {
                    // Failed transpilation - record as failure
                    self.stats.failed_pairs += 1;

                    let traces = self.extract_decision_traces(&python_code, "");
                    let error_code = format!("TRANSPILE_FAIL_{}", category.to_uppercase());

                    let outcome = CompilationOutcome::failure(
                        vec![error_code.clone()],
                        vec![SourceSpan::line("input.py", 1)],
                        vec!["Transpilation not yet supported".to_string()],
                    );

                    self.trainer
                        .ingest_session(traces, outcome, None)
                        .map_err(|e| OracleError::Model(e.to_string()))?;

                    // Track error categories
                    self.error_categories
                        .entry(error_code)
                        .or_default()
                        .push(category.clone());
                }
            }
        }

        self.stats.categories = categories_seen.len();
        self.stats.unique_patterns = self.trainer.pattern_store().len();

        Ok(self.stats.clone())
    }

    /// Ingest a single Python-Rust pair
    ///
    /// # Arguments
    ///
    /// * `python_code` - Original Python source
    /// * `rust_code` - Transpiled Rust code (None if failed)
    /// * `category` - Example category name
    ///
    /// # Errors
    ///
    /// Returns error if ingestion fails.
    pub fn ingest_pair(
        &mut self,
        python_code: &str,
        rust_code: Option<&str>,
        category: &str,
    ) -> Result<(), OracleError> {
        self.stats.total_pairs += 1;

        if let Some(rust) = rust_code {
            self.stats.success_pairs += 1;

            let traces = self.extract_decision_traces(python_code, rust);
            let outcome = CompilationOutcome::success();
            let diff = self.create_diff(python_code, rust);

            self.trainer
                .ingest_session(traces, outcome, Some(diff))
                .map_err(|e| OracleError::Model(e.to_string()))?;
        } else {
            self.stats.failed_pairs += 1;

            let traces = self.extract_decision_traces(python_code, "");
            let error_code = format!("TRANSPILE_FAIL_{}", category.to_uppercase());

            let outcome = CompilationOutcome::failure(
                vec![error_code.clone()],
                vec![SourceSpan::line("input.py", 1)],
                vec!["Transpilation failed".to_string()],
            );

            self.trainer
                .ingest_session(traces, outcome, None)
                .map_err(|e| OracleError::Model(e.to_string()))?;

            // Track error categories
            self.error_categories
                .entry(error_code)
                .or_default()
                .push(category.to_string());
        }

        Ok(())
    }

    /// Suggest fixes for an error
    ///
    /// # Arguments
    ///
    /// * `error_code` - The error code (e.g., "TRANSPILE_FAIL_LOG_PARSER")
    /// * `context` - Decision context (Python AST features used)
    /// * `max_suggestions` - Maximum suggestions to return
    ///
    /// # Returns
    ///
    /// Vector of fix suggestions sorted by relevance.
    pub fn suggest_fix(
        &self,
        error_code: &str,
        context: &[String],
        max_suggestions: usize,
    ) -> Result<Vec<FixSuggestion>, OracleError> {
        self.pattern_store
            .suggest_fix(error_code, context, max_suggestions)
            .map_err(|e| OracleError::Model(e.to_string()))
    }

    /// Get top suspicious decision types (by Tarantula score)
    ///
    /// # Arguments
    ///
    /// * `k` - Number of top types to return
    ///
    /// # Returns
    ///
    /// Vector of (decision_type, suspiciousness_score) pairs.
    #[must_use]
    pub fn top_suspicious_decisions(&self, k: usize) -> Vec<(&str, f32)> {
        self.trainer.top_suspicious_types(k)
    }

    /// Get ingestion statistics
    #[must_use]
    pub fn stats(&self) -> &IngestionStats {
        &self.stats
    }

    /// Get the number of patterns in the store
    #[must_use]
    pub fn pattern_count(&self) -> usize {
        self.pattern_store.len()
    }

    /// Get error categories mapping
    #[must_use]
    pub fn error_categories(&self) -> &HashMap<String, Vec<String>> {
        &self.error_categories
    }

    /// Save patterns to disk (APR format)
    ///
    /// # Errors
    ///
    /// Returns error if file cannot be written.
    pub fn save_patterns(&self, path: &Path) -> Result<(), OracleError> {
        self.pattern_store
            .save_apr(path)
            .map_err(|e| OracleError::Model(e.to_string()))
    }

    /// Load patterns from disk (APR format)
    ///
    /// # Errors
    ///
    /// Returns error if file cannot be read.
    pub fn load_patterns(&mut self, path: &Path) -> Result<(), OracleError> {
        self.pattern_store =
            DecisionPatternStore::load_apr(path).map_err(|e| OracleError::Model(e.to_string()))?;
        Ok(())
    }

    // ========================================================================
    // Private helpers
    // ========================================================================

    /// Extract decision traces from Python code
    fn extract_decision_traces(&self, python_code: &str, _rust_code: &str) -> Vec<DecisionTrace> {
        let mut traces = Vec::new();

        // Extract Python AST features as decision traces
        let features = self.extract_python_features(python_code);

        for (i, feature) in features.iter().enumerate() {
            traces.push(
                DecisionTrace::new(
                    format!("d{}", i),
                    feature.clone(),
                    format!("Python feature: {}", feature),
                )
                .with_span(SourceSpan::line("input.py", 1)),
            );
        }

        traces
    }

    /// Extract Python features for decision tracing
    fn extract_python_features(&self, python_code: &str) -> Vec<String> {
        let mut features = Vec::new();

        // Simple pattern matching for common Python features
        if python_code.contains("stdin") {
            features.push("stdin_usage".to_string());
        }
        if python_code.contains(":=") {
            features.push("walrus_operator".to_string());
        }
        if python_code.contains("async ") || python_code.contains("await ") {
            features.push("async_await".to_string());
        }
        if python_code.contains("yield") {
            features.push("generator".to_string());
        }
        if python_code.contains("lambda") {
            features.push("lambda".to_string());
        }
        if python_code.contains("class ") {
            features.push("class_definition".to_string());
        }
        if python_code.contains("def ") {
            features.push("function_definition".to_string());
        }
        if python_code.contains("import ") {
            features.push("import_statement".to_string());
        }
        if python_code.contains("try:") || python_code.contains("except") {
            features.push("exception_handling".to_string());
        }
        if python_code.contains("with ") {
            features.push("context_manager".to_string());
        }
        if python_code.contains("[") && python_code.contains("for") {
            features.push("list_comprehension".to_string());
        }

        features
    }

    /// Create a diff between Python and Rust code
    fn create_diff(&self, python: &str, rust: &str) -> String {
        // Simple line-by-line diff format
        let mut diff = String::new();

        for line in python.lines() {
            diff.push_str(&format!("- {}\n", line));
        }
        for line in rust.lines() {
            diff.push_str(&format!("+ {}\n", line));
        }

        diff
    }
}

impl Default for CorpusCITL {
    fn default() -> Self {
        Self::new().expect("CorpusCITL initialization failed")
    }
}

// ============================================================================
// EXTREME TDD Tests
// ============================================================================

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

    // ========================================================================
    // Unit Tests - IngestionStats
    // ========================================================================

    #[test]
    fn test_ingestion_stats_default() {
        let stats = IngestionStats::default();
        assert_eq!(stats.total_pairs, 0);
        assert_eq!(stats.success_pairs, 0);
        assert_eq!(stats.failed_pairs, 0);
        assert_eq!(stats.unique_patterns, 0);
        assert_eq!(stats.categories, 0);
    }

    // ========================================================================
    // Unit Tests - CorpusCITL Construction
    // ========================================================================

    #[test]
    fn test_corpus_citl_new() {
        let citl = CorpusCITL::new();
        assert!(citl.is_ok());

        let citl = citl.unwrap();
        assert_eq!(citl.stats().total_pairs, 0);
        assert_eq!(citl.pattern_count(), 0);
    }

    #[test]
    fn test_corpus_citl_default() {
        let citl = CorpusCITL::default();
        assert_eq!(citl.stats().total_pairs, 0);
    }

    // ========================================================================
    // Unit Tests - Feature Extraction
    // ========================================================================

    #[test]
    fn test_extract_python_features_stdin() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("import sys\ndata = sys.stdin.read()");
        assert!(features.contains(&"stdin_usage".to_string()));
        assert!(features.contains(&"import_statement".to_string()));
    }

    #[test]
    fn test_extract_python_features_walrus() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("if (n := len(items)) > 0:");
        assert!(features.contains(&"walrus_operator".to_string()));
    }

    #[test]
    fn test_extract_python_features_async() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("async def fetch(): await get()");
        assert!(features.contains(&"async_await".to_string()));
        assert!(features.contains(&"function_definition".to_string()));
    }

    #[test]
    fn test_extract_python_features_generator() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("def gen(): yield 1");
        assert!(features.contains(&"generator".to_string()));
    }

    #[test]
    fn test_extract_python_features_comprehension() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("squares = [x*x for x in range(10)]");
        assert!(features.contains(&"list_comprehension".to_string()));
    }

    #[test]
    fn test_extract_python_features_exception() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("try:\n  x()\nexcept Error:");
        assert!(features.contains(&"exception_handling".to_string()));
    }

    #[test]
    fn test_extract_python_features_context_manager() {
        let citl = CorpusCITL::new().unwrap();
        let features = citl.extract_python_features("with open('f') as f:");
        assert!(features.contains(&"context_manager".to_string()));
    }

    // ========================================================================
    // Unit Tests - Pair Ingestion
    // ========================================================================

    #[test]
    fn test_ingest_pair_success() {
        let mut citl = CorpusCITL::new().unwrap();

        let python = "def add(a, b): return a + b";
        let rust = "fn add(a: i32, b: i32) -> i32 { a + b }";

        let result = citl.ingest_pair(python, Some(rust), "simple_add");
        assert!(result.is_ok());

        assert_eq!(citl.stats().total_pairs, 1);
        assert_eq!(citl.stats().success_pairs, 1);
        assert_eq!(citl.stats().failed_pairs, 0);
    }

    #[test]
    fn test_ingest_pair_failure() {
        let mut citl = CorpusCITL::new().unwrap();

        let python = "data = sys.stdin.readlines()";

        let result = citl.ingest_pair(python, None, "log_parser");
        assert!(result.is_ok());

        assert_eq!(citl.stats().total_pairs, 1);
        assert_eq!(citl.stats().success_pairs, 0);
        assert_eq!(citl.stats().failed_pairs, 1);
    }

    #[test]
    fn test_ingest_multiple_pairs() {
        let mut citl = CorpusCITL::new().unwrap();

        // Success
        citl.ingest_pair("def f(): pass", Some("fn f() {}"), "simple")
            .unwrap();

        // Failure
        citl.ingest_pair("async def f(): await g()", None, "async_basic")
            .unwrap();

        // Success
        citl.ingest_pair("x = 1 + 2", Some("let x = 1 + 2;"), "math")
            .unwrap();

        assert_eq!(citl.stats().total_pairs, 3);
        assert_eq!(citl.stats().success_pairs, 2);
        assert_eq!(citl.stats().failed_pairs, 1);
    }

    // ========================================================================
    // Unit Tests - Suspiciousness Analysis
    // ========================================================================

    #[test]
    fn test_top_suspicious_decisions_empty() {
        let citl = CorpusCITL::new().unwrap();
        let top = citl.top_suspicious_decisions(5);
        assert!(top.is_empty());
    }

    #[test]
    fn test_top_suspicious_after_ingestion() {
        let mut citl = CorpusCITL::new().unwrap();

        // Ingest some failures with stdin
        for _ in 0..5 {
            citl.ingest_pair("import sys\ndata = sys.stdin.read()", None, "stdin_example")
                .unwrap();
        }

        // Ingest some successes without stdin
        for _ in 0..3 {
            citl.ingest_pair("x = 1", Some("let x = 1;"), "simple")
                .unwrap();
        }

        let top = citl.top_suspicious_decisions(10);
        // stdin_usage should have high suspiciousness (appears in failures, not successes)
        // This is a basic check - exact scores depend on Tarantula implementation
        assert!(!top.is_empty() || citl.stats().failed_pairs > 0);
    }

    // ========================================================================
    // Unit Tests - Error Categories
    // ========================================================================

    #[test]
    fn test_error_categories_tracking() {
        let mut citl = CorpusCITL::new().unwrap();

        citl.ingest_pair("stdin.read()", None, "log_parser")
            .unwrap();
        citl.ingest_pair("if (x := 1):", None, "walrus_operator")
            .unwrap();

        let categories = citl.error_categories();
        assert!(categories.contains_key("TRANSPILE_FAIL_LOG_PARSER"));
        assert!(categories.contains_key("TRANSPILE_FAIL_WALRUS_OPERATOR"));
    }

    // ========================================================================
    // Unit Tests - Diff Creation
    // ========================================================================

    #[test]
    fn test_create_diff() {
        let citl = CorpusCITL::new().unwrap();

        let python = "def add(a, b):\n    return a + b";
        let rust = "fn add(a: i32, b: i32) -> i32 {\n    a + b\n}";

        let diff = citl.create_diff(python, rust);

        assert!(diff.contains("- def add(a, b):"));
        assert!(diff.contains("+ fn add(a: i32, b: i32) -> i32 {"));
    }

    // ========================================================================
    // Property Tests
    // ========================================================================

    use proptest::prelude::*;

    proptest! {
        #[test]
        fn prop_ingestion_counts_consistent(
            success_count in 0usize..20,
            failure_count in 0usize..20
        ) {
            let mut citl = CorpusCITL::new().unwrap();

            for i in 0..success_count {
                citl.ingest_pair(
                    &format!("def f{i}(): pass"),
                    Some(&format!("fn f{i}() {{}}")),
                    &format!("success_{i}"),
                ).unwrap();
            }

            for i in 0..failure_count {
                citl.ingest_pair(
                    &format!("async def f{i}(): await x()"),
                    None,
                    &format!("failure_{i}"),
                ).unwrap();
            }

            prop_assert_eq!(citl.stats().total_pairs, success_count + failure_count);
            prop_assert_eq!(citl.stats().success_pairs, success_count);
            prop_assert_eq!(citl.stats().failed_pairs, failure_count);
        }

        #[test]
        fn prop_feature_extraction_deterministic(code in "[a-z ]+") {
            let citl = CorpusCITL::new().unwrap();
            let features1 = citl.extract_python_features(&code);
            let features2 = citl.extract_python_features(&code);
            prop_assert_eq!(features1, features2);
        }
    }

    // ========================================================================
    // Integration Tests
    // ========================================================================

    #[test]
    #[ignore] // Run with: cargo test --ignored corpus_citl
    fn test_ingest_reprorusted_corpus() {
        use std::path::PathBuf;

        // Path to the reprorusted corpus (use snappy-compressed version)
        let corpus_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
            .parent()
            .unwrap()
            .parent()
            .unwrap()
            .parent()
            .unwrap()
            .join("reprorusted-python-cli")
            .join("data")
            .join("depyler_citl_corpus_uncompressed.parquet");

        if !corpus_path.exists() {
            eprintln!("Skipping test: corpus not found at {:?}", corpus_path);
            return;
        }

        let mut citl = CorpusCITL::new().unwrap();
        let stats = citl.ingest_from_parquet(&corpus_path).unwrap();

        // Verify corpus statistics
        println!("Corpus ingestion stats:");
        println!("  Total pairs: {}", stats.total_pairs);
        println!("  Success pairs: {}", stats.success_pairs);
        println!("  Failed pairs: {}", stats.failed_pairs);
        println!("  Categories: {}", stats.categories);
        println!("  Unique patterns: {}", stats.unique_patterns);

        // Basic sanity checks based on known corpus
        assert!(stats.total_pairs > 500, "Expected 600+ pairs");
        assert!(stats.success_pairs > 400, "Expected 400+ successful pairs");
        assert!(stats.categories > 200, "Expected 200+ categories");

        // Check suspicious decisions
        let suspicious = citl.top_suspicious_decisions(10);
        println!("\nTop 10 suspicious decision types:");
        for (decision_type, score) in &suspicious {
            println!("  {}: {:.3}", decision_type, score);
        }

        // Verify error categories were tracked
        let error_cats = citl.error_categories();
        println!("\nError categories tracked: {}", error_cats.len());
    }
}