minerva 0.2.0

Causal ordering for distributed systems
extern crate alloc;

use crate::kairos::{Clock, Kairos, TickCounter, VirtualTimeSource};

#[test]
fn test_observe_advances_clock_without_minting() {
    // observe folds a remote in (the HLC receive rule) without returning a stamp
    // or a kairotic; the next `now` reflects it. A remote far ahead in physical
    // pulls the clock forward (recorded as forward skew), and the subsequent mint
    // strictly exceeds the remote while carrying this node's own identity.
    let clock = Clock::with_default_config(TickCounter::new(), 1).unwrap();
    let first = clock.now(0u16); // physical 0, logical 0
    let remote = Kairos::new(100, 7, 2, 10u16);
    clock.observe(remote);
    assert_eq!(
        clock.stats().max_forward_skew_ns,
        99,
        "observe pulls the clock forward to the remote's physical time"
    );
    let next = clock.now(0u16);
    assert!(
        next > remote,
        "a mint after observe exceeds the observed remote"
    );
    assert!(next > first);
    assert_eq!(
        next.physical(),
        100,
        "physical jumped to the observed remote"
    );
    assert_eq!(
        next.station_id(),
        1,
        "observe carries no identity; the mint is local"
    );
}

#[test]
fn test_observe_of_dominated_remote_still_advances() {
    // observe is a receive *event*: even a remote the clock already dominates ticks
    // logical, matching the HLC receive rule (and the receive half of `after`), not
    // an idempotent merge. So observe-then-now lands two ticks on, not one.
    let clock = Clock::with_default_config(VirtualTimeSource::new(0), 1).unwrap();
    let a = clock.now(0u16); // (0, 0)
    clock.observe(Kairos::new(0, 0, 2, 0u16)); // a stamp already dominated; ticks to (0, 1)
    let b = clock.now(0u16); // (0, 2)
    assert!(b > a);
    assert_eq!(
        b.logical(),
        2,
        "observe consumed a logical tick, so the next mint is two on, not one"
    );
}