vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Adversary corpus — deliberately-broken component implementations that
//! the meta-test suite MUST reject.
//!
//! For every [`ComponentSpec`], the contributor (or an adversary agent in
//! the Implementor/Prosecutor/Defender flow) writes one or more
//! [`BrokenComponent`] entries. Each entry carries a specific bug that a
//! *good* meta-test set will detect: a law checker that skips a boundary,
//! a reference interpreter that returns the wrong answer on one Expr
//! variant, an oracle resolver that downgrades to property when a law
//! applies.
//!
//! The meta-gate runs the committed meta-test set against every adversary
//! in the corpus. If any adversary slips past the tests, the meta-test set
//! is rejected with structured feedback naming the adversary and the
//! expected failure signature.
//!
//! [`ComponentSpec`]: crate::meta::component::ComponentSpec

use crate::meta::mutation::MetaMutationClass;

/// Policy used when matching test output against an adversary signature.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum SignatureMatchPolicy {
    /// Byte-for-byte equality after trimming leading/trailing whitespace.
    Exact,
    /// Substring containment.
    Substring,
}

/// One deliberately-broken component implementation. Static dispatch only
/// — each adversary is registered at compile time as a `&'static` entry so
/// the registry is verifiable by the build script.
#[derive(Debug, Clone, Copy)]
pub struct BrokenComponent {
    /// Stable identifier for this adversary, unique within its component.
    ///
    /// Used by structured feedback: when a meta-test set fails to catch
    /// this adversary, the feedback names it so the contributor knows
    /// exactly which bug they must detect. Example: `"skip_u32_max_pair"`.
    pub id: &'static str,
    /// Human-readable description of the bug this adversary injects.
    ///
    /// Two sentences max. Names the corruption and the symptom a correct
    /// meta-test must notice. Example: `"Commutativity checker skips the
    /// (u32::MAX, 0) witness pair. Symptom: declares an op commutative
    /// when it has a single-point asymmetry at the u32 upper boundary."`
    pub description: &'static str,
    /// The qualified path of the component this adversary corrupts.
    ///
    /// Must match a [`crate::meta::component::ComponentSpec::name`]
    /// exactly. Used by the registry checker to route adversaries to
    /// their components.
    pub targets: &'static str,
    /// The signature a meta-test must produce when it detects this
    /// adversary — e.g., `"returned Counterexample { id: \"u32_max_pair\" }"`.
    ///
    /// The meta-harness matches test output against this signature; an
    /// exact match earns the test credit for killing the adversary.
    pub expected_failure_signature: &'static str,
    /// How the harness matches `expected_failure_signature` against test output.
    pub signature_match_policy: SignatureMatchPolicy,
    /// Explicit mutation classes this adversary covers.
    pub covers_classes: &'static [MetaMutationClass],
    /// Contract ids this adversary exercises (for build-time coverage).
    pub covers_contract_ids: &'static [&'static str],
}

/// A `&'static` reference to a [`BrokenComponent`]. Used in
/// [`crate::meta::component::ComponentSpec::adversaries`] so the list can
/// be a compile-time constant slice.
pub type AdversaryRef = &'static BrokenComponent;

/// Match `output` against `signature` using the chosen `policy`.
#[must_use]
#[inline]
pub fn matches_signature(output: &str, signature: &str, policy: SignatureMatchPolicy) -> bool {
    match policy {
        SignatureMatchPolicy::Exact => output.trim() == signature.trim(),
        SignatureMatchPolicy::Substring => output.contains(signature),
    }
}