mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Forward thread originators from standalone extensions (#33677)
## Why Standalone web search and image requests need to preserve the trusted, thread-scoped originator used for billing attribution. ## What changed - Seed extension data with the resolved thread originator and recognize `codex_work_cca` and `chatgpt_cca` service names as originators. - Forward non-default originators from the web search and image generation extensions with the shared originator-header helper. ## Testing - Cover originator resolution, header validation, and forwarding for web search, image generation, and image editing. GitOrigin-RevId: 165dace8e4d24e4bd92f234bff5ec77a21a7ff6e
This commit is contained in:
committed by
copyberry
parent
71448a29e7
commit
78ba047bda
@@ -95,7 +95,14 @@ async fn standalone_image_generation_returns_saved_path_hint_to_model() -> Resul
|
||||
.build()
|
||||
.await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
start_image_generation_turn(&mut mcp).await?;
|
||||
start_image_generation_turn(
|
||||
&mut mcp,
|
||||
ThreadStartParams {
|
||||
service_name: Some("chatgpt_cca".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
let completed = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
@@ -123,6 +130,23 @@ async fn standalone_image_generation_returns_saved_path_hint_to_model() -> Resul
|
||||
assert_eq!(result, RESULT);
|
||||
assert_eq!(std::fs::read(&saved_path)?, TINY_PNG_BYTES);
|
||||
|
||||
let image_request = server
|
||||
.received_requests()
|
||||
.await
|
||||
.context("failed to fetch received requests")?
|
||||
.into_iter()
|
||||
.find(|request| request.url.path() == "/api/codex/images/generations")
|
||||
.context("image generation request should be sent")?;
|
||||
assert_eq!(
|
||||
image_request
|
||||
.headers
|
||||
.get("originator")
|
||||
.context("standalone image generation should include the thread originator")?
|
||||
.to_str()
|
||||
.context("standalone image generation originator should be valid ASCII")?,
|
||||
"chatgpt_cca"
|
||||
);
|
||||
|
||||
let requests = response_mock.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
let output = requests[1].function_call_output(call_id);
|
||||
@@ -196,7 +220,7 @@ async fn standalone_image_generation_failure_emits_terminal_item() -> Result<()>
|
||||
.build()
|
||||
.await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
start_image_generation_turn(&mut mcp).await?;
|
||||
start_image_generation_turn(&mut mcp, ThreadStartParams::default()).await?;
|
||||
|
||||
let completed = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
@@ -325,7 +349,7 @@ async fn standalone_image_generation_is_exposed_in_code_mode_only() -> Result<()
|
||||
.build()
|
||||
.await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
start_image_generation_turn(&mut mcp).await?;
|
||||
start_image_generation_turn(&mut mcp, ThreadStartParams::default()).await?;
|
||||
timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_notification_message("turn/completed"),
|
||||
@@ -391,7 +415,7 @@ generatedImage(result);
|
||||
.build()
|
||||
.await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
start_image_generation_turn(&mut mcp).await?;
|
||||
start_image_generation_turn(&mut mcp, ThreadStartParams::default()).await?;
|
||||
timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_notification_message("turn/completed"),
|
||||
@@ -420,9 +444,13 @@ generatedImage(result);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start_image_generation_turn(mcp: &mut TestAppServer) -> Result<()> {
|
||||
async fn start_image_generation_turn(
|
||||
mcp: &mut TestAppServer,
|
||||
thread_start_params: ThreadStartParams,
|
||||
) -> Result<()> {
|
||||
start_turn(
|
||||
mcp,
|
||||
thread_start_params,
|
||||
vec![V2UserInput::Text {
|
||||
text: "Generate an image".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
@@ -474,7 +502,15 @@ async fn run_image_edit_test(
|
||||
.build()
|
||||
.await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
start_turn(&mut mcp, input).await?;
|
||||
start_turn(
|
||||
&mut mcp,
|
||||
ThreadStartParams {
|
||||
service_name: Some("chatgpt_cca".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
input,
|
||||
)
|
||||
.await?;
|
||||
timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
wait_for_image_generation_completed(&mut mcp),
|
||||
@@ -491,16 +527,29 @@ async fn run_image_edit_test(
|
||||
.received_requests()
|
||||
.await
|
||||
.context("failed to fetch received requests")?;
|
||||
Ok(requests
|
||||
let image_request = requests
|
||||
.iter()
|
||||
.find(|request| request.url.path() == "/api/codex/images/edits")
|
||||
.context("image edit request should be sent")?
|
||||
.body_json::<serde_json::Value>()?)
|
||||
.context("image edit request should be sent")?;
|
||||
assert_eq!(
|
||||
image_request
|
||||
.headers
|
||||
.get("originator")
|
||||
.context("standalone image edit should include the thread originator")?
|
||||
.to_str()
|
||||
.context("standalone image edit originator should be valid ASCII")?,
|
||||
"chatgpt_cca"
|
||||
);
|
||||
Ok(image_request.body_json::<serde_json::Value>()?)
|
||||
}
|
||||
|
||||
async fn start_turn(mcp: &mut TestAppServer, input: Vec<V2UserInput>) -> Result<()> {
|
||||
async fn start_turn(
|
||||
mcp: &mut TestAppServer,
|
||||
thread_start_params: ThreadStartParams,
|
||||
input: Vec<V2UserInput>,
|
||||
) -> Result<()> {
|
||||
let thread_req = mcp
|
||||
.send_thread_start_request_with_auto_env(ThreadStartParams::default())
|
||||
.send_thread_start_request_with_auto_env(thread_start_params)
|
||||
.await?;
|
||||
let thread_resp: JSONRPCResponse = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
|
||||
@@ -100,7 +100,10 @@ async fn standalone_web_search_round_trips_output() -> Result<()> {
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
|
||||
let thread_req = mcp
|
||||
.send_thread_start_request_with_auto_env(ThreadStartParams::default())
|
||||
.send_thread_start_request_with_auto_env(ThreadStartParams {
|
||||
service_name: Some("chatgpt_cca".to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
let thread_resp: JSONRPCResponse = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
@@ -159,6 +162,15 @@ async fn standalone_web_search_round_trips_output() -> Result<()> {
|
||||
);
|
||||
|
||||
let search_request = search_request(&server).await?;
|
||||
assert_eq!(
|
||||
search_request
|
||||
.headers
|
||||
.get("originator")
|
||||
.context("standalone search should include the thread originator")?
|
||||
.to_str()
|
||||
.context("standalone search originator should be valid ASCII")?,
|
||||
"chatgpt_cca"
|
||||
);
|
||||
let search_body = search_request
|
||||
.body_json::<Value>()
|
||||
.context("search request body should be JSON")?;
|
||||
|
||||
Reference in New Issue
Block a user