forbidden-strings 0.4.1

Out-of-band scanner for forbidden literal strings and regex patterns. Gitignore-aware, fast, dependency-light: built for CI deny-listing of leaked credentials and banned tokens.
//! Cache-warning JSON protocol tests.

use super::{CacheWarning, CacheWarningReason};

/// Every load failure renders exact closed JSON without dynamic data.
#[test]
fn load_failure_reasons_render_exact_json() {
    let cases = [
        (CacheWarningReason::Missing, "missing"),
        (CacheWarningReason::CacheRootUnavailable, "cache-root-unavailable"),
        (CacheWarningReason::Unreadable, "unreadable"),
        (CacheWarningReason::SourceMismatch, "source-mismatch"),
        (CacheWarningReason::Incompatible, "incompatible"),
        (CacheWarningReason::Invalid, "invalid"),
    ];
    for (reason, token) in cases {
        let warning = CacheWarning::compile_from_text(reason);
        assert_eq!(
            warning.to_string(),
            format!(
                "{{\"type\":\"forbidden-strings/cache-warning\",\"schemaVersion\":1,\"reason\":\"{token}\",\"recovery\":\"compile-from-text\"}}",
            ),
        );
    }
}

/// Write failure renders only continue-with-compiled-rules pairing.
#[test]
fn write_failure_renders_exact_json() {
    assert_eq!(
        CacheWarning::write_failed().to_string(),
        "{\"type\":\"forbidden-strings/cache-warning\",\"schemaVersion\":1,\"reason\":\"write-failed\",\"recovery\":\"continue-with-compiled-rules\"}",
    );
}