vyre-driver 0.4.1

Driver layer: registry, runtime, pipeline, routing, diagnostics. Substrate-agnostic backend machinery. Part of the vyre GPU compiler.
//! Contract test for cache-invalidation stub behavior.
//!
//! When `self-substrate-adapters` is disabled (the default), the
//! `impacted_entries_into` function must produce a zero-filled mask of
//! the correct length without panicking, regardless of input values.
//! This test documents and guards that no-op contract.

use vyre_driver::cache_invalidation::{impacted_entries_into, CacheInvalidationScratch};

#[test]
fn stub_returns_zero_mask_of_correct_length() {
    let mut out = vec![99u32; 5];
    let mut scratch = CacheInvalidationScratch::default();

    impacted_entries_into(
        &[1, 0, 1],
        &[0; 9],
        &[0; 9],
        &[0; 9],
        3,
        10,
        &[0; 4],
        &mut out,
        &mut scratch,
    );

    assert_eq!(out.len(), 4, "output length must match lineage_cells.len()");
    assert!(out.iter().all(|&v| v == 0), "stub must return all zeros, got: {:?}", out);
}

#[test]
fn stub_handles_empty_lineage_cells() {
    let mut out = vec![99u32; 3];
    let mut scratch = CacheInvalidationScratch::default();

    impacted_entries_into(&[], &[], &[], &[], 0, 0, &[], &mut out, &mut scratch);

    assert!(out.is_empty(), "empty lineage_cells must produce empty output");
}

#[test]
fn stub_handles_max_u32_n_without_panic() {
    let mut out = vec![99u32; 2];
    let mut scratch = CacheInvalidationScratch::default();

    // n = u32::MAX with tiny arrays: the stub path must not attempt
    // to index or allocate based on n.
    impacted_entries_into(
        &[1],
        &[0],
        &[0],
        &[0],
        u32::MAX,
        u32::MAX,
        &[0; 2],
        &mut out,
        &mut scratch,
    );

    assert_eq!(out.len(), 2);
    assert!(out.iter().all(|&v| v == 0));
}

#[test]
fn stub_reuses_scratch_without_growing() {
    let mut out = vec![99u32; 3];
    let mut scratch = CacheInvalidationScratch::default();

    // First call
    impacted_entries_into(&[1], &[0], &[0], &[0], 1, 1, &[0; 3], &mut out, &mut scratch);
    assert_eq!(out, vec![0, 0, 0]);

    // Second call with different length
    impacted_entries_into(&[1], &[0], &[0], &[0], 1, 1, &[0; 5], &mut out, &mut scratch);
    assert_eq!(out, vec![0, 0, 0, 0, 0]);
}