Skip to main content

eggress_testkit/oracle/
mod.rs

1//! Scenario-driven oracle harness for comparing eggress with pproxy.
2//!
3//! This module provides a structured framework for running equivalent
4//! scenarios against both pproxy and eggress, normalizing outputs, and
5//! generating JSON comparison reports.
6//!
7//! # Gating
8//!
9//! Oracle differential tests are gated on `EGRESS_PPROXY_CERTIFY=1`
10//! and require Python 3 with pproxy==2.7.9 installed. Structural tests
11//! that need no pproxy run without any gate variable.
12
13pub mod observations;
14pub mod probes;
15pub mod profile;
16pub mod report;
17pub mod scenario;
18pub mod schema;
19pub mod supervisor;
20
21use std::time::Duration;
22
23/// Environment variable that gates oracle differential tests.
24pub const ORACLE_GATE_VAR: &str = "EGRESS_PPROXY_CERTIFY";
25
26/// Check if the oracle test gate is enabled.
27pub fn oracle_gate_enabled() -> bool {
28    std::env::var(ORACLE_GATE_VAR)
29        .map(|v| v == "1")
30        .unwrap_or(false)
31}
32
33/// Require the oracle gate to be enabled. Panics with a clear message if not.
34pub fn require_oracle_gate() {
35    if !oracle_gate_enabled() {
36        panic!(
37            "oracle tests require {}=1 and pproxy=={}",
38            ORACLE_GATE_VAR,
39            crate::differential::PINNED_PPROXY_VERSION
40        );
41    }
42    if !pproxy_available() {
43        panic!(
44            "pproxy not available; install with: pip install pproxy=={}",
45            crate::differential::PINNED_PPROXY_VERSION
46        );
47    }
48}
49
50fn pproxy_available() -> bool {
51    let python = crate::differential::find_python_binary();
52    std::process::Command::new(&python)
53        .args(["-c", "import pproxy"])
54        .stdout(std::process::Stdio::null())
55        .stderr(std::process::Stdio::null())
56        .status()
57        .map(|s| s.success())
58        .unwrap_or(false)
59}
60
61/// Default timeout for oracle scenario execution.
62pub const DEFAULT_SCENARIO_TIMEOUT: Duration = Duration::from_secs(15);
63
64/// Default timeout for process startup.
65pub const DEFAULT_STARTUP_TIMEOUT: Duration = Duration::from_secs(5);
66
67/// Default timeout for I/O operations.
68pub const DEFAULT_IO_TIMEOUT: Duration = Duration::from_secs(3);