#![cfg(feature = "inference")]

use mimirs_encoding::SemanticEncoder;

#[tokio::test]
async fn test_alignment_pass() {
    // 1. Load encoder
    let encoder = SemanticEncoder::load_default().expect("Failed to load BERT");

    // 2. Encode text
    let text = "Quantum memory is stable.";
    let vec_raw = encoder.encode(text).expect("Failed to encode");
    assert!(!vec_raw.is_empty(), "Embedding should not be empty");

    // 3. Load a second encoder and verify deterministic output
    let encoder2 = SemanticEncoder::load_default().expect("Failed to reload BERT");
    let vec2 = encoder2.encode(text).expect("Failed to encode");

    // 4. Same encoder should produce same results
    for i in 0..vec_raw.len() {
        assert!(
            (vec_raw[i] - vec2[i]).abs() < 1e-5,
            "Same text should produce identical embeddings"
        );
    }

    // 5. Different text should produce different embeddings
    let vec_different = encoder
        .encode("Completely unrelated text about cooking")
        .expect("Failed to encode");
    let mut diff_sum = 0.0;
    for i in 0..vec_raw.len().min(vec_different.len()) {
        diff_sum += (vec_raw[i] - vec_different[i]).abs();
    }
    assert!(
        diff_sum > 0.1,
        "Different text should produce different embeddings (diff_sum={})",
        diff_sum
    );

    println!(
        "SemanticEncoder alignment pass verified! dim={}",
        vec_raw.len()
    );
}
