mirror of
https://github.com/openai/codex.git
synced 2026-04-26 15:45:02 +00:00
remove get_responses_requests and get_responses_request_bodies to use in-place matcher (#8858)
This commit is contained in:
@@ -70,6 +70,10 @@ impl ResponsesRequest {
|
||||
self.0.body_json().unwrap()
|
||||
}
|
||||
|
||||
pub fn body_bytes(&self) -> Vec<u8> {
|
||||
self.0.body.clone()
|
||||
}
|
||||
|
||||
/// Returns all `input_text` spans from `message` inputs for the provided role.
|
||||
pub fn message_input_texts(&self, role: &str) -> Vec<String> {
|
||||
self.inputs_of_type("message")
|
||||
@@ -701,33 +705,6 @@ pub async fn start_mock_server() -> MockServer {
|
||||
server
|
||||
}
|
||||
|
||||
// todo(aibrahim): remove this and use our search matching patterns directly
|
||||
/// Get all POST requests to `/responses` endpoints from the mock server.
|
||||
/// Filters out GET requests (e.g., `/models`) .
|
||||
pub async fn get_responses_requests(server: &MockServer) -> Vec<wiremock::Request> {
|
||||
server
|
||||
.received_requests()
|
||||
.await
|
||||
.expect("mock server should not fail")
|
||||
.into_iter()
|
||||
.filter(|req| req.method == "POST" && req.url.path().ends_with("/responses"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
// todo(aibrahim): remove this and use our search matching patterns directly
|
||||
/// Get request bodies as JSON values from POST requests to `/responses` endpoints.
|
||||
/// Filters out GET requests (e.g., `/models`) .
|
||||
pub async fn get_responses_request_bodies(server: &MockServer) -> Vec<Value> {
|
||||
get_responses_requests(server)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|req| {
|
||||
req.body_json::<Value>()
|
||||
.expect("request body to be valid JSON")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FunctionCallResponseMocks {
|
||||
pub function_call: ResponseMock,
|
||||
|
||||
@@ -23,10 +23,11 @@ use tempfile::TempDir;
|
||||
use wiremock::MockServer;
|
||||
|
||||
use crate::load_default_config_for_test;
|
||||
use crate::responses::get_responses_request_bodies;
|
||||
use crate::responses::start_mock_server;
|
||||
use crate::streaming_sse::StreamingSseServer;
|
||||
use crate::wait_for_event;
|
||||
use wiremock::Match;
|
||||
use wiremock::matchers::path_regex;
|
||||
|
||||
type ConfigMutator = dyn FnOnce(&mut Config) + Send;
|
||||
type PreBuildHook = dyn FnOnce(&Path) + Send + 'static;
|
||||
@@ -322,7 +323,18 @@ impl TestCodexHarness {
|
||||
}
|
||||
|
||||
pub async fn request_bodies(&self) -> Vec<Value> {
|
||||
get_responses_request_bodies(&self.server).await
|
||||
let path_matcher = path_regex(".*/responses$");
|
||||
self.server
|
||||
.received_requests()
|
||||
.await
|
||||
.expect("mock server should not fail")
|
||||
.into_iter()
|
||||
.filter(|req| path_matcher.matches(req))
|
||||
.map(|req| {
|
||||
req.body_json::<Value>()
|
||||
.expect("request body to be valid JSON")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub async fn function_call_output_value(&self, call_id: &str) -> Value {
|
||||
|
||||
Reference in New Issue
Block a user