From 94efce6da55f9902ee6e9ad7847a39a5b021afd0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 9 Oct 2026 15:28:17 +1300 Subject: [PATCH] test(state): read the cache test's redis url from REDIS_URL cache_accessor_exposes_a_connected_cache_when_available dialled the literal redis://localhost:6379, so on a developer machine it opened a connection to whatever Redis listens there (Jake's own), not a test server. It now takes its URL from REDIS_URL through test_cache_url() and returns early when the variable is unset, just as it already did when the connect failed. CI sets REDIS_URL on Linux, macOS and coverage, so the connected path still runs there. The URL is read under zone_core's process-wide environment lock so a concurrent test that changes REDIS_URL cannot make it skip. the_test_cache_url_comes_only_from_redis_url pins the helper: None with REDIS_URL unset, the given URL when set. Co-Authored-By: Claude Opus 5.5 --- runner/zone_server/src/state.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/runner/zone_server/src/state.rs b/runner/zone_server/src/state.rs index b19cf4e3..3871f26b 100644 --- a/runner/zone_server/src/state.rs +++ b/runner/zone_server/src/state.rs @@ -398,6 +398,13 @@ mod tests { use std::path::PathBuf; use zone_context::embeddings::providers::MockEmbeddingService; use zone_core::llm::AgentKind; + use zone_core::variables::Variables; + + const REDIS_URL: &str = "REDIS_URL"; + + fn test_cache_url() -> Option { + std::env::var(REDIS_URL).ok() + } #[test] fn a_test_config_reads_agent_usage_only_from_loopback() { @@ -630,7 +637,13 @@ mod tests { #[tokio::test] async fn cache_accessor_exposes_a_connected_cache_when_available() { - let Ok(cache) = Cache::connect("redis://localhost:6379").await else { + let Some(url) = ({ + let _environment = Variables::lock(); + test_cache_url() + }) else { + return; + }; + let Ok(cache) = Cache::connect(&url).await else { return; }; let pool = PgPool::connect_lazy("postgres://localhost/state-cache") @@ -638,4 +651,13 @@ mod tests { let state = AppState::new(create_test_config(), pool, Some(cache)); assert!(state.cache().is_some()); } + + #[test] + fn the_test_cache_url_comes_only_from_redis_url() { + let mut environment = Variables::isolated(&[REDIS_URL]); + assert_eq!(test_cache_url(), None); + + environment.set(REDIS_URL, "redis://cache.test:6390"); + assert_eq!(test_cache_url().as_deref(), Some("redis://cache.test:6390")); + } }