From 7f892275e31002f0422477c6219189284560e689 Mon Sep 17 00:00:00 2001 From: alishobeiri-oai Date: Sun, 4 Oct 2026 22:58:20 +0000 Subject: [PATCH] Isolate tracing in the strict third-party tool deferral test (#50977) ## Why The warning assertions need tracing callsite interest to remain independent of untraced parallel tests, even when the test runner already owns the global subscriber. ## What changed Run the test on a current-thread Tokio runtime and capture warnings with a thread-local subscriber and an explicit buffer. Keep a `NoSubscriber` dispatch alive to stabilize callsite interest, and assert the deferral warning and `client_echo` directly against the captured logs. GitOrigin-RevId: 5bf22b2cbfefcf8f65016d2cc1444112d9f6a6c7 --- .../spec_plan_strict_third_party_tests.rs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/tools/spec_plan_strict_third_party_tests.rs b/codex-rs/core/src/tools/spec_plan_strict_third_party_tests.rs index 197a82b7e7..4b3b66f2bc 100644 --- a/codex-rs/core/src/tools/spec_plan_strict_third_party_tests.rs +++ b/codex-rs/core/src/tools/spec_plan_strict_third_party_tests.rs @@ -3,10 +3,22 @@ use super::*; use crate::tools::registry::ToolRegistry; use codex_extension_api::ToolPolicy; use pretty_assertions::assert_eq; +use tracing_test::internal::MockWriter; -#[tokio::test] -#[tracing_test::traced_test] +#[tokio::test(flavor = "current_thread")] async fn strict_defers_third_party_tools_despite_caller_settings_and_logs_overrides() { + let buffer: &'static std::sync::Mutex> = + Box::leak(Box::new(std::sync::Mutex::new(Vec::new()))); + let subscriber = tracing_subscriber::fmt() + .with_ansi(false) + .without_time() + .with_max_level(tracing::Level::WARN) + .with_writer(MockWriter::new(buffer)) + .finish(); + // Keep callsite interest independent of untraced parallel test threads. + let _untraced = tracing::Dispatch::new(tracing::subscriber::NoSubscriber::default()); + // The test runner may already own the global subscriber. + let _subscriber = tracing::subscriber::set_default(subscriber); for supports_search_tool in [false, true] { let plan = probe_with( |turn| { @@ -92,10 +104,13 @@ async fn strict_defers_third_party_tools_despite_caller_settings_and_logs_overri "warnings must not enter the model prompt" ); } - assert!(logs_contain( - "Deferring third-party tool because code_mode_only_strict_3p_tools is enabled" - )); - assert!(logs_contain("client_echo")); + let logs = String::from_utf8(buffer.lock().unwrap().clone()).unwrap(); + assert!( + logs.contains( + "Deferring third-party tool because code_mode_only_strict_3p_tools is enabled" + ) + ); + assert!(logs.contains("client_echo")); } #[tokio::test]