Skip to content

Commit d850323

Browse files
claudehyperpolymath
authored andcommitted
fix: pass clippy --all-targets -D warnings + fmt for CI
Outcome: - cargo fmt --all -- --check → pass - cargo clippy --all-targets --all-features -- -D warnings → pass - cargo test --workspace --release → 139 / 139 pass Specific fixes: - bridge: replace `len() == 0` with `is_empty()` (clippy::len_zero). - llm: surface `MockBackend::config()` instead of dead-coding the field. - claude-client: drop unused imports (futures::StreamExt, tokio::sync::mpsc, tracing::{error,info}); allow dead `error_type` field used only for serde deserialisation; derive Default for ClaudeModel via #[default]. - lsm + esn: rand 0.9 deprecation rename (`thread_rng` → `rng`, `gen` → `random`). These were latent because the workspace didn't compile before; pinning rand 0.9 surfaced the deprecation warnings, which the CI lint gate treats as errors. - neurophone-core: deduplicate accidental `#![forbid(unsafe_code)]`, drop unused `Arc`/`Duration` imports, derive Default for SystemState, remove `>= 0` checks on unsigned types (clippy::absurd_extreme_comparisons), swap `vec!["..."]` for an array literal (clippy::useless_vec). - claude-client integration tests: use `RangeInclusive::contains` instead of manual `>=` / `<=` chain (clippy::manual_range_contains). - All eight criterion benches: migrate to `std::hint::black_box` (criterion::black_box was deprecated in criterion 0.6). - sensors bench: don't pass a unit value to black_box. - property test: derive iteration counter from enumerate() instead of a parallel mutable variable (clippy::explicit_counter_loop). - cargo fmt --all run; 24 files normalised (import order, trailing commas in long groups, line breaks in nested formats). https://claude.ai/code/session_012opuP3HehkjDkF1XQ8nFex
1 parent 2e0d5d3 commit d850323

26 files changed

Lines changed: 658 additions & 353 deletions

crates/bridge/benches/bridge_bench.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
//! Benches for the bridge crate.
44
55
use bridge::{Bridge, BridgeConfig};
6-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
6+
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
77
use ndarray::Array1;
8+
use std::hint::black_box;
89

910
fn bench_encode_sizes(c: &mut Criterion) {
1011
let mut g = c.benchmark_group("bridge_encode");
1112
for &(n_lsm, n_esn) in &[(100usize, 50usize), (512, 300), (2048, 1024)] {
1213
let lsm = Array1::from_elem(n_lsm, 0.4);
1314
let esn = Array1::from_elem(n_esn, 0.4);
14-
g.bench_with_input(BenchmarkId::from_parameter(format!("lsm{n_lsm}_esn{n_esn}")),
15-
&(lsm, esn), |b, (lsm, esn)| {
15+
g.bench_with_input(
16+
BenchmarkId::from_parameter(format!("lsm{n_lsm}_esn{n_esn}")),
17+
&(lsm, esn),
18+
|b, (lsm, esn)| {
1619
let mut br = Bridge::new(BridgeConfig::default()).unwrap();
1720
b.iter(|| black_box(br.encode(lsm.view(), esn.view())))
18-
});
21+
},
22+
);
1923
}
2024
g.finish();
2125
}
@@ -28,7 +32,9 @@ fn bench_encode_with_dynamics(c: &mut Criterion) {
2832
let esn = Array1::from_elem(300, 0.4);
2933
b.iter(|| {
3034
t = t.wrapping_add(1);
31-
for v in lsm.iter_mut() { *v = ((t % 100) as f32) * 0.01; }
35+
for v in lsm.iter_mut() {
36+
*v = ((t % 100) as f32) * 0.01;
37+
}
3238
black_box(br.encode(lsm.view(), esn.view()));
3339
})
3440
});

crates/bridge/src/lib.rs

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ pub struct BridgeConfig {
2929
}
3030

3131
impl Default for BridgeConfig {
32-
fn default() -> Self { Self { activation_threshold: 0.3, lsm_weight: 0.5 } }
32+
fn default() -> Self {
33+
Self {
34+
activation_threshold: 0.3,
35+
lsm_weight: 0.5,
36+
}
37+
}
3338
}
3439

3540
impl BridgeConfig {
3641
pub fn validate(&self) -> Result<(), BridgeError> {
3742
if !(0.0..=1.0).contains(&self.activation_threshold) {
38-
return Err(BridgeError::InvalidConfig("activation_threshold ∉ [0,1]".into()));
43+
return Err(BridgeError::InvalidConfig(
44+
"activation_threshold ∉ [0,1]".into(),
45+
));
3946
}
4047
if !(0.0..=1.0).contains(&self.lsm_weight) {
4148
return Err(BridgeError::InvalidConfig("lsm_weight ∉ [0,1]".into()));
@@ -69,20 +76,31 @@ pub struct Bridge {
6976
impl Bridge {
7077
pub fn new(config: BridgeConfig) -> Result<Self, BridgeError> {
7178
config.validate()?;
72-
Ok(Self { config, last_lsm: None })
79+
Ok(Self {
80+
config,
81+
last_lsm: None,
82+
})
7383
}
7484

75-
pub fn config(&self) -> &BridgeConfig { &self.config }
85+
pub fn config(&self) -> &BridgeConfig {
86+
&self.config
87+
}
7688

7789
fn count_active(view: ArrayView1<f32>, thresh: f32) -> usize {
7890
view.iter().filter(|v| v.abs() >= thresh).count()
7991
}
8092

8193
fn rms_delta(prev: &Array1<f32>, curr: ArrayView1<f32>) -> f32 {
82-
if prev.len() != curr.len() { return 0.0; }
94+
if prev.len() != curr.len() {
95+
return 0.0;
96+
}
8397
let n = prev.len() as f32;
84-
if n == 0.0 { return 0.0; }
85-
let sum_sq: f32 = prev.iter().zip(curr.iter())
98+
if n == 0.0 {
99+
return 0.0;
100+
}
101+
let sum_sq: f32 = prev
102+
.iter()
103+
.zip(curr.iter())
86104
.map(|(a, b)| (a - b).powi(2))
87105
.sum();
88106
(sum_sq / n).sqrt().min(1.0)
@@ -93,8 +111,16 @@ impl Bridge {
93111
let t = self.config.activation_threshold;
94112
let lsm_active = Self::count_active(lsm, t);
95113
let esn_active = Self::count_active(esn, t);
96-
let lsm_frac = if lsm.len() == 0 { 0.0 } else { lsm_active as f32 / lsm.len() as f32 };
97-
let esn_frac = if esn.len() == 0 { 0.0 } else { esn_active as f32 / esn.len() as f32 };
114+
let lsm_frac = if lsm.is_empty() {
115+
0.0
116+
} else {
117+
lsm_active as f32 / lsm.len() as f32
118+
};
119+
let esn_frac = if esn.is_empty() {
120+
0.0
121+
} else {
122+
esn_active as f32 / esn.len() as f32
123+
};
98124
let w = self.config.lsm_weight;
99125
let salience = (w * lsm_frac + (1.0 - w) * esn_frac).clamp(0.0, 1.0);
100126

@@ -106,10 +132,18 @@ impl Bridge {
106132
let description = describe(salience, urgency, lsm_active, esn_active);
107133
self.last_lsm = Some(lsm.to_owned());
108134

109-
NeuralContext { salience, urgency, lsm_active, esn_active, description }
135+
NeuralContext {
136+
salience,
137+
urgency,
138+
lsm_active,
139+
esn_active,
140+
description,
141+
}
110142
}
111143

112-
pub fn reset(&mut self) { self.last_lsm = None; }
144+
pub fn reset(&mut self) {
145+
self.last_lsm = None;
146+
}
113147
}
114148

115149
fn describe(salience: f32, urgency: f32, lsm_active: usize, esn_active: usize) -> String {
@@ -129,20 +163,34 @@ fn describe(salience: f32, urgency: f32, lsm_active: usize, esn_active: usize) -
129163
)
130164
}
131165

132-
pub fn hello() -> &'static str { "bridge" }
166+
pub fn hello() -> &'static str {
167+
"bridge"
168+
}
133169

134170
#[cfg(test)]
135171
mod tests {
136172
use super::*;
137173
use ndarray::Array1;
138174

139-
#[test] fn config_validates() {
140-
assert!(BridgeConfig { activation_threshold: -0.1, lsm_weight: 0.5 }.validate().is_err());
141-
assert!(BridgeConfig { activation_threshold: 0.5, lsm_weight: 1.5 }.validate().is_err());
175+
#[test]
176+
fn config_validates() {
177+
assert!(BridgeConfig {
178+
activation_threshold: -0.1,
179+
lsm_weight: 0.5
180+
}
181+
.validate()
182+
.is_err());
183+
assert!(BridgeConfig {
184+
activation_threshold: 0.5,
185+
lsm_weight: 1.5
186+
}
187+
.validate()
188+
.is_err());
142189
assert!(BridgeConfig::default().validate().is_ok());
143190
}
144191

145-
#[test] fn quiet_state_low_salience() {
192+
#[test]
193+
fn quiet_state_low_salience() {
146194
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
147195
let lsm = Array1::zeros(100);
148196
let esn = Array1::zeros(50);
@@ -153,7 +201,8 @@ mod tests {
153201
assert!(ctx.description.contains("quiet"));
154202
}
155203

156-
#[test] fn high_state_high_salience() {
204+
#[test]
205+
fn high_state_high_salience() {
157206
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
158207
let lsm = Array1::from_elem(100, 1.0);
159208
let esn = Array1::from_elem(50, 1.0);
@@ -162,29 +211,33 @@ mod tests {
162211
assert!(ctx.description.contains("high"));
163212
}
164213

165-
#[test] fn urgency_zero_on_first_call() {
214+
#[test]
215+
fn urgency_zero_on_first_call() {
166216
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
167217
let lsm = Array1::from_elem(10, 0.5);
168218
let ctx = b.encode(lsm.view(), Array1::zeros(10).view());
169219
assert!(ctx.urgency.abs() < 1e-6);
170220
}
171221

172-
#[test] fn urgency_rises_with_change() {
222+
#[test]
223+
fn urgency_rises_with_change() {
173224
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
174225
let _ = b.encode(Array1::zeros(10).view(), Array1::zeros(10).view());
175226
let ctx = b.encode(Array1::from_elem(10, 1.0).view(), Array1::zeros(10).view());
176227
assert!(ctx.urgency > 0.5);
177228
}
178229

179-
#[test] fn reset_clears_history() {
230+
#[test]
231+
fn reset_clears_history() {
180232
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
181233
let _ = b.encode(Array1::from_elem(10, 1.0).view(), Array1::zeros(10).view());
182234
b.reset();
183235
let ctx = b.encode(Array1::zeros(10).view(), Array1::zeros(10).view());
184236
assert!(ctx.urgency.abs() < 1e-6);
185237
}
186238

187-
#[test] fn description_contains_markers() {
239+
#[test]
240+
fn description_contains_markers() {
188241
let mut b = Bridge::new(BridgeConfig::default()).unwrap();
189242
let ctx = b.encode(Array1::zeros(10).view(), Array1::zeros(10).view());
190243
assert!(ctx.description.starts_with("[NEURAL_STATE]"));

crates/bridge/tests/aspect_lifecycle.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ use ndarray::Array1;
77

88
#[test]
99
fn aspect_invalid_threshold_rejected() {
10-
let cfg = BridgeConfig { activation_threshold: 1.5, lsm_weight: 0.5 };
10+
let cfg = BridgeConfig {
11+
activation_threshold: 1.5,
12+
lsm_weight: 0.5,
13+
};
1114
assert!(Bridge::new(cfg).is_err());
1215
}
1316

1417
#[test]
1518
fn aspect_invalid_weight_rejected() {
16-
let cfg = BridgeConfig { activation_threshold: 0.5, lsm_weight: -0.1 };
19+
let cfg = BridgeConfig {
20+
activation_threshold: 0.5,
21+
lsm_weight: -0.1,
22+
};
1723
assert!(Bridge::new(cfg).is_err());
1824
}
1925

crates/bridge/tests/integration_encode.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ fn salience_monotonic_in_active_fraction() {
2828

2929
#[test]
3030
fn lsm_weight_zero_uses_only_esn() {
31-
let cfg = BridgeConfig { lsm_weight: 0.0, ..Default::default() };
31+
let cfg = BridgeConfig {
32+
lsm_weight: 0.0,
33+
..Default::default()
34+
};
3235
let mut b = Bridge::new(cfg).unwrap();
3336
let lsm = Array1::from_elem(10, 1.0);
3437
let esn = Array1::zeros(10);
@@ -38,7 +41,10 @@ fn lsm_weight_zero_uses_only_esn() {
3841

3942
#[test]
4043
fn lsm_weight_one_uses_only_lsm() {
41-
let cfg = BridgeConfig { lsm_weight: 1.0, ..Default::default() };
44+
let cfg = BridgeConfig {
45+
lsm_weight: 1.0,
46+
..Default::default()
47+
};
4248
let mut b = Bridge::new(cfg).unwrap();
4349
let lsm = Array1::zeros(10);
4450
let esn = Array1::from_elem(10, 1.0);

crates/claude-client/benches/claude_bench.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! Benches for the Claude client (offline / routing only — no network).
44
55
use claude_client::{HybridInference, Message};
6-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
6+
use criterion::{criterion_group, criterion_main, Criterion};
7+
use std::hint::black_box;
78

89
fn bench_complexity_estimation(c: &mut Criterion) {
910
let h = HybridInference::new(None);
@@ -28,5 +29,10 @@ fn bench_message_construction(c: &mut Criterion) {
2829
});
2930
}
3031

31-
criterion_group!(benches, bench_complexity_estimation, bench_should_use_cloud, bench_message_construction);
32+
criterion_group!(
33+
benches,
34+
bench_complexity_estimation,
35+
bench_should_use_cloud,
36+
bench_message_construction
37+
);
3238
criterion_main!(benches);

0 commit comments

Comments
 (0)