guise 0.1.2

Canonical browser fingerprint bundles, human-behavior timing, and TLS profile re-exports for the Santh fleet
Documentation
use super::*;

#[test]
fn bundled_corpus_has_at_least_eight_traces() {
    // Less than this and the per-call sampler runs out of
    // diversity quickly - anti-bot ML can fingerprint 4-trace
    // corpora. 8 is the floor.
    assert!(bundled_corpus().len() >= 8);
}

#[test]
fn every_bundled_trace_terminates_at_unit_square() {
    for (i, t) in bundled_corpus().iter().enumerate() {
        let cumul = t.cumulative();
        let (x, y, _) = *cumul.last().unwrap();
        assert!(
            (x - 1.0).abs() < 1e-3,
            "trace #{i} ends at x={x}, expected 1.0"
        );
        assert!(
            (y - 1.0).abs() < 1e-3,
            "trace #{i} ends at y={y}, expected 1.0"
        );
    }
}

#[test]
fn every_bundled_trace_has_realistic_step_count() {
    // <8 steps = synthetic-bezier territory. >100 steps =
    // unrealistic 1000Hz sampling. Real corpora cluster
    // 10-50.
    for (i, t) in bundled_corpus().iter().enumerate() {
        assert!(
            (8..=100).contains(&t.steps.len()),
            "trace #{i} has {} steps (expect 8..=100)",
            t.steps.len()
        );
    }
}

#[test]
fn every_bundled_trace_has_realistic_inter_step_delay() {
    // Real pointing devices report at ~62-125 Hz (8-16 ms). We
    // allow up to 50ms for natural pause-and-think frames in
    // the long traces.
    for (i, t) in bundled_corpus().iter().enumerate() {
        for (j, s) in t.steps.iter().enumerate() {
            assert!(
                (5..=50).contains(&s.dt_ms),
                "trace #{i} step #{j} dt_ms = {} (expect 5..=50)",
                s.dt_ms
            );
        }
    }
}

#[test]
fn every_bundled_trace_has_natural_duration() {
    // Real-corpus durations span a wide range: fast deliberate
    // swipes can land at 100ms (8-12 step minimal-pause moves);
    // contemplative deliberation traces stretch to ~1500ms.
    // Bound 100..=1800 captures the realistic envelope. Below
    // 100ms is single-frame jitter dominated; above 1800ms is
    // outlier territory we shouldn't ship by default.
    for (i, t) in bundled_corpus().iter().enumerate() {
        let d = t.duration_ms();
        assert!(
            (100..=1800).contains(&d),
            "trace #{i} duration {d}ms (expect 100..=1800)"
        );
    }
}

#[test]
fn sampler_returns_a_trace_with_at_least_one_step() {
    let s = MouseSampler::new();
    let t = s.sample(100.0, 200.0, 400.0, 350.0);
    assert!(!t.steps.is_empty());
}

#[test]
fn sampler_lands_close_to_requested_end_coordinate() {
    let sampler = MouseSampler::new();
    // Run a handful of samples and check the cumulative end
    // lands within jitter tolerance of the requested (x1, y1).
    for _ in 0..20 {
        let t = sampler.sample(50.0, 50.0, 500.0, 400.0);
        let cumul = t.cumulative();
        let (end_x, end_y, _) = *cumul.last().unwrap();
        // Per-step jitter is ±2px, summed over up to 50 steps
        // = up to ±100px. Bound the tolerance at 100.
        let actual_end_x = 50.0 + end_x;
        let actual_end_y = 50.0 + end_y;
        assert!(
            (actual_end_x - 500.0).abs() < 100.0,
            "end_x = {actual_end_x}, expected ~500"
        );
        assert!(
            (actual_end_y - 400.0).abs() < 100.0,
            "end_y = {actual_end_y}, expected ~400"
        );
    }
}

#[test]
fn sampler_produces_distinct_paths_across_calls() {
    let sampler = MouseSampler::new();
    let a = sampler.sample(0.0, 0.0, 100.0, 100.0);
    let b = sampler.sample(0.0, 0.0, 100.0, 100.0);
    // Statistically should differ (random trace pick + jitter).
    // Equal coordinate sequences would mean either RNG is
    // broken or the corpus has only one trace.
    assert!(
        a.steps != b.steps,
        "two consecutive samples produced identical paths - sampler RNG broken?"
    );
}

#[test]
fn extra_traces_are_added_to_corpus() {
    let s = MouseSampler::new().with_extra_traces(vec![Trace {
        steps: vec![Step {
            dx: 1.0,
            dy: 1.0,
            dt_ms: 100,
        }],
    }]);
    assert!(s.corpus().len() >= 9);
}

#[test]
fn cumulative_starts_at_origin() {
    let t = Trace {
        steps: vec![Step {
            dx: 0.5,
            dy: 0.5,
            dt_ms: 100,
        }],
    };
    let cumul = t.cumulative();
    assert_eq!(cumul[0], (0.0, 0.0, 0));
}

#[test]
fn arc_length_sums_step_distances() {
    // 3-4-5 triangle steps → arc length = 5 + 5 = 10.
    let t = Trace {
        steps: vec![
            Step {
                dx: 3.0,
                dy: 4.0,
                dt_ms: 10,
            },
            Step {
                dx: -3.0,
                dy: -4.0,
                dt_ms: 10,
            },
        ],
    };
    assert!((t.arc_length() - 10.0).abs() < 1e-5);
}

#[test]
fn duration_ms_is_zero_for_empty_trace() {
    let t = Trace { steps: vec![] };
    assert_eq!(t.duration_ms(), 0);
}

#[test]
fn affine_transform_handles_zero_length_normalised_trace_gracefully() {
    // Edge case: a trace whose cumulative end is (0, 0) - the
    // transform must not divide by zero.
    let trace = Trace {
        steps: vec![
            Step {
                dx: 0.5,
                dy: 0.5,
                dt_ms: 10,
            },
            Step {
                dx: -0.5,
                dy: -0.5,
                dt_ms: 10,
            },
        ],
    };
    let mut rng = rand::rngs::StdRng::from_entropy_via_thread_local();
    let out = affine_transform_with_jitter(&trace, (0.0, 0.0), (100.0, 100.0), &mut rng);
    assert_eq!(out.steps.len(), 2);
}