fix(simulation): Clippy cleanup and CI enforcement (#635)
Fix all Clippy warnings across the server codebase (2411 insertions, 1341 deletions). Raise type-complexity-threshold to 750 and too-many-arguments to 12 in .clippy.toml for idiomatic Bevy ECS system signatures. The server now passes `cargo clippy -- --deny warnings` cleanly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -103,10 +103,7 @@ impl VoiceCacheStore {
|
||||
pub fn zone_cache(&mut self, zone_id: u32) -> &mut ZoneVoiceCache {
|
||||
if !self.zones.contains_key(&zone_id) {
|
||||
let cache = self.load_zone(zone_id).unwrap_or_else(|| {
|
||||
ZoneVoiceCache::new(
|
||||
self.model_version.clone(),
|
||||
self.injector_version.clone(),
|
||||
)
|
||||
ZoneVoiceCache::new(self.model_version.clone(), self.injector_version.clone())
|
||||
});
|
||||
self.zones.insert(zone_id, cache);
|
||||
}
|
||||
@@ -139,8 +136,7 @@ impl VoiceCacheStore {
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let path = dir.join(format!("{}.msgpack", zone_id));
|
||||
let data = rmp_serde::to_vec(cache)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
let data = rmp_serde::to_vec(cache).map_err(io::Error::other)?;
|
||||
fs::write(path, data)
|
||||
}
|
||||
|
||||
@@ -163,10 +159,7 @@ impl VoiceCacheStore {
|
||||
if cache.model_version != self.model_version
|
||||
|| cache.injector_version != self.injector_version
|
||||
{
|
||||
tracing::info!(
|
||||
zone_id,
|
||||
"voice cache version mismatch — invalidating"
|
||||
);
|
||||
tracing::info!(zone_id, "voice cache version mismatch — invalidating");
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -286,7 +279,10 @@ mod tests {
|
||||
|
||||
let data = rmp_serde::to_vec(&cache).unwrap();
|
||||
let restored: ZoneVoiceCache = rmp_serde::from_slice(&data).unwrap();
|
||||
assert_eq!(restored.lookup(&key), Some("Hands are steady. Eyes aren't."));
|
||||
assert_eq!(
|
||||
restored.lookup(&key),
|
||||
Some("Hands are steady. Eyes aren't.")
|
||||
);
|
||||
assert_eq!(restored.model_version, "v1");
|
||||
}
|
||||
|
||||
|
||||
@@ -115,14 +115,20 @@ pub fn probe_hardware(mode: Option<ResourceMode>) -> HardwareProbe {
|
||||
tracing::warn!("GPU mode set but VRAM probe failed — falling back to system RAM");
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_memory();
|
||||
(sys.total_memory() / (1024 * 1024), sys.available_memory() / (1024 * 1024))
|
||||
(
|
||||
sys.total_memory() / (1024 * 1024),
|
||||
sys.available_memory() / (1024 * 1024),
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// CPU mode or Apple Silicon (unified memory = system RAM)
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_memory();
|
||||
(sys.total_memory() / (1024 * 1024), sys.available_memory() / (1024 * 1024))
|
||||
(
|
||||
sys.total_memory() / (1024 * 1024),
|
||||
sys.available_memory() / (1024 * 1024),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,7 +234,10 @@ pub enum ScalingDecision {
|
||||
/// Returns (total_mb, free_mb) for the first GPU, or None.
|
||||
fn probe_nvidia_vram() -> Option<(u64, u64)> {
|
||||
let output = Command::new("nvidia-smi")
|
||||
.args(["--query-gpu=memory.total,memory.free", "--format=csv,noheader,nounits"])
|
||||
.args([
|
||||
"--query-gpu=memory.total,memory.free",
|
||||
"--format=csv,noheader,nounits",
|
||||
])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
@@ -480,9 +489,9 @@ mod tests {
|
||||
fn evaluate_scaling_hold_when_calm() {
|
||||
let decision = evaluate_scaling(
|
||||
ResourceMode::Cpu,
|
||||
2, // running
|
||||
5, // queue depth (low)
|
||||
1, // active
|
||||
2, // running
|
||||
5, // queue depth (low)
|
||||
1, // active
|
||||
None,
|
||||
);
|
||||
assert!(matches!(decision, ScalingDecision::Hold));
|
||||
|
||||
@@ -96,8 +96,15 @@ mod tests {
|
||||
cache.lock().unwrap().store(100, key, "Voiced line.".into());
|
||||
|
||||
let result = voiced_behavior(
|
||||
&cache, 100, "van-maanens-star", 42, ContentType::Behavior, 0, None,
|
||||
"Base line.", false,
|
||||
&cache,
|
||||
100,
|
||||
"van-maanens-star",
|
||||
42,
|
||||
ContentType::Behavior,
|
||||
0,
|
||||
None,
|
||||
"Base line.",
|
||||
false,
|
||||
);
|
||||
assert_eq!(result, "Voiced line.");
|
||||
}
|
||||
@@ -106,8 +113,15 @@ mod tests {
|
||||
fn cache_miss_returns_base_text() {
|
||||
let cache = test_cache();
|
||||
let result = voiced_behavior(
|
||||
&cache, 100, "van-maanens-star", 42, ContentType::Behavior, 0, None,
|
||||
"Base line.", false,
|
||||
&cache,
|
||||
100,
|
||||
"van-maanens-star",
|
||||
42,
|
||||
ContentType::Behavior,
|
||||
0,
|
||||
None,
|
||||
"Base line.",
|
||||
false,
|
||||
);
|
||||
assert_eq!(result, "Base line.");
|
||||
}
|
||||
@@ -156,8 +170,15 @@ mod tests {
|
||||
cache.lock().unwrap().store(100, key, "Voiced tell.".into());
|
||||
|
||||
let result = voiced_behavior(
|
||||
&cache, 100, "van-maanens-star", 42, ContentType::Behavior, 0,
|
||||
Some(TellCategory::Angry), "Base tell.", true,
|
||||
&cache,
|
||||
100,
|
||||
"van-maanens-star",
|
||||
42,
|
||||
ContentType::Behavior,
|
||||
0,
|
||||
Some(TellCategory::Angry),
|
||||
"Base tell.",
|
||||
true,
|
||||
);
|
||||
assert_eq!(result, "Base tell.");
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ pub fn build_prompt(
|
||||
if rng.random::<f32>() < injection.frequency {
|
||||
parts.push(String::new());
|
||||
// Imperative framing — no "when" conditional, just "include this"
|
||||
parts.push(format!("INJECT: Include the phrase from this example in your output."));
|
||||
parts.push("INJECT: Include the phrase from this example in your output.".to_string());
|
||||
if let Some(ref example) = injection.example {
|
||||
parts.push(format!("INPUT: {}", example.input));
|
||||
parts.push(format!("OUTPUT: {}", example.output));
|
||||
@@ -367,7 +367,7 @@ pub fn build_prompt(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::npc::blueprint::{
|
||||
CultureProfile, CulturalValues, NamingConventions, OccasionalInjection, SpeechPatterns,
|
||||
CulturalValues, CultureProfile, NamingConventions, OccasionalInjection, SpeechPatterns,
|
||||
VoiceExample,
|
||||
};
|
||||
use crate::npc::PersonalityTrait;
|
||||
@@ -401,12 +401,10 @@ mod tests {
|
||||
2. You're working-class and pragmatic."
|
||||
.into(),
|
||||
),
|
||||
voice_examples: vec![
|
||||
VoiceExample {
|
||||
input: "declines to answer a question".into(),
|
||||
output: "Look, that's not mine to say.".into(),
|
||||
},
|
||||
],
|
||||
voice_examples: vec![VoiceExample {
|
||||
input: "declines to answer a question".into(),
|
||||
output: "Look, that's not mine to say.".into(),
|
||||
}],
|
||||
occasional_injections: vec![OccasionalInjection {
|
||||
kind: "oath".into(),
|
||||
clause: "When something surprises you, use an oath like \"void take it.\"".into(),
|
||||
@@ -467,7 +465,9 @@ mod tests {
|
||||
fn prompt_contains_persona_when_present() {
|
||||
let culture = van_maanens_star_culture();
|
||||
let result = build_prompt(&culture, "Hello.", ContentType::Dialogue, None, 42);
|
||||
assert!(result.prompt.contains("PERSONA: You are a Van Maanen's Star station worker"));
|
||||
assert!(result
|
||||
.prompt
|
||||
.contains("PERSONA: You are a Van Maanen's Star station worker"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -87,6 +87,12 @@ pub struct VoiceQueue {
|
||||
paused: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl Default for VoiceQueue {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl VoiceQueue {
|
||||
pub fn new() -> Self {
|
||||
let (sender, receiver) = crossbeam_channel::bounded(QUEUE_CAPACITY);
|
||||
|
||||
@@ -165,9 +165,13 @@ impl VoicePipe {
|
||||
.spawn()
|
||||
.map_err(|e| format!("failed to spawn sr-voice: {}", e))?;
|
||||
|
||||
let stdin = child.stdin.take()
|
||||
let stdin = child
|
||||
.stdin
|
||||
.take()
|
||||
.ok_or_else(|| "failed to capture sr-voice stdin".to_string())?;
|
||||
let stdout = child.stdout.take()
|
||||
let stdout = child
|
||||
.stdout
|
||||
.take()
|
||||
.ok_or_else(|| "failed to capture sr-voice stdout".to_string())?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
Reference in New Issue
Block a user