Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types Reference

This chapter documents the core types used throughout cargo-ninety-nine.

Test Execution

TestRun

A single test execution record with full metadata.

#![allow(unused)]
fn main() {
pub struct TestRun {
    pub id: Uuid,
    pub test_name: TestName,
    pub test_path: PathBuf,
    pub outcome: TestOutcome,
    pub duration: Duration,
    pub timestamp: DateTime<Utc>,
    pub commit_hash: String,
    pub branch: String,
    pub environment: TestEnvironment,
    pub retry_count: u32,
    pub error_message: Option<String>,
    pub stack_trace: Option<String>,
}
}
FieldTypeDescription
idUuidUnique identifier for this run
test_nameTestNameType-safe test name
test_pathPathBufPath to the test binary
outcomeTestOutcomeResult of the execution
durationDurationWall-clock execution time
timestampDateTime<Utc>When the run occurred
commit_hashStringGit commit at time of run
branchStringGit branch at time of run
environmentTestEnvironmentExecution environment details
retry_countu32Number of retries before this result
error_messageOption<String>Failure message, if any
stack_traceOption<String>Stack trace on panic/failure

TestOutcome

Classification of a test execution result.

#![allow(unused)]
fn main() {
pub enum TestOutcome {
    Passed,
    Failed,
    Ignored,
    Timeout,
    Panic,
}
}
VariantDescription
PassedTest completed successfully (exit code 0)
FailedTest assertion failed (non-zero exit, no panic)
IgnoredTest marked with #[ignore]
TimeoutTest exceeded the configured timeout
PanicTest panicked (detected via panicked at in output)

Implements Display and FromStr for serialization. Display values: "passed", "failed", "ignored", "timeout", "panic".

TestEnvironment

Captures the environment where tests execute, used for pattern correlation.

#![allow(unused)]
fn main() {
pub struct TestEnvironment {
    pub os: String,
    pub rust_version: String,
    pub cpu_count: u32,
    pub memory_gb: f64,
    pub is_ci: bool,
    pub ci_provider: Option<String>,
}
}

Auto-detected at runtime from the host system. The is_ci field is inferred from environment variables (GITHUB_ACTIONS, GITLAB_CI, JENKINS_URL, CIRCLECI, TF_BUILD, BUILDKITE).

TestName

Newtype wrapper providing type-safe test names. Prevents accidental confusion with branch names, commit hashes, or other string fields.

#![allow(unused)]
fn main() {
pub struct TestName(String);
}

Conversions:

  • From<String>, From<&str> — construct from strings
  • Deref<Target = str> — borrow as &str
  • AsRef<str> — reference conversion
  • Display — format for output
  • PartialEq<str>, PartialEq<&str> — compare with string values

Methods:

  • into_inner(self) -> String — consume and return the inner string

Flakiness Detection

FlakinessScore

The primary output of the Bayesian detection engine. Contains the computed probability that a test is flaky along with statistical parameters.

#![allow(unused)]
fn main() {
pub struct FlakinessScore {
    pub test_name: TestName,
    pub probability_flaky: f64,
    pub confidence: f64,
    pub pass_rate: f64,
    pub fail_rate: f64,
    pub total_runs: u64,
    pub consecutive_failures: u32,
    pub last_updated: DateTime<Utc>,
    pub bayesian_params: BayesianParams,
}
}
FieldTypeRangeDescription
probability_flakyf64[0.0, 1.0]Posterior mean P(failure)
confidencef64[0.0, 1.0]1 - credible interval width (higher = more certain)
pass_ratef64[0.0, 1.0]Fraction of runs that passed
fail_ratef64[0.0, 1.0]Fraction of runs that failed (= 1 - pass_rate)
total_runsu64—Number of non-ignored executions
consecutive_failuresu32—Trailing failure streak count

BayesianParams

Full Bayesian computation state stored for auditability.

#![allow(unused)]
fn main() {
pub struct BayesianParams {
    pub alpha: f64,
    pub beta: f64,
    pub posterior_mean: f64,
    pub posterior_variance: f64,
    pub credible_interval_lower: f64,
    pub credible_interval_upper: f64,
}
}
FieldDescription
alphaBeta distribution shape parameter (prior + failures)
betaBeta distribution shape parameter (prior + passes)
posterior_meanalpha / (alpha + beta)
posterior_variance(alpha * beta) / ((alpha + beta)^2 * (alpha + beta + 1))
credible_interval_lower2.5th percentile of posterior Beta distribution
credible_interval_upper97.5th percentile of posterior Beta distribution

FlakinessCategory

Human-readable classification of flakiness severity.

#![allow(unused)]
fn main() {
pub enum FlakinessCategory {
    Stable,
    Occasional,
    Moderate,
    Frequent,
    Critical,
}
}
CategoryScore RangeConsole Color
Stable< 0.01Green
Occasional0.01 – 0.05Yellow
Moderate0.05 – 0.15Orange
Frequent0.15 – 0.30Red
Critical>= 0.30Dark Red

Methods:

  • from_score(score: f64) -> Self — classify a probability value
  • label(&self) -> &'static str — human-readable label

Sessions

ActiveSession

Represents a running test session. Created via start(); to_run_session() produces the storable RunSession snapshot while the session stays live.

#![allow(unused)]
fn main() {
pub struct ActiveSession { /* private fields */ }
}

Methods:

MethodSignatureDescription
startfn start(commit_hash: &str, branch: &str) -> SelfCreate a new session
idfn id(&self) -> &UuidGet session UUID
to_run_sessionfn to_run_session(&self) -> RunSessionConvert to storable form (borrowing)

RunSession

A session record suitable for storage. May represent a running or completed session.

#![allow(unused)]
fn main() {
pub struct RunSession {
    pub id: Uuid,
    pub started_at: DateTime<Utc>,
    pub finished_at: Option<DateTime<Utc>>,
    pub test_count: u32,
    pub flaky_count: u32,
    pub commit_hash: String,
    pub branch: String,
}
}

QuarantineEntry

A quarantined test record.

#![allow(unused)]
fn main() {
pub struct QuarantineEntry {
    pub test_name: TestName,
    pub quarantined_at: DateTime<Utc>,
    pub reason: String,
    pub flakiness_score: f64,
    pub auto_quarantined: bool,
}
}

Analysis

TrendDirection

Direction of flakiness change over time.

#![allow(unused)]
fn main() {
pub enum TrendDirection {
    Improving,
    Stable,
    Degrading,
}
}

A delta exceeding 0.05 (5%) triggers Improving (decreased flakiness) or Degrading (increased flakiness). Otherwise Stable.

TrendSummary

Trend analysis result comparing recent vs. historical flakiness.

#![allow(unused)]
fn main() {
pub struct TrendSummary {
    pub test_name: TestName,
    pub direction: TrendDirection,
    pub recent_score: f64,
    pub previous_score: f64,
    pub score_delta: f64,
    pub window_runs: u64,
}
}

FailurePattern

A detected failure pattern with correlation strength.

#![allow(unused)]
fn main() {
pub struct FailurePattern {
    pub pattern_type: PatternType,
    pub occurrences: u32,
    pub correlation: f64,
    pub examples: Vec<String>,
}
}

PatternType

Classification of detected failure patterns.

#![allow(unused)]
fn main() {
pub enum PatternType {
    TimeOfDay,
    Environmental,
    Random,
}
}
VariantTriggerDescription
TimeOfDayFailure concentration > 3x expected in a specific hourFailures cluster at a particular time
EnvironmentalCI vs. local failure rate difference > 15%Environment-specific failures
RandomNo pattern detectedFailures appear randomly distributed