From 92a11c3c72b0dd65ad194caea737aa7d297e6546 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 24 Jun 2026 23:22:12 +0300 Subject: [PATCH] style(v0.3): rustfmt power FSM/service/integration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Прогон cargo fmt (гейт lint): многострочное форматирование match-веток FSM, PowerMock/PowerService-литералов, integration-вызовов. Без изменений логики. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Alexander --- crates/core/shturman-power/src/fsm.rs | 85 +++++++++++++++---- crates/core/shturman-power/src/service.rs | 8 +- .../core/shturman-power/tests/integration.rs | 12 ++- 3 files changed, 86 insertions(+), 19 deletions(-) diff --git a/crates/core/shturman-power/src/fsm.rs b/crates/core/shturman-power/src/fsm.rs index d9b4a6b..0f76a05 100644 --- a/crates/core/shturman-power/src/fsm.rs +++ b/crates/core/shturman-power/src/fsm.rs @@ -13,7 +13,10 @@ pub enum State { Off, Accessory, Running, - ShuttingDown { phase: Phase, reason: ShutdownReason }, + ShuttingDown { + phase: Phase, + reason: ShutdownReason, + }, Sleep, // зарезервировано (полные sleep/wake — v1/v2) BatteryCutoff, // зарезервировано (long-park — v1/v2) } @@ -44,7 +47,9 @@ pub struct PowerFsm { impl Default for PowerFsm { fn default() -> Self { - Self { state: State::Running } + Self { + state: State::Running, + } } } @@ -78,7 +83,10 @@ impl PowerFsm { /// Источник питания — сигнал потребителям «времени мало» при shutdown. pub fn source(&self) -> PowerSource { match self.state { - State::ShuttingDown { reason: ShutdownReason::UnderVoltage, .. } => PowerSource::LowBattery, + State::ShuttingDown { + reason: ShutdownReason::UnderVoltage, + .. + } => PowerSource::LowBattery, State::ShuttingDown { .. } => PowerSource::HoldupCap, _ => PowerSource::Vehicle12v, } @@ -104,7 +112,10 @@ impl PowerFsm { } // ACC-off: линия ACC сменилась (AccChanged) + старт shutdown. (Accessory | Running, E::AccOff) => { - self.state = ShuttingDown { phase: Abortable, reason: ShutdownReason::AccOff }; + self.state = ShuttingDown { + phase: Abortable, + reason: ShutdownReason::AccOff, + }; vec![ Action::AccChanged(false), Action::ShutdownImminent(ShutdownReason::AccOff), @@ -112,14 +123,30 @@ impl PowerFsm { ] } // under-voltage/thermal: ACC не менялся → без AccChanged. - (Accessory | Running, E::UnderVoltage) => self.begin_shutdown(ShutdownReason::UnderVoltage), + (Accessory | Running, E::UnderVoltage) => { + self.begin_shutdown(ShutdownReason::UnderVoltage) + } (Accessory | Running, E::ThermalTrip) => self.begin_shutdown(ShutdownReason::Thermal), - (ShuttingDown { phase: Abortable, .. }, E::AccOn) => { + ( + ShuttingDown { + phase: Abortable, .. + }, + E::AccOn, + ) => { self.state = Running; vec![Action::ShutdownAborted, Action::AccChanged(true)] } - (ShuttingDown { phase: Abortable, reason }, E::GraceExpired) => { - self.state = ShuttingDown { phase: Committed, reason }; + ( + ShuttingDown { + phase: Abortable, + reason, + }, + E::GraceExpired, + ) => { + self.state = ShuttingDown { + phase: Committed, + reason, + }; vec![Action::Commit] } // committed/off/sleep/battery_cutoff + всё прочее — no-op (committed не abort-ится) @@ -128,7 +155,10 @@ impl PowerFsm { } fn begin_shutdown(&mut self, reason: ShutdownReason) -> Vec { - self.state = State::ShuttingDown { phase: Phase::Abortable, reason }; + self.state = State::ShuttingDown { + phase: Phase::Abortable, + reason, + }; vec![Action::ShutdownImminent(reason), Action::StartGrace] } } @@ -146,7 +176,9 @@ mod tests { #[test] fn accessory_engine_on_to_running_and_back() { - let mut f = PowerFsm { state: State::Accessory }; + let mut f = PowerFsm { + state: State::Accessory, + }; assert_eq!(f.step(Event::EngineOn), vec![]); assert_eq!(f.state(), State::Running); assert_eq!(f.step(Event::EngineOff), vec![]); @@ -193,20 +225,43 @@ mod tests { f.step(Event::AccOff); assert_eq!(f.step(Event::GraceExpired), vec![Action::Commit]); assert_eq!(f.step(Event::AccOn), vec![]); // committed: abort игнорируется - assert!(matches!(f.state(), State::ShuttingDown { phase: Phase::Committed, .. })); + assert!(matches!( + f.state(), + State::ShuttingDown { + phase: Phase::Committed, + .. + } + )); } #[test] fn reserved_states_noop() { - let mut f = PowerFsm { state: State::Sleep }; + let mut f = PowerFsm { + state: State::Sleep, + }; assert_eq!(f.step(Event::AccOn), vec![]); assert_eq!(f.state(), State::Sleep); } #[test] fn ignition_projection() { - assert_eq!(PowerFsm { state: State::Running }.ignition(), IgnitionState::Running); - assert_eq!(PowerFsm { state: State::Accessory }.ignition(), IgnitionState::Accessory); - assert_eq!(PowerFsm { state: State::Off }.ignition(), IgnitionState::Off); + assert_eq!( + PowerFsm { + state: State::Running + } + .ignition(), + IgnitionState::Running + ); + assert_eq!( + PowerFsm { + state: State::Accessory + } + .ignition(), + IgnitionState::Accessory + ); + assert_eq!( + PowerFsm { state: State::Off }.ignition(), + IgnitionState::Off + ); } } diff --git a/crates/core/shturman-power/src/service.rs b/crates/core/shturman-power/src/service.rs index d89e753..4fe5a4f 100644 --- a/crates/core/shturman-power/src/service.rs +++ b/crates/core/shturman-power/src/service.rs @@ -18,7 +18,9 @@ pub struct PowerService { impl Default for PowerService { fn default() -> Self { - Self { fsm: Arc::new(Mutex::new(PowerFsm::new())) } + Self { + fsm: Arc::new(Mutex::new(PowerFsm::new())), + } } } @@ -38,7 +40,9 @@ impl PowerService { #[cfg(feature = "dev-mocks")] pub fn mock(&self) -> PowerMock { - PowerMock { fsm: Arc::clone(&self.fsm) } + PowerMock { + fsm: Arc::clone(&self.fsm), + } } } diff --git a/crates/core/shturman-power/tests/integration.rs b/crates/core/shturman-power/tests/integration.rs index c7a3637..e38afea 100644 --- a/crates/core/shturman-power/tests/integration.rs +++ b/crates/core/shturman-power/tests/integration.rs @@ -55,8 +55,16 @@ async fn shutdown_imminent_then_abort() { let svc = PowerService::new(); let mock = svc.mock(); let server = zbus::Connection::session().await.unwrap(); - server.object_server().at(names::power::PATH, svc).await.unwrap(); - server.object_server().at(names::power::PATH, mock).await.unwrap(); + server + .object_server() + .at(names::power::PATH, svc) + .await + .unwrap(); + server + .object_server() + .at(names::power::PATH, mock) + .await + .unwrap(); server.request_name(names::power::NAME).await.unwrap(); let client = zbus::Connection::session().await.unwrap();