From 9254e08daa33b81caddbf219190bc0d8797888dd Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 24 Oct 2026 14:21:22 +0300 Subject: [PATCH] Ask improve_level for more than the test identity already has ts::identity::tests::improve_level_keeps_the_key made its identity with Identity::create(), which stops at the first counter whose level is 8 or more, and asked improve_level for 13. About one identity in 32 has 13 or more already, and improve_level then returns it as it is, so the assertion that the counter grew failed: 8 failures in 300 runs of the single test before this change, 0 in 300 after. The target is now three levels above what the identity has, so the search always runs. The assertions on the level, the callbacks and the counter use that target. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-core/src/ts/identity.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/voelin-core/src/ts/identity.rs b/crates/voelin-core/src/ts/identity.rs index b517a1b..8adbd9f 100644 --- a/crates/voelin-core/src/ts/identity.rs +++ b/crates/voelin-core/src/ts/identity.rs @@ -672,15 +672,19 @@ mod tests { #[test] fn improve_level_keeps_the_key() { let identity = synthetic(); + // A fresh identity stops at the first counter whose level is 8 or more, + // and about one in 32 has 13 or more already, which `improve_level` + // returns as it is: ask for more than this one has, whatever it has. + let target = identity.level() + 3; let levels = std::sync::Mutex::new(Vec::new()); - let better = improve_level(&identity, 13, &AtomicBool::new(false), |l| { + let better = improve_level(&identity, target, &AtomicBool::new(false), |l| { levels.lock().unwrap().push(l); }) .unwrap(); - assert!(better.level() >= 13); + assert!(better.level() >= target); assert_eq!(better.key().to_pub().get_uid(), identity.key().to_pub().get_uid()); assert!(better.counter() > identity.counter()); - assert!(levels.into_inner().unwrap().iter().any(|l| *l >= 13)); + assert!(levels.into_inner().unwrap().iter().any(|l| *l >= target)); // Cancelled: nothing. assert!(improve_level(&identity, 60, &AtomicBool::new(true), |_| {}).is_none()); // Already there: the same identity.