Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions crates/aingle_ai/src/ineru/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
5 changes: 3 additions & 2 deletions crates/aingle_ai/src/kaneru/continuum_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/aingle_ai/src/kaneru/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions crates/aingle_ai/src/kaneru/self_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions crates/aingle_ai/src/nested_learning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,27 @@ 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]
fn test_nested_learning_batch() {
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);
}

#[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();
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_ai/src/nested_learning/transaction_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/aingle_ai/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)));
}
}
9 changes: 2 additions & 7 deletions crates/aingle_contracts/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_contracts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 6 additions & 8 deletions crates/aingle_cortex/src/cluster_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
_ => {}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}");
}
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions crates/aingle_cortex/src/p2p/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ impl P2pConfig {
i += 1;
}
}
"--p2p-peer" => {
if i + 1 < args.len() {
if let Ok(addr) = args[i + 1].parse::<SocketAddr>() {
cfg.manual_peers.push(addr);
}
i += 1;
"--p2p-peer" if i + 1 < args.len() => {
if let Ok(addr) = args[i + 1].parse::<SocketAddr>() {
cfg.manual_peers.push(addr);
}
i += 1;
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_cortex/src/p2p/dag_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn collect_local_tips(graph: &GraphDB) -> (Vec<String>, u64) {
.tips_raw()
.unwrap_or_default()
.into_iter()
.map(|h| hex::encode(h))
.map(hex::encode)
.collect::<Vec<_>>();
let count = dag_store.action_count() as u64;
(tips, count)
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_cortex/src/proofs/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions crates/aingle_cortex/src/rest/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<AuditEntry>(&line) {
entries.push(entry);
}
for line in reader.lines().flatten() {
if let Ok(entry) = serde_json::from_str::<AuditEntry>(&line) {
entries.push(entry);
}
}
// Keep only the last max_entries
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_cortex/src/rest/proof_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions crates/aingle_cortex/src/rest/triples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions crates/aingle_cortex/tests/data_integrity_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand All @@ -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(),
Expand Down Expand Up @@ -209,7 +209,7 @@ async fn test_batch_insert_index_consistency() {
let triples: Vec<Triple> = (0..100)
.map(|i| {
Triple::new(
NodeId::named(&format!("batch:{}", i)),
NodeId::named(format!("batch:{}", i)),
Predicate::named("batch_value"),
Value::Integer(i),
)
Expand All @@ -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));
Expand All @@ -238,7 +238,7 @@ async fn test_batch_insert_index_consistency() {
let triples2: Vec<Triple> = (0..100)
.map(|i| {
Triple::new(
NodeId::named(&format!("batch:{}", i)),
NodeId::named(format!("batch:{}", i)),
Predicate::named("batch_value"),
Value::Integer(i),
)
Expand Down Expand Up @@ -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)),
);
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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),
);
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/aingle_cortex/tests/rate_limiting_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
4 changes: 1 addition & 3 deletions crates/aingle_graph/src/dag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Loading
Loading