diff --git a/crates/aingle_ai/src/ineru/config.rs b/crates/aingle_ai/src/ineru/config.rs index b884d75e..779e8cff 100644 --- a/crates/aingle_ai/src/ineru/config.rs +++ b/crates/aingle_ai/src/ineru/config.rs @@ -135,12 +135,16 @@ mod tests { #[test] fn test_validation() { - let mut config = IneruConfig::default(); - config.window_size = 0; + let config = IneruConfig { + window_size: 0, + ..Default::default() + }; assert!(config.validate().is_err()); - config = IneruConfig::default(); - config.surprise_threshold = 1.5; + let config = IneruConfig { + surprise_threshold: 1.5, + ..Default::default() + }; assert!(config.validate().is_err()); } diff --git a/crates/aingle_ai/src/kaneru/continuum_memory.rs b/crates/aingle_ai/src/kaneru/continuum_memory.rs index 4104c47e..828131fe 100644 --- a/crates/aingle_ai/src/kaneru/continuum_memory.rs +++ b/crates/aingle_ai/src/kaneru/continuum_memory.rs @@ -5,6 +5,8 @@ //! //! Non-discrete memory system with smooth interpolation. +use std::cmp::Reverse; + use super::{Experience, MemoryResult, Query}; use crate::types::{pattern_id, Embedding}; @@ -123,8 +125,7 @@ impl ContinuumMemory { pub fn compress(&mut self) { // Keep only top half by access count if self.entries.len() > 100 { - self.entries - .sort_by(|a, b| b.access_count.cmp(&a.access_count)); + self.entries.sort_by_key(|e| Reverse(e.access_count)); self.entries.truncate(self.entries.len() / 2); } } diff --git a/crates/aingle_ai/src/kaneru/mod.rs b/crates/aingle_ai/src/kaneru/mod.rs index 22b90603..ec2f073f 100644 --- a/crates/aingle_ai/src/kaneru/mod.rs +++ b/crates/aingle_ai/src/kaneru/mod.rs @@ -423,8 +423,10 @@ mod tests { }; let result = agent.query(&query); - // Should have some results - assert!(result.relevant_contexts.len() > 0 || result.memory_matches.len() >= 0); + // Should have some results. The second half used to read + // `memory_matches.len() >= 0`, which is true for every usize — so the + // assertion passed even when the query returned nothing at all. + assert!(!result.relevant_contexts.is_empty() || !result.memory_matches.is_empty()); } #[test] diff --git a/crates/aingle_ai/src/kaneru/self_modifier.rs b/crates/aingle_ai/src/kaneru/self_modifier.rs index 2200b30b..1489eaf4 100644 --- a/crates/aingle_ai/src/kaneru/self_modifier.rs +++ b/crates/aingle_ai/src/kaneru/self_modifier.rs @@ -359,8 +359,10 @@ mod tests { #[test] fn test_rule_evolution() { - let mut config = KaneruConfig::default(); - config.max_rules = 10; + let config = KaneruConfig { + max_rules: 10, + ..Default::default() + }; let mut modifier = SelfModifier::new(&config); // Simulate good outcomes to trigger rule creation diff --git a/crates/aingle_ai/src/nested_learning/mod.rs b/crates/aingle_ai/src/nested_learning/mod.rs index d661db94..7021b764 100644 --- a/crates/aingle_ai/src/nested_learning/mod.rs +++ b/crates/aingle_ai/src/nested_learning/mod.rs @@ -259,7 +259,7 @@ mod tests { let tx = make_test_tx(1); let result = nested.process(&tx).unwrap(); - assert!(result.processed.features.len() > 0); + assert!(!result.processed.features.is_empty()); } #[test] @@ -267,7 +267,7 @@ mod tests { let config = NestedConfig::default(); let nested = NestedLearning::new(config); - let batch: Vec<_> = (0..10).map(|i| make_test_tx(i)).collect(); + let batch: Vec<_> = (0..10).map(make_test_tx).collect(); let plan = nested.get_validation_plan(&batch); assert_eq!(plan.order.len(), 10); @@ -275,8 +275,11 @@ mod tests { #[test] fn test_meta_level_update() { - let mut config = NestedConfig::default(); - config.meta_update_interval = 5; // Update every 5 blocks + // Update every 5 blocks + let config = NestedConfig { + meta_update_interval: 5, + ..Default::default() + }; let mut nested = NestedLearning::new(config); let stats = BlockStats::default(); diff --git a/crates/aingle_ai/src/nested_learning/transaction_level.rs b/crates/aingle_ai/src/nested_learning/transaction_level.rs index fd38a931..59d14ed0 100644 --- a/crates/aingle_ai/src/nested_learning/transaction_level.rs +++ b/crates/aingle_ai/src/nested_learning/transaction_level.rs @@ -294,7 +294,7 @@ mod tests { // Process and update let tx = make_tx(1); - let processed = tl.process(tx.clone()); + let _processed = tl.process(tx.clone()); let outcome = ValidationOutcome { valid: true, diff --git a/crates/aingle_ai/src/types.rs b/crates/aingle_ai/src/types.rs index 502a3d3f..645e58a4 100644 --- a/crates/aingle_ai/src/types.rs +++ b/crates/aingle_ai/src/types.rs @@ -174,8 +174,8 @@ impl AiTransaction { // Entry type hash features (first 4 bytes as float) let type_hash = pattern_id(self.entry_type.as_bytes()); - for i in 0..4 { - features.push(type_hash[i] as f32 / 255.0); + for byte in type_hash.iter().take(4) { + features.push(*byte as f32 / 255.0); } // Agent features (first 4 bytes) @@ -287,6 +287,6 @@ mod tests { let features = tx.extract_features(); assert_eq!(features.len(), 16); - assert!(features.iter().all(|&f| f >= 0.0 && f <= 2.0)); + assert!(features.iter().all(|&f| (0.0..=2.0).contains(&f))); } } diff --git a/crates/aingle_contracts/src/contract.rs b/crates/aingle_contracts/src/contract.rs index bb437e1c..3739df7e 100644 --- a/crates/aingle_contracts/src/contract.rs +++ b/crates/aingle_contracts/src/contract.rs @@ -13,11 +13,12 @@ use crate::error::{ContractError, Result}; use crate::types::{Address, ContractId}; /// Function visibility/mutability -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] pub enum FunctionType { /// Read-only function (view) View, /// State-mutating function + #[default] Mutate, /// Payable function (can receive value) Payable, @@ -27,12 +28,6 @@ pub enum FunctionType { Constructor, } -impl Default for FunctionType { - fn default() -> Self { - Self::Mutate - } -} - /// Contract function definition #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ContractFunction { diff --git a/crates/aingle_contracts/src/types.rs b/crates/aingle_contracts/src/types.rs index cc7f6b24..0fcc3b1a 100644 --- a/crates/aingle_contracts/src/types.rs +++ b/crates/aingle_contracts/src/types.rs @@ -46,7 +46,7 @@ impl Address { hasher.update(b"aingle_deploy:"); hasher.update(deployer.as_bytes()); hasher.update(code_hash); - hasher.update(&nonce); + hasher.update(nonce); let hash: [u8; 32] = hasher.finalize().into(); Self(hash) } diff --git a/crates/aingle_cortex/src/cluster_init.rs b/crates/aingle_cortex/src/cluster_init.rs index 2486d014..36f5342e 100644 --- a/crates/aingle_cortex/src/cluster_init.rs +++ b/crates/aingle_cortex/src/cluster_init.rs @@ -103,11 +103,9 @@ impl ClusterConfig { i += 1; } } - "--cluster-tls-key" => { - if i + 1 < args.len() { - cfg.tls_key = Some(args[i + 1].clone()); - i += 1; - } + "--cluster-tls-key" if i + 1 < args.len() => { + cfg.tls_key = Some(args[i + 1].clone()); + i += 1; } _ => {} } @@ -406,7 +404,7 @@ pub async fn ensure_dag_ready(state: &mut crate::state::AppState, db_path: Optio // Set DAG author from cluster node ID (no-op when not in cluster mode). if let Some(node_id) = state.cluster_node_id { - state.dag_author = Some(aingle_graph::NodeId::named(&format!("node:{}", node_id))); + state.dag_author = Some(aingle_graph::NodeId::named(format!("node:{}", node_id))); } // Initialize the Ed25519 signing key for DAG actions. @@ -459,7 +457,7 @@ pub async fn ensure_dag_ready(state: &mut crate::state::AppState, db_path: Optio } #[cfg(not(unix))] { - if let Err(e) = std::fs::write(&key_path, &seed) { + if let Err(e) = std::fs::write(&key_path, seed) { tracing::error!("Failed to persist DAG signing key: {e}"); } } @@ -496,7 +494,7 @@ pub async fn init_cluster( bind_addr: &str, p2p_addr: &str, ) -> Result<(), Error> { - config.validate().map_err(|e| Error::Internal(e))?; + config.validate().map_err(Error::Internal)?; let wal_dir = config.wal_dir.as_deref().unwrap_or("wal"); let wal_path = std::path::Path::new(wal_dir); diff --git a/crates/aingle_cortex/src/p2p/config.rs b/crates/aingle_cortex/src/p2p/config.rs index c44da9f4..56cb94ee 100644 --- a/crates/aingle_cortex/src/p2p/config.rs +++ b/crates/aingle_cortex/src/p2p/config.rs @@ -114,13 +114,11 @@ impl P2pConfig { i += 1; } } - "--p2p-peer" => { - if i + 1 < args.len() { - if let Ok(addr) = args[i + 1].parse::() { - cfg.manual_peers.push(addr); - } - i += 1; + "--p2p-peer" if i + 1 < args.len() => { + if let Ok(addr) = args[i + 1].parse::() { + cfg.manual_peers.push(addr); } + i += 1; } _ => {} } diff --git a/crates/aingle_cortex/src/p2p/dag_sync.rs b/crates/aingle_cortex/src/p2p/dag_sync.rs index f5f6b0fa..7f9df964 100644 --- a/crates/aingle_cortex/src/p2p/dag_sync.rs +++ b/crates/aingle_cortex/src/p2p/dag_sync.rs @@ -19,7 +19,7 @@ pub fn collect_local_tips(graph: &GraphDB) -> (Vec, u64) { .tips_raw() .unwrap_or_default() .into_iter() - .map(|h| hex::encode(h)) + .map(hex::encode) .collect::>(); let count = dag_store.action_count() as u64; (tips, count) diff --git a/crates/aingle_cortex/src/proofs/store.rs b/crates/aingle_cortex/src/proofs/store.rs index 2bb6eb34..4ff1283e 100644 --- a/crates/aingle_cortex/src/proofs/store.rs +++ b/crates/aingle_cortex/src/proofs/store.rs @@ -282,7 +282,7 @@ impl ProofStore { .map_err(|e| VerificationError::InvalidProofData(e.to_string()))?; self.backend .put(&proof_id, &serialized) - .map_err(|e| VerificationError::InvalidProofData(e))?; + .map_err(VerificationError::InvalidProofData)?; // Update stats let mut stats = self.stats.write().await; diff --git a/crates/aingle_cortex/src/rest/audit.rs b/crates/aingle_cortex/src/rest/audit.rs index 2856ebd9..3f6a8e66 100644 --- a/crates/aingle_cortex/src/rest/audit.rs +++ b/crates/aingle_cortex/src/rest/audit.rs @@ -63,11 +63,9 @@ impl AuditLog { // Read existing entries from JSONL file if let Ok(file) = std::fs::File::open(&path) { let reader = std::io::BufReader::new(file); - for line in reader.lines() { - if let Ok(line) = line { - if let Ok(entry) = serde_json::from_str::(&line) { - entries.push(entry); - } + for line in reader.lines().flatten() { + if let Ok(entry) = serde_json::from_str::(&line) { + entries.push(entry); } } // Keep only the last max_entries diff --git a/crates/aingle_cortex/src/rest/proof_api.rs b/crates/aingle_cortex/src/rest/proof_api.rs index 711aca50..daf030df 100644 --- a/crates/aingle_cortex/src/rest/proof_api.rs +++ b/crates/aingle_cortex/src/rest/proof_api.rs @@ -124,7 +124,7 @@ pub async fn verify_proofs_batch( let results = state.proof_store.batch_verify(&request.proof_ids).await; let mut verifications = Vec::new(); - for (proof_id, result) in request.proof_ids.iter().zip(results.into_iter()) { + for (proof_id, result) in request.proof_ids.iter().zip(results) { // Every entry carries its own replay material: a batch verdict is no more // authoritative than a single one, so it must not be the only thing a // caller can act on. diff --git a/crates/aingle_cortex/src/rest/triples.rs b/crates/aingle_cortex/src/rest/triples.rs index 342b0006..d8a3972f 100644 --- a/crates/aingle_cortex/src/rest/triples.rs +++ b/crates/aingle_cortex/src/rest/triples.rs @@ -178,7 +178,7 @@ pub async fn create_triple( #[cfg(feature = "dag")] if let Some(ref raft) = state.raft { let dag_author = state.dag_author.clone().unwrap_or_else(|| { - aingle_graph::NodeId::named(&format!("node:{}", state.cluster_node_id.unwrap_or(0))) + aingle_graph::NodeId::named(format!("node:{}", state.cluster_node_id.unwrap_or(0))) }); // Get current tips, and a sequence number that continues this author's // recorded chain rather than restarting at 1 and evicting its own history @@ -457,7 +457,7 @@ pub async fn delete_triple( #[cfg(feature = "dag")] if let Some(ref raft) = state.raft { let dag_author = state.dag_author.clone().unwrap_or_else(|| { - aingle_graph::NodeId::named(&format!("node:{}", state.cluster_node_id.unwrap_or(0))) + aingle_graph::NodeId::named(format!("node:{}", state.cluster_node_id.unwrap_or(0))) }); let (parents, subject_for_dag, dag_seq) = { let graph = state.graph.read().await; diff --git a/crates/aingle_cortex/tests/data_integrity_test.rs b/crates/aingle_cortex/tests/data_integrity_test.rs index 70ddb0a7..0a3c6b67 100644 --- a/crates/aingle_cortex/tests/data_integrity_test.rs +++ b/crates/aingle_cortex/tests/data_integrity_test.rs @@ -139,7 +139,7 @@ async fn test_graph_dag_triple_materialization_consistency() { let mut triple_ids = Vec::new(); for i in 0..50 { let triple = Triple::new( - NodeId::named(&format!("entity:{}", i)), + NodeId::named(format!("entity:{}", i)), Predicate::named("has_value"), Value::Integer(i * 100), ); @@ -166,7 +166,7 @@ async fn test_graph_dag_triple_materialization_consistency() { // Verify pattern queries return correct results for i in 0..50 { - let pattern = TriplePattern::subject(NodeId::named(&format!("entity:{}", i))); + let pattern = TriplePattern::subject(NodeId::named(format!("entity:{}", i))); let results = graph.find(pattern).unwrap(); assert_eq!( results.len(), @@ -209,7 +209,7 @@ async fn test_batch_insert_index_consistency() { let triples: Vec = (0..100) .map(|i| { Triple::new( - NodeId::named(&format!("batch:{}", i)), + NodeId::named(format!("batch:{}", i)), Predicate::named("batch_value"), Value::Integer(i), ) @@ -222,7 +222,7 @@ async fn test_batch_insert_index_consistency() { // Verify every triple is findable by subject pattern (uses SPO index) for i in 0..100 { - let pattern = TriplePattern::subject(NodeId::named(&format!("batch:{}", i))); + let pattern = TriplePattern::subject(NodeId::named(format!("batch:{}", i))); let results = graph.find(pattern).unwrap(); assert_eq!(results.len(), 1, "batch:{} should be findable via index", i); assert_eq!(results[0].object, Value::Integer(i)); @@ -238,7 +238,7 @@ async fn test_batch_insert_index_consistency() { let triples2: Vec = (0..100) .map(|i| { Triple::new( - NodeId::named(&format!("batch:{}", i)), + NodeId::named(format!("batch:{}", i)), Predicate::named("batch_value"), Value::Integer(i), ) @@ -270,7 +270,7 @@ async fn test_app_state_flush_restore_roundtrip() { let graph = state.graph.read().await; for i in 0..10 { let triple = Triple::new( - NodeId::named(&format!("node:{}", i)), + NodeId::named(format!("node:{}", i)), Predicate::named("value"), Value::String(format!("data-{}", i)), ); @@ -308,7 +308,7 @@ async fn test_app_state_flush_restore_roundtrip() { assert_eq!(graph.count(), 10, "graph triples should survive restart"); for i in 0..10 { - let pattern = TriplePattern::subject(NodeId::named(&format!("node:{}", i))); + let pattern = TriplePattern::subject(NodeId::named(format!("node:{}", i))); let results = graph.find(pattern).unwrap(); assert_eq!(results.len(), 1, "node:{} missing after restart", i); assert_eq!( @@ -496,7 +496,7 @@ async fn test_graph_sled_persistence_full_cycle() { let graph = GraphDB::sled(path_str).unwrap(); for i in 0..25 { let triple = Triple::new( - NodeId::named(&format!("persist:{}", i)), + NodeId::named(format!("persist:{}", i)), Predicate::named("data"), Value::Float(i as f64 * 1.5), ); @@ -512,7 +512,7 @@ async fn test_graph_sled_persistence_full_cycle() { assert_eq!(graph.count(), 25, "sled graph should persist"); for i in 0..25 { - let pattern = TriplePattern::subject(NodeId::named(&format!("persist:{}", i))); + let pattern = TriplePattern::subject(NodeId::named(format!("persist:{}", i))); let results = graph.find(pattern).unwrap(); assert_eq!(results.len(), 1, "persist:{} missing", i); match &results[0].object { diff --git a/crates/aingle_cortex/tests/rate_limiting_test.rs b/crates/aingle_cortex/tests/rate_limiting_test.rs index 19687210..a18c8972 100644 --- a/crates/aingle_cortex/tests/rate_limiting_test.rs +++ b/crates/aingle_cortex/tests/rate_limiting_test.rs @@ -281,7 +281,7 @@ async fn test_rate_limiter_gradual_refill() { // Should have succeeded ~3 times (with some tolerance for timing) assert!( - successes >= 2 && successes <= 4, + (2..=4).contains(&successes), "Should refill approximately 3 tokens, got {}", successes ); diff --git a/crates/aingle_graph/src/dag/mod.rs b/crates/aingle_graph/src/dag/mod.rs index 50da412d..970d8ee9 100644 --- a/crates/aingle_graph/src/dag/mod.rs +++ b/crates/aingle_graph/src/dag/mod.rs @@ -29,12 +29,10 @@ pub mod tips; pub use action::{ DagAction, DagActionHash, DagPayload, MemoryOpKind, Provenance, TripleInsertPayload, }; -pub use canonical::{ - CanonicalAction, CANONICAL_SPEC, HASH_ALG, SIGNATURE_ALG, SIGNED_MESSAGE, -}; #[cfg(feature = "sled-backend")] pub use backend::SledDagBackend; pub use backend::{DagBackend, MemoryDagBackend}; +pub use canonical::{CanonicalAction, CANONICAL_SPEC, HASH_ALG, SIGNATURE_ALG, SIGNED_MESSAGE}; pub use export::{DagGraph, ExportFormat}; pub use pruning::{PruneResult, RetentionPolicy}; #[cfg(feature = "dag-sign")] diff --git a/crates/aingle_graph/src/dag/store.rs b/crates/aingle_graph/src/dag/store.rs index b32ea183..b430cd02 100644 --- a/crates/aingle_graph/src/dag/store.rs +++ b/crates/aingle_graph/src/dag/store.rs @@ -7,6 +7,8 @@ //! In-memory indexes (author chain, affected triples) are rebuilt on startup //! from the backend, ensuring zero data loss across restarts. +use std::cmp::Reverse; + use super::action::{DagAction, DagActionHash, DagPayload, TripleInsertPayload}; use super::backend::DagBackend; use super::pruning::{PruneResult, RetentionPolicy}; @@ -369,7 +371,7 @@ impl DagStore { .collect(); // Sort by seq descending (most recent first) - entries.sort_by(|a, b| b.0.cmp(&a.0)); + entries.sort_by_key(|e| Reverse(e.0)); entries.truncate(limit); drop(idx); @@ -407,7 +409,7 @@ impl DagStore { } // Sort by timestamp descending - result.sort_by(|a, b| b.timestamp.cmp(&a.timestamp)); + result.sort_by_key(|a| Reverse(a.timestamp)); result.truncate(limit); Ok(result) @@ -440,7 +442,7 @@ impl DagStore { } } - result.sort_by(|a, b| b.timestamp.cmp(&a.timestamp)); + result.sort_by_key(|a| Reverse(a.timestamp)); result.truncate(limit); Ok(result) @@ -713,10 +715,10 @@ impl DagStore { hash.copy_from_slice(&key[2..]); if let Some(action) = DagAction::from_bytes(value) { - if action.timestamp <= *ts { - if best.as_ref().map_or(true, |(_, t)| action.timestamp > *t) { - best = Some((DagActionHash(hash), action.timestamp)); - } + if action.timestamp <= *ts + && best.as_ref().is_none_or(|(_, t)| action.timestamp > *t) + { + best = Some((DagActionHash(hash), action.timestamp)); } } } @@ -1044,10 +1046,9 @@ fn topo_sort(mut collected: HashMap<[u8; 32], DagAction>) -> crate::Result Vec<[u8; 32]> { match payload { - DagPayload::TripleInsert { triples } => triples - .iter() - .map(|t| compute_triple_id_from_payload(t)) - .collect(), + DagPayload::TripleInsert { triples } => { + triples.iter().map(compute_triple_id_from_payload).collect() + } DagPayload::TripleDelete { triple_ids, .. } => triple_ids.clone(), DagPayload::Batch { ops } => ops.iter().flat_map(extract_affected_triple_ids).collect(), _ => vec![], diff --git a/crates/aingle_graph/src/dag/timetravel.rs b/crates/aingle_graph/src/dag/timetravel.rs index 95abfb82..152885a5 100644 --- a/crates/aingle_graph/src/dag/timetravel.rs +++ b/crates/aingle_graph/src/dag/timetravel.rs @@ -49,6 +49,7 @@ pub struct DagDiff { /// Errors from individual insert/delete operations are intentionally ignored: /// - Duplicate inserts are expected (same triple in multiple actions). /// - Deletes of already-deleted triples are expected after pruning. +/// /// These are not failures — they're inherent to replaying a DAG. pub(crate) fn replay_payload(db: &crate::GraphDB, payload: &DagPayload) -> crate::Result<()> { match payload { diff --git a/crates/aingle_graph/src/lib.rs b/crates/aingle_graph/src/lib.rs index ebfa4bfe..ef60a331 100644 --- a/crates/aingle_graph/src/lib.rs +++ b/crates/aingle_graph/src/lib.rs @@ -1108,10 +1108,8 @@ impl GraphDB { let mut deleted = 0usize; for triple in all { if let Some(name) = triple.subject.as_name() { - if name.starts_with(prefix) { - if self.delete(&triple.id())? { - deleted += 1; - } + if name.starts_with(prefix) && self.delete(&triple.id())? { + deleted += 1; } } } @@ -1456,7 +1454,7 @@ mod tests { for i in 0..10 { db.insert(Triple::new( - NodeId::named(&format!("node:{}", i)), + NodeId::named(format!("node:{}", i)), Predicate::named("has_value"), Value::integer(i as i64), )) @@ -1808,7 +1806,7 @@ mod tests { // DAG has one action let action = db.dag_action(&dag_hash).unwrap().unwrap(); assert_eq!(action.seq, 1); - assert!(action.is_genesis() == false || action.parents.is_empty()); + assert!(!action.is_genesis() || action.parents.is_empty()); // Tips point to the new action let tips = db.dag_tips().unwrap(); @@ -1874,7 +1872,7 @@ mod tests { for seq in 1..=5 { let triple = Triple::new( - NodeId::named(&format!("node:{}", seq)), + NodeId::named(format!("node:{}", seq)), Predicate::named("p"), Value::integer(seq), ); diff --git a/crates/aingle_graph/src/value.rs b/crates/aingle_graph/src/value.rs index dfa8836f..d948c28b 100644 --- a/crates/aingle_graph/src/value.rs +++ b/crates/aingle_graph/src/value.rs @@ -481,8 +481,8 @@ mod tests { let int_val = Value::integer(42); assert_eq!(int_val.as_integer(), Some(42)); - let float_val = Value::float(3.14); - assert_eq!(float_val.as_float(), Some(3.14)); + let float_val = Value::float(2.5); + assert_eq!(float_val.as_float(), Some(2.5)); } #[test] diff --git a/crates/aingle_graph/tests/graph_integration_tests.rs b/crates/aingle_graph/tests/graph_integration_tests.rs index 56860125..355e4600 100644 --- a/crates/aingle_graph/tests/graph_integration_tests.rs +++ b/crates/aingle_graph/tests/graph_integration_tests.rs @@ -152,7 +152,7 @@ fn test_batch_insertion_large() { let triples: Vec = (0..100) .map(|i| { Triple::new( - NodeId::named(&format!("node:{}", i)), + NodeId::named(format!("node:{}", i)), Predicate::named("has_id"), Value::integer(i as i64), ) @@ -247,7 +247,7 @@ fn test_query_with_limit() { // Insert 10 triples for i in 0..10 { db.insert(Triple::new( - NodeId::named(&format!("node:{}", i)), + NodeId::named(format!("node:{}", i)), Predicate::named("type"), Value::literal("test"), )) @@ -581,7 +581,7 @@ fn test_different_value_types() { db.insert(Triple::new( NodeId::named("node:1"), Predicate::named("float_val"), - Value::float(3.14), + Value::float(2.5), )) .unwrap(); diff --git a/crates/aingle_ingest/src/chunk.rs b/crates/aingle_ingest/src/chunk.rs index dc540327..b79f71f4 100644 --- a/crates/aingle_ingest/src/chunk.rs +++ b/crates/aingle_ingest/src/chunk.rs @@ -188,10 +188,7 @@ mod tests { // 50 lines that are each ~1KB: a full 50-line window would exceed the // cap, so the window must close early on the byte budget. let one = "a".repeat(1024); - let content = std::iter::repeat(one) - .take(50) - .collect::>() - .join("\n"); + let content = std::iter::repeat_n(one, 50).collect::>().join("\n"); let chunks = chunk_fixed("data.txt", &content, "h", 50); assert!( @@ -240,7 +237,7 @@ mod tests { // Regression: a small markdown note splits by heading into one chunk per // section, none of them byte-split. let content = "# A\n\nalpha\n\n# B\n\nbeta\n"; - let chunks = chunk_markdown("n.md", &content, "h"); + let chunks = chunk_markdown("n.md", content, "h"); assert_eq!(chunks.len(), 2); assert!(chunks[0].text.contains("alpha")); diff --git a/crates/aingle_minimal/src/config.rs b/crates/aingle_minimal/src/config.rs index 94459c36..dc5a6e75 100644 --- a/crates/aingle_minimal/src/config.rs +++ b/crates/aingle_minimal/src/config.rs @@ -44,7 +44,7 @@ use std::time::Duration; /// let mut config = Config::test_mode(); /// config.power_mode = PowerMode::Low; /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] pub enum PowerMode { /// Full performance with no power-saving measures. /// @@ -54,6 +54,7 @@ pub enum PowerMode { /// A balance between performance and power consumption. /// /// This is the default mode, suitable for most use cases. + #[default] Balanced, /// Prioritizes low power usage by reducing activity. /// @@ -65,12 +66,6 @@ pub enum PowerMode { Critical, } -impl Default for PowerMode { - fn default() -> Self { - Self::Balanced - } -} - /// Defines the network transport to be used by the node. /// /// Different transports are optimized for different environments. CoAP is ideal @@ -321,12 +316,14 @@ impl GossipConfig { /// ``` #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] +#[derive(Default)] pub enum StorageBackendType { /// Use SQLite for storage. /// /// SQLite is a lightweight, single-file database that's ideal for IoT devices /// and embedded systems. It has minimal dependencies and works well on /// resource-constrained platforms. + #[default] Sqlite, /// Use RocksDB for storage. /// @@ -341,13 +338,6 @@ pub enum StorageBackendType { Memory, } -impl Default for StorageBackendType { - fn default() -> Self { - // SQLite is the default for IoT compatibility. - Self::Sqlite - } -} - impl std::fmt::Display for StorageBackendType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -1027,8 +1017,11 @@ mod tests { #[test] fn test_config_validate_invalid_memory() { - let mut config = Config::default(); - config.memory_limit = 100; // Too small + // Too small + let config = Config { + memory_limit: 100, + ..Default::default() + }; assert!(config.validate().is_err()); } diff --git a/crates/aingle_minimal/src/error.rs b/crates/aingle_minimal/src/error.rs index 4a3249ed..c20f2355 100644 --- a/crates/aingle_minimal/src/error.rs +++ b/crates/aingle_minimal/src/error.rs @@ -740,7 +740,7 @@ mod tests { let _: &dyn StdError = &error; // Test source() for Io error - let io_err = std::io::Error::new(std::io::ErrorKind::Other, "test"); + let io_err = std::io::Error::other("test"); let error = Error::Io(io_err); assert!(StdError::source(&error).is_some()); } diff --git a/crates/aingle_minimal/src/network.rs b/crates/aingle_minimal/src/network.rs index a2d31677..15fd7e1d 100644 --- a/crates/aingle_minimal/src/network.rs +++ b/crates/aingle_minimal/src/network.rs @@ -12,6 +12,8 @@ //! - **QUIC**: Future support for reliable transport //! - **Mesh**: Future support for mesh networking +use std::cmp::Reverse; + use crate::config::{GossipConfig, TransportConfig}; use crate::discovery::Discovery; use crate::error::{Error, Result}; @@ -565,7 +567,7 @@ impl Network { /// Get peers for gossip (best quality first) pub fn gossip_peers(&self) -> Vec { let mut peers: Vec<_> = self.active_peers().into_iter().collect(); - peers.sort_by(|a, b| b.quality.cmp(&a.quality)); + peers.sort_by_key(|p| Reverse(p.quality)); peers .into_iter() .take(self.gossip_config.max_peers) @@ -905,8 +907,10 @@ mod tests { #[test] fn test_gossip_timing() { - let mut config = GossipConfig::default(); - config.loop_delay = Duration::from_millis(10); + let config = GossipConfig { + loop_delay: Duration::from_millis(10), + ..Default::default() + }; let mut gossip = GossipManager::new(config); assert!(!gossip.should_gossip()); // Just created @@ -1166,8 +1170,10 @@ mod tests { #[test] fn test_network_gossip_peers_sorting() { let config = TransportConfig::Memory; - let mut gossip = GossipConfig::default(); - gossip.max_peers = 10; + let gossip = GossipConfig { + max_peers: 10, + ..Default::default() + }; let mut network = Network::new(config, gossip, "test-node".to_string()); // Add multiple peers @@ -1189,8 +1195,10 @@ mod tests { #[test] fn test_network_gossip_peers_limited() { let config = TransportConfig::Memory; - let mut gossip = GossipConfig::default(); - gossip.max_peers = 2; + let gossip = GossipConfig { + max_peers: 2, + ..Default::default() + }; let mut network = Network::new(config, gossip, "test-node".to_string()); // Add more peers than limit @@ -1260,8 +1268,10 @@ mod tests { #[test] fn test_gossip_manager_complete_failure() { - let mut config = GossipConfig::default(); - config.loop_delay = Duration::from_millis(10); + let config = GossipConfig { + loop_delay: Duration::from_millis(10), + ..Default::default() + }; let mut manager = GossipManager::new(config); @@ -1589,9 +1599,11 @@ mod tests { #[test] fn test_gossip_manager_config() { - let mut config = GossipConfig::default(); - config.loop_delay = Duration::from_millis(100); - config.max_peers = 5; + let config = GossipConfig { + loop_delay: Duration::from_millis(100), + max_peers: 5, + ..Default::default() + }; let manager = GossipManager::new(config.clone()); diff --git a/crates/aingle_minimal/src/node.rs b/crates/aingle_minimal/src/node.rs index 6b9e4b18..3bef02a1 100644 --- a/crates/aingle_minimal/src/node.rs +++ b/crates/aingle_minimal/src/node.rs @@ -1037,9 +1037,11 @@ mod tests { let addr: std::net::SocketAddr = "192.168.1.100:5683".parse().unwrap(); node.add_peer(addr); - // Verify peer was added via stats + // Verify peer was added via stats. `peer_count` is unsigned, so the + // old `>= 0` here held for every possible value including "nothing was + // added" — the one outcome this test exists to rule out. let stats = node.stats().unwrap(); - assert!(stats.peer_count >= 0); // At least no error + assert_eq!(stats.peer_count, 1); } #[test] @@ -1052,9 +1054,9 @@ mod tests { node.add_peer("192.168.1.101:5683".parse().unwrap()); node.add_peer("192.168.1.102:5683".parse().unwrap()); - // Stats should work + // Stats should work, and report all three. let stats = node.stats().unwrap(); - assert!(stats.peer_count >= 0); + assert_eq!(stats.peer_count, 3); } #[test] @@ -1126,9 +1128,11 @@ mod tests { // Sleep a bit to ensure uptime is measurable std::thread::sleep(std::time::Duration::from_millis(10)); - let stats = node.stats().unwrap(); - // Uptime should be at least 0 (could be 0 if very fast) - assert!(stats.uptime_secs >= 0); + // Uptime is whole seconds, so a node this young legitimately reports 0 + // and there is no lower bound to assert: `>= 0` on a u64 was always + // true. What this test does establish is that `stats()` succeeds on a + // freshly started node, which is the `unwrap` below. + let _stats = node.stats().unwrap(); } #[test] diff --git a/crates/aingle_minimal/src/ota.rs b/crates/aingle_minimal/src/ota.rs index 02f44a83..01ac4c7b 100644 --- a/crates/aingle_minimal/src/ota.rs +++ b/crates/aingle_minimal/src/ota.rs @@ -711,7 +711,7 @@ mod tests { }; let cloned = update.clone(); assert_eq!(cloned.version, "2.0.0"); - assert_eq!(cloned.critical, true); + assert!(cloned.critical); let debug = format!("{:?}", update); assert!(debug.contains("UpdateInfo")); diff --git a/crates/aingle_minimal/src/power.rs b/crates/aingle_minimal/src/power.rs index 8f0a231f..18280b38 100644 --- a/crates/aingle_minimal/src/power.rs +++ b/crates/aingle_minimal/src/power.rs @@ -590,9 +590,11 @@ mod tests { std::thread::sleep(Duration::from_millis(100)); let stats = pm.get_stats(); - // At least one metric should be non-zero - assert!(stats.uptime_secs >= 0); - assert!(stats.time_in_balanced >= 0); + // These counters are unsigned, so the old `>= 0` pair held always. Assert + // the invariant that can actually break instead: time spent in one + // profile cannot exceed the total uptime, and energy is never negative. + assert!(stats.time_in_balanced <= stats.uptime_secs); + assert!(stats.energy_consumed_mwh >= 0.0); } #[test] diff --git a/crates/aingle_minimal/tests/iot_integration_tests.rs b/crates/aingle_minimal/tests/iot_integration_tests.rs index 9bd70f68..c72532f8 100644 --- a/crates/aingle_minimal/tests/iot_integration_tests.rs +++ b/crates/aingle_minimal/tests/iot_integration_tests.rs @@ -260,10 +260,11 @@ fn test_power_stats_tracking() { pm.set_power_profile(PowerProfile::LowPower); let stats = pm.get_stats(); - // Stats should be valid (non-negative) - assert!(stats.uptime_secs >= 0); - assert!(stats.time_in_high_performance >= 0); - assert!(stats.time_in_low_power >= 0); + // These counters are unsigned, so "non-negative" was true by construction + // and asserted nothing. The real invariant: time attributed to the profiles + // this test drove cannot exceed the total uptime. + assert!(stats.time_in_high_performance <= stats.uptime_secs); + assert!(stats.time_in_low_power <= stats.uptime_secs); } #[test] @@ -400,7 +401,9 @@ fn test_complete_iot_device_workflow() { // 8. Get statistics let power_stats = power_manager.get_stats(); - assert!(power_stats.uptime_secs >= 0); + // `uptime_secs` is unsigned; the old `>= 0` asserted nothing. Energy is the + // figure this end-to-end run can actually get wrong. + assert!(power_stats.energy_consumed_mwh >= 0.0); let ota_stats = ota_manager.stats(); assert_eq!(ota_stats.updates_applied, 0); diff --git a/crates/aingle_minimal/tests/transport_integration_tests.rs b/crates/aingle_minimal/tests/transport_integration_tests.rs index d406b5ae..5c2de25d 100644 --- a/crates/aingle_minimal/tests/transport_integration_tests.rs +++ b/crates/aingle_minimal/tests/transport_integration_tests.rs @@ -8,8 +8,6 @@ //! - BLE scanning, connection, and message exchange //! - Hardware wallet connection and signing workflow -use std::time::Duration; - // ============================================================================ // WebRTC Transport Tests // ============================================================================ diff --git a/crates/aingle_raft/src/log_store.rs b/crates/aingle_raft/src/log_store.rs index d3dd4d27..a19d495c 100644 --- a/crates/aingle_raft/src/log_store.rs +++ b/crates/aingle_raft/src/log_store.rs @@ -258,7 +258,7 @@ impl CortexLogStore { term: *term, data: data.clone(), }) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + .map_err(io::Error::other)?; } // Only update BTreeMap after all WAL writes succeed @@ -279,7 +279,7 @@ impl CortexLogStore { pub async fn last_log_id(&self) -> Option { let log = self.log.read().await; - log.values().last().map(|e| e.log_id.clone()) + log.values().last().map(|e| e.log_id) } } @@ -299,7 +299,7 @@ impl RaftLogReader for Arc { async fn read_vote(&mut self) -> Result, io::Error> { let v = self.vote.read().await; - Ok(v.clone()) + Ok(*v) } } @@ -315,14 +315,10 @@ impl RaftLogStorage for Arc { let log = self.log.read().await; let purged = self.purged_log_id.read().await; - let last_log_id = log - .values() - .last() - .map(|e| e.log_id.clone()) - .or_else(|| purged.clone()); + let last_log_id = log.values().last().map(|e| e.log_id).or_else(|| *purged); Ok(LogState { - last_purged_log_id: purged.clone(), + last_purged_log_id: *purged, last_log_id, }) } @@ -334,7 +330,7 @@ impl RaftLogStorage for Arc { async fn save_vote(&mut self, vote: &Vote) -> Result<(), io::Error> { CortexLogStore::persist_vote(&self.wal_dir, vote)?; let mut v = self.vote.write().await; - *v = Some(vote.clone()); + *v = Some(*vote); Ok(()) } @@ -347,7 +343,7 @@ impl RaftLogStorage for Arc { async fn read_committed(&mut self) -> Result, io::Error> { let c = self.committed.read().await; - Ok(c.clone()) + Ok(*c) } async fn append(&mut self, entries: I, callback: IOFlushed) -> Result<(), io::Error> @@ -384,7 +380,7 @@ impl RaftLogStorage for Arc { // Persist truncation boundary so recovery filters out stale entries let mut trunc = self.truncated_after.write().await; - *trunc = last_log_id.clone(); + *trunc = last_log_id; CortexLogStore::persist_truncated_after(&self.wal_dir, &last_log_id)?; Ok(()) @@ -400,7 +396,7 @@ impl RaftLogStorage for Arc { // Persist purge boundary let mut purged = self.purged_log_id.write().await; - *purged = Some(log_id.clone()); + *purged = Some(log_id); CortexLogStore::persist_purged(&self.wal_dir, &log_id)?; // Clean up old WAL segments that are entirely below the purge point diff --git a/crates/aingle_raft/src/network.rs b/crates/aingle_raft/src/network.rs index 0cce196b..453cd8e5 100644 --- a/crates/aingle_raft/src/network.rs +++ b/crates/aingle_raft/src/network.rs @@ -345,7 +345,7 @@ impl CortexNetworkConnection { .as_millis() ); - let num_chunks = (payload.len() + CHUNK_SIZE - 1) / CHUNK_SIZE; + let num_chunks = payload.len().div_ceil(CHUNK_SIZE); tracing::info!( target_node = self.target, total_bytes = total_size, diff --git a/crates/aingle_raft/src/snapshot_builder.rs b/crates/aingle_raft/src/snapshot_builder.rs index d3dff2e8..d15a3244 100644 --- a/crates/aingle_raft/src/snapshot_builder.rs +++ b/crates/aingle_raft/src/snapshot_builder.rs @@ -36,7 +36,7 @@ impl RaftSnapshotBuilder for CortexSnapshotBuilder { let triples = { let all = graph .find(aingle_graph::TriplePattern::any()) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| io::Error::other(e.to_string()))?; all.into_iter() .map(|t| TripleSnapshot { @@ -49,7 +49,7 @@ impl RaftSnapshotBuilder for CortexSnapshotBuilder { let ineru_ltm = memory .export_snapshot() - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| io::Error::other(e.to_string()))?; // Drop locks before serialization to reduce hold time drop(graph); @@ -93,14 +93,12 @@ impl RaftSnapshotBuilder for CortexSnapshotBuilder { checksum: String::new(), }; - let data = snapshot - .to_bytes() - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + let data = snapshot.to_bytes().map_err(io::Error::other)?; let snapshot_id = format!("snap-{}-{}", last_applied_term, last_applied_index); let meta = SnapshotMeta { - last_log_id: self.last_applied.clone(), + last_log_id: self.last_applied, last_membership: self.last_membership.clone(), snapshot_id, }; diff --git a/crates/aingle_raft/src/state_machine.rs b/crates/aingle_raft/src/state_machine.rs index 64ec27e4..c1f6cb8d 100644 --- a/crates/aingle_raft/src/state_machine.rs +++ b/crates/aingle_raft/src/state_machine.rs @@ -428,7 +428,7 @@ impl CortexStateMachine { /// Get the last applied log ID. pub async fn last_applied(&self) -> Option { let guard = self.last_applied.read().await; - guard.clone() + *guard } /// Get the count of applied mutations. @@ -447,7 +447,7 @@ impl RaftStateMachine for Arc { async fn applied_state(&mut self) -> Result<(Option, StoredMembershipOf), io::Error> { let la = self.last_applied.read().await; let membership = self.last_membership.read().await; - Ok((la.clone(), membership.clone())) + Ok((*la, membership.clone())) } async fn apply(&mut self, mut entries: Strm) -> Result<(), io::Error> @@ -460,7 +460,7 @@ impl RaftStateMachine for Arc { // Check for membership change if let Some(membership) = entry.get_membership() { let mut lm = self.last_membership.write().await; - *lm = StoredMembership::new(Some(entry.log_id.clone()), membership.clone()); + *lm = StoredMembership::new(Some(entry.log_id), membership.clone()); } // Apply the business logic @@ -482,7 +482,7 @@ impl RaftStateMachine for Arc { // marking entries as applied before they actually are (#1). { let mut la = self.last_applied.write().await; - *la = Some(entry.log_id.clone()); + *la = Some(entry.log_id); } // Send response to client if waiting (leader only) @@ -500,7 +500,7 @@ impl RaftStateMachine for Arc { CortexSnapshotBuilder { graph: Arc::clone(&self.graph), memory: Arc::clone(&self.memory), - last_applied: la.clone(), + last_applied: *la, last_membership: membership.clone(), proof_provider: self.proof_provider.clone(), } @@ -521,8 +521,7 @@ impl RaftStateMachine for Arc { // Build both new graph and new memory into temporaries FIRST, // then swap atomically only if both succeed (#7). - let new_graph = - GraphDB::memory().map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; + let new_graph = GraphDB::memory().map_err(|e| io::Error::other(e.to_string()))?; for ts in &cluster_snap.triples { let value = json_to_value(&ts.object); let triple = aingle_graph::Triple::new( @@ -532,7 +531,7 @@ impl RaftStateMachine for Arc { ); new_graph .insert(triple) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; + .map_err(|e| io::Error::other(e.to_string()))?; } let new_memory = if !cluster_snap.ineru_ltm.is_empty() { @@ -597,7 +596,7 @@ impl RaftStateMachine for Arc { // Update metadata { let mut la = self.last_applied.write().await; - *la = meta.last_log_id.clone(); + *la = meta.last_log_id; } { let mut lm = self.last_membership.write().await; diff --git a/crates/aingle_viz/src/api.rs b/crates/aingle_viz/src/api.rs index 617dece9..99558bb9 100644 --- a/crates/aingle_viz/src/api.rs +++ b/crates/aingle_viz/src/api.rs @@ -844,8 +844,8 @@ mod tests { // Add test data for i in 0..5 { - let node = DagNodeBuilder::new(&format!("node{}", i), NodeType::Entry) - .label(&format!("Node {}", i)) + let node = DagNodeBuilder::new(format!("node{}", i), NodeType::Entry) + .label(format!("Node {}", i)) .build(); state.add_node(node).await.unwrap(); } diff --git a/crates/aingle_viz/src/server.rs b/crates/aingle_viz/src/server.rs index 25e6418d..c0e4792a 100644 --- a/crates/aingle_viz/src/server.rs +++ b/crates/aingle_viz/src/server.rs @@ -729,8 +729,8 @@ mod tests { let mut dag = DagView::new(); for i in 0..5 { dag.add_node( - DagNodeBuilder::new(&format!("node{}", i), NodeType::Entry) - .label(&format!("Node {}", i)) + DagNodeBuilder::new(format!("node{}", i), NodeType::Entry) + .label(format!("Node {}", i)) .build(), ); } diff --git a/crates/aingle_wal/src/writer.rs b/crates/aingle_wal/src/writer.rs index 13b4cae1..eb35e9b1 100644 --- a/crates/aingle_wal/src/writer.rs +++ b/crates/aingle_wal/src/writer.rs @@ -73,12 +73,10 @@ impl WalWriter { let timestamp = Utc::now(); let prev_hash = { - let guard = self.last_hash.lock().map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("WAL last_hash lock poisoned: {e}"), - ) - })?; + let guard = self + .last_hash + .lock() + .map_err(|e| io::Error::other(format!("WAL last_hash lock poisoned: {e}")))?; *guard }; @@ -93,12 +91,10 @@ impl WalWriter { }; { - let mut seg = self.current_segment.lock().map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("WAL segment lock poisoned: {e}"), - ) - })?; + let mut seg = self + .current_segment + .lock() + .map_err(|e| io::Error::other(format!("WAL segment lock poisoned: {e}")))?; seg.append(&entry)?; seg.sync()?; @@ -112,12 +108,10 @@ impl WalWriter { // Update last_hash { - let mut guard = self.last_hash.lock().map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("WAL last_hash lock poisoned: {e}"), - ) - })?; + let mut guard = self + .last_hash + .lock() + .map_err(|e| io::Error::other(format!("WAL last_hash lock poisoned: {e}")))?; *guard = entry.hash; } @@ -126,12 +120,10 @@ impl WalWriter { /// Flush the current segment to disk. pub fn sync(&self) -> io::Result<()> { - let mut seg = self.current_segment.lock().map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - format!("WAL segment lock poisoned: {e}"), - ) - })?; + let mut seg = self + .current_segment + .lock() + .map_err(|e| io::Error::other(format!("WAL segment lock poisoned: {e}")))?; seg.sync() } diff --git a/crates/aingle_zk/benches/full_benchmarks.rs b/crates/aingle_zk/benches/full_benchmarks.rs index d4b8c7a3..6a2fef2a 100644 --- a/crates/aingle_zk/benches/full_benchmarks.rs +++ b/crates/aingle_zk/benches/full_benchmarks.rs @@ -11,7 +11,7 @@ //! - Memory usage use aingle_zk::{ - aggregation::{aggregate_proofs, ProofAggregator}, + aggregation::aggregate_proofs, batch::{verify_schnorr_batch, BatchVerifier}, commitment::{HashCommitment, PedersenCommitment}, merkle::{MerkleTree, SparseMerkleTree}, @@ -442,12 +442,16 @@ fn benchmark_serialization(c: &mut Criterion) { /// Benchmark memory usage fn benchmark_memory(c: &mut Criterion) { - let mut group = c.benchmark_group("memory"); + // Not `mut`: this group records no measurements, it only prints sizes. + let group = c.benchmark_group("memory"); // Measure proof sizes let secret = Scalar::random(&mut OsRng); let public = RISTRETTO_BASEPOINT_POINT * secret; - let schnorr = SchnorrProof::prove_knowledge(&secret, b"test", &public); + // Argument order follows `prove_knowledge(secret, public_point, message)`. + // It was called with the last two swapped, so this benchmark had not + // compiled since that signature settled — invisible until `--all-targets`. + let schnorr = SchnorrProof::prove_knowledge(&secret, &public, b"test"); let schnorr_size = std::mem::size_of_val(&schnorr); println!("Schnorr proof in-memory size: {} bytes", schnorr_size); diff --git a/crates/aingle_zk/src/aggregation.rs b/crates/aingle_zk/src/aggregation.rs index 0976bb12..37a49a7b 100644 --- a/crates/aingle_zk/src/aggregation.rs +++ b/crates/aingle_zk/src/aggregation.rs @@ -423,7 +423,7 @@ mod tests { // Should have some size savings from aggregation let savings = agg.size_savings(); - assert!(savings >= 0.0 && savings <= 1.0); + assert!((0.0..=1.0).contains(&savings)); let ratio = agg.compression_ratio(); // Ratio could be < 1.0 if aggregated format has overhead @@ -506,8 +506,9 @@ mod tests { assert!(result.all_valid); assert_eq!(result.success_rate(), 1.0); assert!(result.avg_time_per_proof() >= 0.0); - // Verification time may be 0 if very fast (< 1ms) - assert!(result.verification_time_ms >= 0); + // No assertion on `verification_time_ms`: it is unsigned and legitimately + // 0 for a batch that verifies in under a millisecond, so every bound + // that could be written here is either always true or flaky. } #[test] diff --git a/crates/aingle_zk/src/proof.rs b/crates/aingle_zk/src/proof.rs index 3d6d6d0d..0ec00bc1 100644 --- a/crates/aingle_zk/src/proof.rs +++ b/crates/aingle_zk/src/proof.rs @@ -939,7 +939,7 @@ mod tests { // Compute challenge c = H(R || P) let mut hasher = Sha256::new(); - hasher.update(&r_bytes); + hasher.update(r_bytes); hasher.update(public.compress().as_bytes()); let challenge: [u8; 32] = hasher.finalize().into(); let c = Scalar::from_bytes_mod_order(challenge); diff --git a/crates/kaneru/benches/agent_bench.rs b/crates/kaneru/benches/agent_bench.rs index 197a34f5..1234c2d8 100644 --- a/crates/kaneru/benches/agent_bench.rs +++ b/crates/kaneru/benches/agent_bench.rs @@ -5,7 +5,7 @@ //! //! Run with: cargo bench -p kaneru -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; use kaneru::{Action, Agent, AgentConfig, Condition, Goal, Observation, Rule, SimpleAgent}; /// Benchmark agent creation diff --git a/crates/kaneru/examples/kaneru_orchestrator.rs b/crates/kaneru/examples/kaneru_orchestrator.rs index 3acaacb0..3b5f2d66 100644 --- a/crates/kaneru/examples/kaneru_orchestrator.rs +++ b/crates/kaneru/examples/kaneru_orchestrator.rs @@ -12,9 +12,8 @@ //! - Serialize/deserialize agent state use kaneru::{ - Action, ActionResult, ActionType, Goal, GoalSelectionStrategy, KaneruAgent, KaneruConfig, - LearningAlgorithm, LearningConfig, Observation, OperationMode, Outcome, PredictiveConfig, - Priority, + ActionResult, ActionType, Goal, GoalSelectionStrategy, KaneruAgent, KaneruConfig, + LearningAlgorithm, LearningConfig, Observation, OperationMode, Outcome, Priority, }; fn main() { diff --git a/crates/kaneru/src/agent.rs b/crates/kaneru/src/agent.rs index c935fff2..b1624975 100644 --- a/crates/kaneru/src/agent.rs +++ b/crates/kaneru/src/agent.rs @@ -872,10 +872,12 @@ impl Agent for SimpleAgent { self.stats.actions_executed += 1; // Store state-action pair for learning - if self.config.learning_enabled && self.last_observation.is_some() { - let state_id = StateId::from_observation(self.last_observation.as_ref().unwrap()); - let action_id = ActionId::from_action(&action); - self.last_state_action = Some((state_id, action_id)); + if self.config.learning_enabled { + if let Some(observation) = self.last_observation.as_ref() { + let state_id = StateId::from_observation(observation); + let action_id = ActionId::from_action(&action); + self.last_state_action = Some((state_id, action_id)); + } } // Simple execution - just log and return success diff --git a/crates/kaneru/src/coordination.rs b/crates/kaneru/src/coordination.rs index 2ec8f594..b2850418 100644 --- a/crates/kaneru/src/coordination.rs +++ b/crates/kaneru/src/coordination.rs @@ -36,6 +36,7 @@ use crate::{Action, AgentId, KaneruAgent, Observation, Outcome}; use serde::{Deserialize, Serialize}; +use std::cmp::Reverse; use std::collections::{HashMap, VecDeque}; /// A unique identifier for a `Message`. @@ -301,7 +302,7 @@ impl MessageBus { } self.queue = remaining; - messages.sort_by(|a, b| b.priority.cmp(&a.priority)); + messages.sort_by_key(|m| Reverse(m.priority)); messages } diff --git a/crates/kaneru/src/goal.rs b/crates/kaneru/src/goal.rs index 1e56ffa1..d2c0b0cf 100644 --- a/crates/kaneru/src/goal.rs +++ b/crates/kaneru/src/goal.rs @@ -375,7 +375,7 @@ mod tests { #[test] fn test_goal_status_clone() { let status = GoalStatus::Active; - let cloned = status.clone(); + let cloned = status; assert_eq!(status, cloned); } diff --git a/crates/kaneru/src/hierarchical/decomposition.rs b/crates/kaneru/src/hierarchical/decomposition.rs index e7ad4998..773b159f 100644 --- a/crates/kaneru/src/hierarchical/decomposition.rs +++ b/crates/kaneru/src/hierarchical/decomposition.rs @@ -330,7 +330,6 @@ impl DecompositionStrategy for ConditionalStrategy { #[cfg(test)] mod tests { use super::*; - use crate::types::ValueRange; #[test] fn test_default_rules_exist() { diff --git a/crates/kaneru/src/hierarchical/goal_solver.rs b/crates/kaneru/src/hierarchical/goal_solver.rs index 4296f40e..6abcb834 100644 --- a/crates/kaneru/src/hierarchical/goal_solver.rs +++ b/crates/kaneru/src/hierarchical/goal_solver.rs @@ -564,7 +564,6 @@ fn is_mutually_exclusive(g1: &GoalType, g2: &GoalType) -> bool { #[cfg(test)] mod tests { use super::*; - use crate::types::Timestamp; #[test] fn test_goal_solver_creation() { diff --git a/crates/kaneru/src/hierarchical/tests.rs b/crates/kaneru/src/hierarchical/tests.rs index fe596f56..229b755f 100644 --- a/crates/kaneru/src/hierarchical/tests.rs +++ b/crates/kaneru/src/hierarchical/tests.rs @@ -96,7 +96,7 @@ fn test_executable_goals() { let executable = solver.get_executable_goals(); // Only the simple task and subtask should be executable - assert!(executable.len() >= 1); + assert!(!executable.is_empty()); assert!(executable.iter().any(|g| g.id == id1)); } diff --git a/crates/kaneru/src/learning/engine.rs b/crates/kaneru/src/learning/engine.rs index a78328f1..bb813b5e 100644 --- a/crates/kaneru/src/learning/engine.rs +++ b/crates/kaneru/src/learning/engine.rs @@ -670,10 +670,12 @@ mod tests { #[test] fn test_epsilon_decay() { - let mut config = LearningConfig::default(); - config.epsilon = 1.0; - config.epsilon_decay = 0.9; - config.epsilon_min = 0.1; + let config = LearningConfig { + epsilon: 1.0, + epsilon_decay: 0.9, + epsilon_min: 0.1, + ..Default::default() + }; let mut engine = LearningEngine::new(config); diff --git a/crates/kaneru/src/predictive/anomaly.rs b/crates/kaneru/src/predictive/anomaly.rs index 57b7fff6..33768bb5 100644 --- a/crates/kaneru/src/predictive/anomaly.rs +++ b/crates/kaneru/src/predictive/anomaly.rs @@ -279,7 +279,7 @@ mod tests { detector.update(&Observation::sensor("flag", true)); detector.update(&Observation::sensor("flag", false)); - assert!(detector.history.len() > 0); + assert!(!detector.history.is_empty()); } #[test] diff --git a/crates/kaneru/src/types.rs b/crates/kaneru/src/types.rs index 34feffa2..9b84a614 100644 --- a/crates/kaneru/src/types.rs +++ b/crates/kaneru/src/types.rs @@ -293,8 +293,8 @@ mod tests { #[test] fn test_value_conversions() { - let v = Value::Float(3.14); - assert!((v.as_f64().unwrap() - 3.14).abs() < 0.001); + let v = Value::Float(2.5); + assert!((v.as_f64().unwrap() - 2.5).abs() < 0.001); let v = Value::Int(42); assert_eq!(v.as_i64().unwrap(), 42); @@ -372,7 +372,7 @@ mod tests { assert_eq!(Value::Bool(true).as_string(), "true"); assert_eq!(Value::Bool(false).as_string(), "false"); assert_eq!(Value::Int(42).as_string(), "42"); - assert_eq!(Value::Float(3.14).as_string(), "3.14"); + assert_eq!(Value::Float(2.5).as_string(), "2.5"); assert_eq!(Value::String("test".to_string()).as_string(), "test"); } @@ -393,9 +393,9 @@ mod tests { #[test] fn test_value_from_f64() { - let v: Value = 3.14f64.into(); + let v: Value = 2.5f64.into(); if let Value::Float(f) = v { - assert!((f - 3.14).abs() < 0.001); + assert!((f - 2.5).abs() < 0.001); } else { panic!("Expected Float"); } diff --git a/examples/iot_sensor_network/src/main.rs b/examples/iot_sensor_network/src/main.rs index ea457712..499cdf42 100644 --- a/examples/iot_sensor_network/src/main.rs +++ b/examples/iot_sensor_network/src/main.rs @@ -166,7 +166,7 @@ fn main() -> Result<(), Box> { let reading: SensorReading = serde_json::from_slice(&entry.content)?; println!( " {} - {} {:.2} {} at {}", - hash.to_string()[..8].to_string(), + &hash.to_string()[..8], reading.sensor_id, reading.value, reading.unit,