MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_session_event_key_ordering

Function test_session_event_key_ordering

atomic-core/src/change/session.rs:785–813  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

783
784 #[test]
785 fn test_session_event_key_ordering() {
786 // Keys for the same provenance_id must sort by seq in lexicographic
787 // (B-tree) order across the full u64 range. Big-endian encoding
788 // guarantees this: the most-significant byte comes first, so byte-wise
789 // comparison matches numeric comparison for all values.
790 let k1 = encode_session_event_key(5, 0);
791 let k2 = encode_session_event_key(5, 1);
792 let k3 = encode_session_event_key(5, 100);
793 let k4 = encode_session_event_key(6, 0);
794
795 assert!(k1 < k2);
796 assert!(k2 < k3);
797 assert!(k3 < k4, "different provenance_id sorts after");
798
799 // Boundary: seq=255 (single-byte max) vs seq=256 (spills into second byte).
800 // With big-endian encoding this must sort correctly.
801 let k_255 = encode_session_event_key(5, 255);
802 let k_256 = encode_session_event_key(5, 256);
803 assert!(
804 k_255 < k_256,
805 "seq=255 must sort before seq=256 (byte-spill boundary)"
806 );
807
808 // seq=256 on provenance_id=5 must still sort before provenance_id=6.
809 assert!(
810 k_256 < k4,
811 "seq=256 on provenance_id=5 must sort before provenance_id=6"
812 );
813 }
814
815 #[test]
816 fn test_session_todo_key_deterministic() {

Callers

nothing calls this directly

Calls 1

encode_session_event_keyFunction · 0.85

Tested by

no test coverage detected