From 1f3496e4ed2d56a126c08e4ed877d072b5d2e43d Mon Sep 17 00:00:00 2001 From: jars Date: Sat, 9 May 2026 11:14:24 +0100 Subject: [PATCH] feat(core): add PowerState skeleton in new power module Introduces crates/core/src/power.rs with the PowerState enum (OnAc / OnBattery / Unknown) and a unit test confirming the three variants are distinct. Registers the module in lib.rs and adds tempfile = "3" to dev-dependencies for use in later tasks. Co-Authored-By: Claude Opus 4.7 (1M context) --- Cargo.lock | 1 + crates/core/Cargo.toml | 3 +++ crates/core/src/lib.rs | 1 + crates/core/src/power.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 crates/core/src/power.rs diff --git a/Cargo.lock b/Cargo.lock index 9ecc0aa..cddd331 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2859,6 +2859,7 @@ dependencies = [ "serde", "serde_json", "sysinfo", + "tempfile", "thiserror 2.0.18", ] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 1ac7d0d..4fae7aa 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -11,3 +11,6 @@ thiserror = "2" sysinfo = "0.35" async-trait = "0.1" num_cpus = "1" + +[dev-dependencies] +tempfile = "3" diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 3845d15..1e48006 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -5,6 +5,7 @@ pub mod model_registry; pub mod paths; pub mod process_watch; pub mod recommendation; +pub mod power; pub mod types; pub use error::{MagnotiaError, Result}; diff --git a/crates/core/src/power.rs b/crates/core/src/power.rs new file mode 100644 index 0000000..37000f0 --- /dev/null +++ b/crates/core/src/power.rs @@ -0,0 +1,27 @@ +//! Power-state probe for inference thread tuning. +//! +//! Reports whether the machine is running on AC or battery so callers +//! can drop thread counts when energy matters more than throughput. +//! Linux uses the documented sysfs ABI under +//! `/sys/class/power_supply/`. macOS and Windows return `Unknown` for +//! now; native probes (IOPSGetProvidingPowerSourceType, +//! GetSystemPowerStatus) are deferred. + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PowerState { + OnAc, + OnBattery, + Unknown, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn power_state_variants_are_distinct() { + assert_ne!(PowerState::OnAc, PowerState::OnBattery); + assert_ne!(PowerState::OnAc, PowerState::Unknown); + assert_ne!(PowerState::OnBattery, PowerState::Unknown); + } +}