From 826a437d083590b1384d235504fbf31e36e2b01e Mon Sep 17 00:00:00 2001 From: Rodolfo Olivieri Date: Mon, 11 May 2026 19:47:31 -0300 Subject: [PATCH] chore: replace lazy_static with std::sync::LazyLock (#8815) Signed-off-by: Rodolfo Olivieri --- Cargo.lock | 1 - crates/goose/Cargo.toml | 1 - crates/goose/src/security/patterns.rs | 20 +++++++++----------- crates/goose/tests/providers.rs | 7 +++---- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 895705eb89..c300a3ea9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4412,7 +4412,6 @@ dependencies = [ "jsonschema", "jsonwebtoken", "keyring", - "lazy_static", "libc", "llama-cpp-2", "lru", diff --git a/crates/goose/Cargo.toml b/crates/goose/Cargo.toml index f26a262327..95ac5f73e3 100644 --- a/crates/goose/Cargo.toml +++ b/crates/goose/Cargo.toml @@ -99,7 +99,6 @@ base64 = { workspace = true } url = { workspace = true } axum = { workspace = true, features = ["ws"] } webbrowser = { workspace = true } -lazy_static = "1.5.0" tracing = { workspace = true } tracing-subscriber = { workspace = true } tracing-futures = { workspace = true } diff --git a/crates/goose/src/security/patterns.rs b/crates/goose/src/security/patterns.rs index 0ab8b40264..df8173f54a 100644 --- a/crates/goose/src/security/patterns.rs +++ b/crates/goose/src/security/patterns.rs @@ -1,6 +1,6 @@ -use lazy_static::lazy_static; use regex::Regex; use std::collections::HashMap; +use std::sync::LazyLock; /// Security threat patterns for command injection detection /// These patterns detect dangerous shell commands and injection attempts @@ -315,17 +315,15 @@ pub const THREAT_PATTERNS: &[ThreatPattern] = &[ }, ]; -lazy_static! { - static ref COMPILED_PATTERNS: HashMap<&'static str, Regex> = { - let mut patterns = HashMap::new(); - for threat in THREAT_PATTERNS { - if let Ok(regex) = Regex::new(&format!("(?i){}", threat.pattern)) { - patterns.insert(threat.name, regex); - } +static COMPILED_PATTERNS: LazyLock> = LazyLock::new(|| { + let mut patterns = HashMap::new(); + for threat in THREAT_PATTERNS { + if let Ok(regex) = Regex::new(&format!("(?i){}", threat.pattern)) { + patterns.insert(threat.name, regex); } - patterns - }; -} + } + patterns +}); /// Pattern matcher for detecting security threats pub struct PatternMatcher { diff --git a/crates/goose/tests/providers.rs b/crates/goose/tests/providers.rs index 045f657747..1fa05facea 100644 --- a/crates/goose/tests/providers.rs +++ b/crates/goose/tests/providers.rs @@ -90,10 +90,9 @@ impl TestReport { } } -lazy_static::lazy_static! { - static ref TEST_REPORT: Arc = TestReport::new(); - static ref ENV_LOCK: Mutex<()> = Mutex::new(()); -} +static TEST_REPORT: std::sync::LazyLock> = + std::sync::LazyLock::new(TestReport::new); +static ENV_LOCK: std::sync::LazyLock> = std::sync::LazyLock::new(|| Mutex::new(())); struct ProviderFixture { name: String,