//! Drift test for the `sv:{ppnum_id}` shared cache contract.
//!
//! Asserts that `sv_cache_key()` and `SV_CACHE_TTL` still produce the
//! values documented in `0context/STANDARDS_SHARED_CACHE.md §3.1` (the
//! cross-service contract). If anyone changes the constant value or
//! the key shape function without updating the standards doc — and
//! propagating the change through the PAS writer + PCS reader + SDK
//! reader — this test fails on the very next CI run, surfacing the
//! drift before it reaches production.
//!
//! See also `STANDARDS_AUTH_PPOPPO.md §17.7` (wiring status table) and
//! `STANDARDS_SHARED_CACHE.md §7` (Standards Sync Triggers row for
//! `SV_CACHE_KEY_PREFIX` / `SV_CACHE_TTL` value changes).

#![allow(clippy::unwrap_used, clippy::expect_used)]

use std::time::Duration;

use ppoppo_token::{SV_CACHE_TTL, sv_cache_key};

/// Key shape `sv:{ppnum_id}` is a cross-service contract — PAS writer
/// and PCS / SDK readers all build the key by calling this function,
/// so they cannot drift on the prefix or separator. The expected
/// shape is documented in STANDARDS_SHARED_CACHE §3.1 ("Key shape"
/// row).
#[test]
fn sv_cache_key_produces_documented_shape() {
    // Realistic ULID input.
    assert_eq!(
        sv_cache_key("01HZXY12345678901234567890"),
        "sv:01HZXY12345678901234567890",
    );
    // Empty input still yields the bare prefix — defensive check that
    // the prefix itself is exactly `sv:` (no trailing space, no other
    // separator).
    assert_eq!(sv_cache_key(""), "sv:");
}

/// TTL is documented as 60 s in STANDARDS_SHARED_CACHE §3.1 ("TTL"
/// row) and §4 (TTL guidance — auth decisions). Any change here
/// shifts the post-break-glass staleness upper bound for SDK
/// consumers and must propagate to the standards doc + the §6.9
/// Cross-system effect timing table in STANDARDS_AUTH_PPOPPO.
#[test]
fn sv_cache_ttl_matches_standards_doc() {
    assert_eq!(SV_CACHE_TTL, Duration::from_secs(60));
}
