From e9418c790c5d5c8196b2ce625292876ece386520 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 8 Jan 2026 00:30:52 -0800 Subject: [PATCH] fix: leverage find_resource! macro in load_sse_fixture_with_id --- codex-rs/core/tests/common/lib.rs | 12 +++++++++++- codex-rs/core/tests/suite/client.rs | 2 +- codex-rs/core/tests/suite/fork_thread.rs | 2 +- codex-rs/core/tests/suite/model_tools.rs | 2 +- codex-rs/core/tests/suite/prompt_caching.rs | 2 +- .../tests/suite/stream_error_allows_next_turn.rs | 2 +- codex-rs/core/tests/suite/stream_no_completed.rs | 2 +- codex-rs/core/tests/suite/web_search_cached.rs | 2 +- 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/codex-rs/core/tests/common/lib.rs b/codex-rs/core/tests/common/lib.rs index 45e8b0b46f3..7b593f63f03 100644 --- a/codex-rs/core/tests/common/lib.rs +++ b/codex-rs/core/tests/common/lib.rs @@ -1,5 +1,6 @@ #![expect(clippy::expect_used)] +use codex_utils_cargo_bin::find_resource; use tempfile::TempDir; use codex_core::CodexThread; @@ -150,7 +151,16 @@ pub fn load_sse_fixture_with_id_from_str(raw: &str, id: &str) -> String { /// single JSON template be reused by multiple tests that each need a unique /// `response_id`. pub fn load_sse_fixture_with_id(path: impl AsRef, id: &str) -> String { - let raw = std::fs::read_to_string(path).expect("read fixture template"); + let p = path.as_ref(); + let full_path = match find_resource!(p) { + Ok(p) => p, + Err(err) => panic!( + "failed to find fixture template at {:?}: {err}", + path.as_ref() + ), + }; + + let raw = std::fs::read_to_string(full_path).expect("read fixture template"); let replaced = raw.replace("__ID__", id); let events: Vec = serde_json::from_str(&replaced).expect("parse JSON fixture"); diff --git a/codex-rs/core/tests/suite/client.rs b/codex-rs/core/tests/suite/client.rs index 2c08083ba5a..99cc57c06eb 100644 --- a/codex-rs/core/tests/suite/client.rs +++ b/codex-rs/core/tests/suite/client.rs @@ -58,7 +58,7 @@ use wiremock::matchers::query_param; /// Build minimal SSE stream with completed marker using the JSON fixture. fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[expect(clippy::unwrap_used)] diff --git a/codex-rs/core/tests/suite/fork_thread.rs b/codex-rs/core/tests/suite/fork_thread.rs index 50a6dba1fbb..b0b3f722620 100644 --- a/codex-rs/core/tests/suite/fork_thread.rs +++ b/codex-rs/core/tests/suite/fork_thread.rs @@ -22,7 +22,7 @@ use wiremock::matchers::path; /// Build minimal SSE stream with completed marker using the JSON fixture. fn sse_completed(id: &str) -> String { - core_test_support::load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + core_test_support::load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/codex-rs/core/tests/suite/model_tools.rs b/codex-rs/core/tests/suite/model_tools.rs index cb2c5725f2b..106bbd85c9f 100644 --- a/codex-rs/core/tests/suite/model_tools.rs +++ b/codex-rs/core/tests/suite/model_tools.rs @@ -7,7 +7,7 @@ use core_test_support::skip_if_no_network; use core_test_support::test_codex::test_codex; fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[allow(clippy::expect_used)] diff --git a/codex-rs/core/tests/suite/prompt_caching.rs b/codex-rs/core/tests/suite/prompt_caching.rs index bde146ed47c..da0d0112089 100644 --- a/codex-rs/core/tests/suite/prompt_caching.rs +++ b/codex-rs/core/tests/suite/prompt_caching.rs @@ -44,7 +44,7 @@ fn default_env_context_str(cwd: &str, shell: &Shell) -> String { /// Build minimal SSE stream with completed marker using the JSON fixture. fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } fn assert_tool_names(body: &serde_json::Value, expected_names: &[&str]) { diff --git a/codex-rs/core/tests/suite/stream_error_allows_next_turn.rs b/codex-rs/core/tests/suite/stream_error_allows_next_turn.rs index e7a60912643..65313072dc3 100644 --- a/codex-rs/core/tests/suite/stream_error_allows_next_turn.rs +++ b/codex-rs/core/tests/suite/stream_error_allows_next_turn.rs @@ -16,7 +16,7 @@ use wiremock::matchers::method; use wiremock::matchers::path; fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/codex-rs/core/tests/suite/stream_no_completed.rs b/codex-rs/core/tests/suite/stream_no_completed.rs index a203658c2fd..830c0917b51 100644 --- a/codex-rs/core/tests/suite/stream_no_completed.rs +++ b/codex-rs/core/tests/suite/stream_no_completed.rs @@ -25,7 +25,7 @@ fn sse_incomplete() -> String { } fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/codex-rs/core/tests/suite/web_search_cached.rs b/codex-rs/core/tests/suite/web_search_cached.rs index fa8e303d809..b6900a4c2dc 100644 --- a/codex-rs/core/tests/suite/web_search_cached.rs +++ b/codex-rs/core/tests/suite/web_search_cached.rs @@ -10,7 +10,7 @@ use pretty_assertions::assert_eq; use serde_json::Value; fn sse_completed(id: &str) -> String { - load_sse_fixture_with_id("tests/fixtures/completed_template.json", id) + load_sse_fixture_with_id("../fixtures/completed_template.json", id) } #[allow(clippy::expect_used)]