Skip to main content

verificar/
lib.rs

1//! Verificar - Synthetic Data Factory for Domain-Specific Code Intelligence
2//!
3//! Verificar is a unified combinatorial test generation and synthetic data factory
4//! that serves multiple transpiler projects (depyler, bashrs, ruchy, decy). It generates
5//! verified `(source, target, correctness)` tuples at scale, creating training data
6//! for domain-specific code intelligence models.
7//!
8//! # Architecture
9//!
10//! ```text
11//! ┌─────────────────────────────────────────────────────────────┐
12//! │                       VERIFICAR CORE                        │
13//! ├─────────────────────────────────────────────────────────────┤
14//! │  Grammar    →   Generator   →   Mutator   →   Oracle       │
15//! │  Definitions    Engine         Engine         Verification  │
16//! └─────────────────────────────────────────────────────────────┘
17//! ```
18//!
19//! # Quick Start
20//!
21//! ```rust,no_run
22//! use verificar::generator::{Generator, SamplingStrategy};
23//! use verificar::Language;
24//!
25//! // Create a generator for Python
26//! let generator = Generator::new(Language::Python);
27//!
28//! // Generate test cases using coverage-guided sampling
29//! let strategy = SamplingStrategy::CoverageGuided {
30//!     coverage_map: None,
31//!     max_depth: 3,
32//!     seed: 42,
33//! };
34//! let test_cases = generator.generate(strategy, 100);
35//! ```
36//!
37//! # Modules
38//!
39//! - [`grammar`] - Language grammar definitions (tree-sitter, pest PEGs)
40//! - [`generator`] - Combinatorial program generation engine
41//! - [`mutator`] - AST mutation operators (AOR, ROR, LOR, BSR, etc.)
42//! - [`oracle`] - Verification oracle (sandbox execution, I/O diffing)
43//! - [`data`] - Data pipeline (Parquet output)
44//! - [`ml`] - ML model training (bug prediction, embeddings)
45
46// Note: Lint configuration is in Cargo.toml [workspace.lints]
47#![forbid(unsafe_code)]
48
49#[macro_use]
50#[allow(unused_macros, clippy::duplicated_attributes)]
51mod generated_contracts;
52
53pub mod audit;
54pub mod data;
55pub mod error;
56pub mod generator;
57pub mod grammar;
58pub mod ml;
59pub mod mutator;
60pub mod oracle;
61pub mod transpiler;
62
63use serde::{Deserialize, Serialize};
64
65pub use error::{Error, Result};
66
67// Audit Trail exports (entrenar-style provenance)
68pub use audit::{
69    new_audit_collector, AuditCollector, AuditStats, AuditTrace, ChainVerification,
70    ExecutionSummary, HashChainEntry, VerificationPath, VerificationTimer,
71};
72
73/// Supported source languages for generation
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
75pub enum Language {
76    /// Python (depyler source → Rust)
77    Python,
78    /// Bash (bashrs source → Rust)
79    Bash,
80    /// C (decy source → Rust)
81    C,
82    /// TypeScript (decy target for C → TypeScript)
83    TypeScript,
84    /// Ruchy (standalone language)
85    Ruchy,
86    /// Rust (common target language)
87    Rust,
88}
89
90impl std::fmt::Display for Language {
91    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
92        match self {
93            Self::Python => write!(f, "python"),
94            Self::Bash => write!(f, "bash"),
95            Self::C => write!(f, "c"),
96            Self::TypeScript => write!(f, "typescript"),
97            Self::Ruchy => write!(f, "ruchy"),
98            Self::Rust => write!(f, "rust"),
99        }
100    }
101}
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn test_language_display_python() {
109        assert_eq!(format!("{}", Language::Python), "python");
110    }
111
112    #[test]
113    fn test_language_display_bash() {
114        assert_eq!(format!("{}", Language::Bash), "bash");
115    }
116
117    #[test]
118    fn test_language_display_c() {
119        assert_eq!(format!("{}", Language::C), "c");
120    }
121
122    #[test]
123    fn test_language_display_ruchy() {
124        assert_eq!(format!("{}", Language::Ruchy), "ruchy");
125    }
126
127    #[test]
128    fn test_language_display_rust() {
129        assert_eq!(format!("{}", Language::Rust), "rust");
130    }
131
132    #[test]
133    fn test_language_display_typescript() {
134        assert_eq!(format!("{}", Language::TypeScript), "typescript");
135    }
136
137    #[test]
138    fn test_language_clone() {
139        let lang = Language::Python;
140        let cloned = lang.clone();
141        assert_eq!(lang, cloned);
142    }
143
144    #[test]
145    fn test_language_copy() {
146        let lang = Language::Python;
147        let copied = lang;
148        assert_eq!(lang, copied);
149    }
150
151    #[test]
152    fn test_language_debug() {
153        let debug_str = format!("{:?}", Language::Python);
154        assert!(debug_str.contains("Python"));
155    }
156}
157
158/// Prelude module for convenient imports
159pub mod prelude {
160    pub use crate::generator::{Generator, SamplingStrategy};
161    pub use crate::mutator::{MutationOperator, Mutator};
162    pub use crate::oracle::{Oracle, Verdict, VerificationResult};
163    pub use crate::transpiler::{
164        Transpiler, TranspilerConfig, TranspilerOracle, TranspilerVerdict, VerificationStats,
165    };
166    pub use crate::{Error, Language, Result};
167}