From 46dfcfbb11649b57b6edd8ae08d1af7db47f1bef Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 22 Feb 2026 02:49:42 +0100 Subject: [PATCH] fix(risk): fix circuit_breaker position_limit_zero_portfolio test Replace RealBrokerClient (which connects to localhost:50054) with MockBrokerService in test, so it runs without a live broker. All 209 risk tests now pass. Co-Authored-By: Claude Opus 4.6 --- risk/src/circuit_breaker.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/risk/src/circuit_breaker.rs b/risk/src/circuit_breaker.rs index 111507c0e..1df6f6343 100644 --- a/risk/src/circuit_breaker.rs +++ b/risk/src/circuit_breaker.rs @@ -798,6 +798,36 @@ mod tests { use tokio; // CANONICAL TYPE IMPORTS - Use types::prelude for dec! macro + /// Mock broker service for unit tests that don't require a real broker connection + struct MockBrokerService { + portfolio_value: Decimal, + daily_pnl: Decimal, + } + + impl MockBrokerService { + fn with_zero_portfolio() -> Self { + Self { + portfolio_value: Decimal::ZERO, + daily_pnl: Decimal::ZERO, + } + } + } + + #[async_trait] + impl BrokerAccountService for MockBrokerService { + async fn get_portfolio_value(&self, _account_id: &str) -> RiskResult { + Ok(self.portfolio_value) + } + + async fn get_daily_pnl(&self, _account_id: &str) -> RiskResult { + Ok(self.daily_pnl) + } + + async fn get_positions(&self, _account_id: &str) -> RiskResult> { + Ok(Vec::new()) + } + } + fn create_test_config() -> Result> { Ok(CircuitBreakerConfig { enabled: true, @@ -876,7 +906,8 @@ mod tests { async fn test_circuit_breaker_position_limit_zero_portfolio( ) -> Result<(), Box> { let config = create_test_config()?; - let broker_service = Arc::new(RealBrokerClient::new("http://localhost:50054".to_string())); + let broker_service: Arc = + Arc::new(MockBrokerService::with_zero_portfolio()); if let Ok(circuit_breaker) = RealCircuitBreaker::new(config, broker_service).await { let account_id = "TEST_ACCOUNT";