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
This commit is contained in:
alishobeiri-oai
2026-10-04 23:07:12 +00:00
committed by copyberry
parent 4ad985e2ca
commit 7f892275e3
@@ -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<Vec<u8>> =
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]