Crate leviso_cheat_guard

Crate leviso_cheat_guard 

Source
Expand description

§leviso-cheat-guard

Runtime macros for cheat-aware error handling in non-test contexts.

This crate provides macro_rules! macros that work like anyhow::bail! and anyhow::ensure! but include cheat documentation in error messages.

§Why This Exists

The leviso-cheat-test crate provides proc-macro attributes for #[test] functions. But install-tests uses a custom Step trait, not standard tests. This crate provides macros that can be used inside any function to document cheat vectors and fail with informative messages.

§Macros

  • cheat_bail! - Like bail!() but with cheat documentation
  • cheat_ensure! - Like ensure!() but with cheat documentation
  • cheat_check! - Check a condition and add to StepResult with cheat metadata

§Example

use leviso_cheat_guard::cheat_bail;

fn partition_disk(console: &mut Console) -> Result<()> {
    let output = console.exec("sfdisk /dev/vda", timeout)?;

    if !output.contains("vda1") {
        cheat_bail!(
            protects = "Disk is partitioned correctly",
            severity = "CRITICAL",
            cheats = ["Accept exit code without verification", "Skip partition check"],
            consequence = "No partitions, installation fails silently",
            "Partition vda1 not found after sfdisk"
        );
    }

    Ok(())
}

Macros§

cheat_bail
Bail with cheat-aware error message.
cheat_check
Check a condition and record result with cheat metadata.
cheat_ensure
Ensure a condition with cheat-aware error message.

Enums§

CheckResult
CheckResult for use with cheat_check! macro. Mirrors the install-tests CheckResult enum.

Attribute Macros§

cheat_aware
Mark a test as cheat-aware, documenting how it could be cheated.
cheat_canary
Mark a test as a canary - an intentionally verbose/tedious test that should trigger extra scrutiny if modified.
cheat_reviewed
A simpler version of cheat_aware for tests where full metadata isn’t needed.