aKode fase 2b-1 (WIP): rimossi cloud-config, apps MCP ChatGPT, upload file, connectors-extension, rate limits backend; plugin remoti in corso (test non ancora compilanti)
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled
This commit is contained in:
@@ -1,142 +0,0 @@
|
||||
//! Analytics plan discovery must not follow redirects with runtime authentication.
|
||||
|
||||
use anyhow::Result;
|
||||
use base64::Engine;
|
||||
use codex_backend_client::AnalyticsSession;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_login::AuthCredentialsStoreMode;
|
||||
use core_test_support::load_default_config_for_test;
|
||||
use core_test_support::runtime_auth::PROBE_SERVER;
|
||||
use core_test_support::runtime_auth::run_harness_through_proxy_with_env;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn analytics_does_not_follow_runtime_redirects() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let token = format!(
|
||||
"e30.{}.c2ln",
|
||||
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(
|
||||
json!({
|
||||
"exp": 4_102_444_800_u64,
|
||||
"iss": "https://auth.openai.com",
|
||||
"session_id": "session-analytics",
|
||||
"https://api.openai.com/auth": {
|
||||
"chatgpt_user_id": "user-analytics",
|
||||
"chatgpt_account_id": "account-analytics",
|
||||
},
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
);
|
||||
if std::env::var(PROBE_SERVER).is_ok() {
|
||||
for mode in [RuntimeAuthMode::DualHeader, RuntimeAuthMode::AssertionOnly] {
|
||||
let home = tempfile::tempdir()?;
|
||||
codex_login::auth::login_with_chatgpt_auth_tokens(
|
||||
home.path(),
|
||||
&token,
|
||||
"account-analytics",
|
||||
Some("plus"),
|
||||
)?;
|
||||
let mut config = load_default_config_for_test(&home).await;
|
||||
config.chatgpt_base_url = "https://chatgpt.com/backend-api".into();
|
||||
config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::Ephemeral;
|
||||
let result = AnalyticsSession::from_config(
|
||||
&config,
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
Some(mode),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"Analytics must reject a redirected plan response"
|
||||
);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/agent/register"))
|
||||
.respond_with(ResponseTemplate::new(/*s*/ 200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": "runtime-analytics",
|
||||
"agent_host_id": "host-analytics",
|
||||
"actor": {
|
||||
"kind": "chatgpt",
|
||||
"user_id": "user-analytics",
|
||||
"account_id": "account-analytics",
|
||||
},
|
||||
})))
|
||||
.expect(/*r*/ 2)
|
||||
.mount(&server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/backend-api/wham/accounts/check"))
|
||||
.respond_with(ResponseTemplate::new(/*s*/ 307).insert_header(
|
||||
"Location",
|
||||
"https://chatgpt.com/backend-api/redirected-plan",
|
||||
))
|
||||
.expect(/*r*/ 2)
|
||||
.mount(&server)
|
||||
.await;
|
||||
Mock::given(path("/backend-api/redirected-plan"))
|
||||
.respond_with(ResponseTemplate::new(/*s*/ 200).set_body_json(json!({
|
||||
"accounts": [],
|
||||
"account_ordering": [],
|
||||
})))
|
||||
.expect(/*r*/ 0)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
run_harness_through_proxy_with_env(
|
||||
&server,
|
||||
"suite::analytics_runtime_auth::analytics_does_not_follow_runtime_redirects",
|
||||
/*realtime_target*/ None,
|
||||
&[
|
||||
("OPENAI_API_KEY", None),
|
||||
("CODEX_API_KEY", None),
|
||||
("OPENAI_FEDERATION_RULE_ID", None),
|
||||
("OPENAI_IDENTITY_TOKEN_FILE", None),
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
|
||||
let requests = server
|
||||
.received_requests()
|
||||
.await
|
||||
.expect("requests should be recorded");
|
||||
let discovery: Vec<_> = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/backend-api/wham/accounts/check")
|
||||
.collect();
|
||||
assert_eq!(discovery.len(), 2);
|
||||
assert_eq!(
|
||||
discovery[0].headers["authorization"],
|
||||
format!("Bearer {token}")
|
||||
);
|
||||
assert!(
|
||||
discovery[0]
|
||||
.headers
|
||||
.contains_key("x-openai-agent-assertion")
|
||||
);
|
||||
assert!(
|
||||
discovery[1].headers["authorization"]
|
||||
.to_str()?
|
||||
.starts_with("AgentAssertion ")
|
||||
);
|
||||
assert!(
|
||||
!discovery[1]
|
||||
.headers
|
||||
.contains_key("x-openai-agent-assertion")
|
||||
);
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
@@ -48,7 +48,6 @@ mod agent_execution;
|
||||
mod agent_message_wake;
|
||||
mod agent_websocket;
|
||||
mod agents_md;
|
||||
mod analytics_runtime_auth;
|
||||
mod app_tool_exposure;
|
||||
mod apply_patch_cli;
|
||||
mod apply_patch_serialization;
|
||||
@@ -170,7 +169,6 @@ mod multi_agent_tool_descriptions;
|
||||
#[cfg(unix)]
|
||||
mod multi_exec_server_sandbox;
|
||||
mod network_approval;
|
||||
mod openai_file_mcp;
|
||||
mod otel;
|
||||
mod output_token_replay;
|
||||
mod override_updates;
|
||||
@@ -214,8 +212,6 @@ mod rmcp_client;
|
||||
mod rollout_budget;
|
||||
mod rollout_compression;
|
||||
mod rollout_list_find;
|
||||
mod runtime_auth;
|
||||
mod runtime_auth_denials;
|
||||
mod safety_buffering;
|
||||
mod safety_check_downgrade;
|
||||
mod scenarios;
|
||||
|
||||
@@ -1,442 +0,0 @@
|
||||
#![cfg(not(target_os = "windows"))]
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use codex_core::config::Config;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use core_test_support::PathExt;
|
||||
use core_test_support::apps_test_server::AppsTestServer;
|
||||
use core_test_support::apps_test_server::CALENDAR_EXTRACT_TEXT_TOOL_NAME;
|
||||
use core_test_support::apps_test_server::DIRECT_CALENDAR_EXTRACT_TEXT_TOOL as DOCUMENT_EXTRACT_HOOK_MATCHER;
|
||||
use core_test_support::apps_test_server::DOCUMENT_EXTRACT_TEXT_RESOURCE_URI;
|
||||
use core_test_support::apps_test_server::SEARCH_CALENDAR_EXTRACT_TEXT_TOOL as DOCUMENT_EXTRACT_TOOL;
|
||||
use core_test_support::apps_test_server::SEARCH_CALENDAR_NAMESPACE as DOCUMENT_EXTRACT_NAMESPACE;
|
||||
use core_test_support::apps_test_server::apps_enabled_builder;
|
||||
use core_test_support::apps_test_server::recorded_apps_tool_call_by_name;
|
||||
use core_test_support::hooks::trust_discovered_hooks;
|
||||
use core_test_support::responses::ResponseMock;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::ev_function_call_with_namespace;
|
||||
use core_test_support::responses::ev_response_created;
|
||||
use core_test_support::responses::ev_tool_search_call;
|
||||
use core_test_support::responses::mount_sse_sequence;
|
||||
use core_test_support::responses::namespace_child_tool;
|
||||
use core_test_support::responses::sse;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::skip_if_sandbox;
|
||||
use core_test_support::skip_if_target_windows;
|
||||
use core_test_support::test_codex::TestCodex;
|
||||
use core_test_support::test_codex::executor_path_uri;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::body_partial_json;
|
||||
use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
const STREAMED_FILE_SIZE: usize = 2 * 1024 * 1024;
|
||||
|
||||
fn restrict_apps_upload_reads(config: &mut Config, denied_file_name: &str) {
|
||||
let denied_path =
|
||||
AbsolutePathBuf::from_absolute_path(config.cwd.as_path().join(denied_file_name))
|
||||
.expect("denied file path should be absolute");
|
||||
let mut file_system_policy = FileSystemSandboxPolicy::read_only();
|
||||
file_system_policy.entries.push(FileSystemSandboxEntry::new(
|
||||
denied_path.into(),
|
||||
FileSystemAccessMode::Deny,
|
||||
));
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(PermissionProfile::from_runtime_permissions(
|
||||
&file_system_policy,
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
))
|
||||
.expect("test config should allow a restricted read policy");
|
||||
|
||||
let user_config_path = config.codex_home.join("config.toml").abs();
|
||||
let user_config = toml::from_str(
|
||||
r#"
|
||||
[apps.calendar]
|
||||
default_tools_approval_mode = "approve"
|
||||
"#,
|
||||
)
|
||||
.expect("Apps approval config should parse");
|
||||
config.config_layer_stack = config
|
||||
.config_layer_stack
|
||||
.with_user_config(&user_config_path, user_config)
|
||||
.expect("Apps approval config should be valid");
|
||||
}
|
||||
|
||||
fn write_post_tool_use_hook(home: &Path) -> Result<()> {
|
||||
let script_path = home.join("post_tool_use_hook.py");
|
||||
let log_path = home.join("post_tool_use_hook_log.jsonl");
|
||||
let script = format!(
|
||||
r#"import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
payload = json.load(sys.stdin)
|
||||
|
||||
with Path(r"{log_path}").open("a", encoding="utf-8") as handle:
|
||||
handle.write(json.dumps(payload) + "\n")
|
||||
|
||||
print(json.dumps({{
|
||||
"hookSpecificOutput": {{
|
||||
"hookEventName": "PostToolUse",
|
||||
"additionalContext": "observed apps file payload"
|
||||
}}
|
||||
}}))
|
||||
"#,
|
||||
log_path = log_path.display(),
|
||||
);
|
||||
let hooks = serde_json::json!({
|
||||
"hooks": {
|
||||
"PostToolUse": [{
|
||||
"matcher": DOCUMENT_EXTRACT_HOOK_MATCHER,
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": format!("python3 {}", script_path.display()),
|
||||
"statusMessage": "running apps file post tool use hook",
|
||||
}]
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
fs::write(&script_path, script).context("write post tool use hook script")?;
|
||||
fs::write(home.join("hooks.json"), hooks.to_string()).context("write hooks.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_post_tool_use_hook_inputs(home: &Path) -> Result<Vec<Value>> {
|
||||
fs::read_to_string(home.join("post_tool_use_hook_log.jsonl"))
|
||||
.context("read post tool use hook log")?
|
||||
.lines()
|
||||
.filter(|line| !line.trim().is_empty())
|
||||
.map(|line| serde_json::from_str(line).context("parse post tool use hook input"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn schema_filtered_uploaded_file(server: &MockServer) -> Value {
|
||||
json!({
|
||||
"download_url": format!("{}/download/file_123", server.uri()),
|
||||
"file_id": "file_123",
|
||||
})
|
||||
}
|
||||
|
||||
async fn mount_file_upload_mocks(server: &MockServer, file_size_bytes: u64) {
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/files"))
|
||||
.and(header("chatgpt-account-id", "account_id"))
|
||||
.and(body_partial_json(json!({
|
||||
"file_name": "report.txt",
|
||||
"file_size": file_size_bytes,
|
||||
"use_case": "codex",
|
||||
})))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"file_id": "file_123",
|
||||
"upload_url": format!("{}/upload/file_123", server.uri()),
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(server)
|
||||
.await;
|
||||
Mock::given(method("PUT"))
|
||||
.and(path("/upload/file_123"))
|
||||
.and(header("content-length", file_size_bytes.to_string()))
|
||||
.respond_with(ResponseTemplate::new(200))
|
||||
.expect(1)
|
||||
.mount(server)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/files/file_123/uploaded"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"status": "success",
|
||||
"download_url": format!("{}/download/file_123", server.uri()),
|
||||
"file_name": "report.txt",
|
||||
"mime_type": "text/plain",
|
||||
"file_size_bytes": file_size_bytes,
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(server)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn run_extract_turn(
|
||||
test: &TestCodex,
|
||||
server: &MockServer,
|
||||
permission_profile: PermissionProfile,
|
||||
) -> Result<ResponseMock> {
|
||||
let mock = mount_sse_sequence(
|
||||
server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_tool_search_call(
|
||||
"extract-search-1",
|
||||
&json!({
|
||||
"query": "extract text from uploaded document",
|
||||
"limit": 1,
|
||||
}),
|
||||
),
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-2"),
|
||||
ev_function_call_with_namespace(
|
||||
"extract-call-1",
|
||||
DOCUMENT_EXTRACT_NAMESPACE,
|
||||
DOCUMENT_EXTRACT_TOOL,
|
||||
&json!({"file": "report.txt"}).to_string(),
|
||||
),
|
||||
ev_completed("resp-2"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-3"),
|
||||
ev_assistant_message("msg-1", "done"),
|
||||
ev_completed("resp-3"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
test.submit_turn_with_approval_and_permission_profile(
|
||||
"Extract the report text with the app tool.",
|
||||
AskForApproval::Never,
|
||||
permission_profile,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(mock)
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn codex_apps_file_params_omit_fields_absent_from_tool_schema() -> Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
mount_file_upload_mocks(&server, STREAMED_FILE_SIZE as u64).await;
|
||||
|
||||
let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url.clone())
|
||||
.with_workspace_setup(|cwd, fs| async move {
|
||||
let report_path = executor_path_uri(cwd.join("report.txt"))?;
|
||||
fs.write_file(
|
||||
&report_path,
|
||||
vec![b'x'; STREAMED_FILE_SIZE],
|
||||
Default::default(),
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
let mock = run_extract_turn(&test, &server, PermissionProfile::Disabled).await?;
|
||||
|
||||
let requests = mock.requests();
|
||||
let search_output = requests[1].tool_search_output("extract-search-1");
|
||||
let missing_tool_message = format!(
|
||||
"missing tool {DOCUMENT_EXTRACT_NAMESPACE}{DOCUMENT_EXTRACT_TOOL} in tool_search output: {search_output:?}"
|
||||
);
|
||||
let extract_tool = namespace_child_tool(
|
||||
&search_output,
|
||||
DOCUMENT_EXTRACT_NAMESPACE,
|
||||
DOCUMENT_EXTRACT_TOOL,
|
||||
)
|
||||
.expect(&missing_tool_message);
|
||||
assert_eq!(
|
||||
extract_tool.pointer("/parameters/properties/file"),
|
||||
Some(&json!({
|
||||
"type": "string",
|
||||
"description": "Document file payload. This parameter expects an absolute local file path. If you want to upload a file, provide the absolute path to that file here."
|
||||
}))
|
||||
);
|
||||
|
||||
let apps_tool_call =
|
||||
recorded_apps_tool_call_by_name(&server, CALENDAR_EXTRACT_TEXT_TOOL_NAME).await;
|
||||
|
||||
assert_eq!(
|
||||
apps_tool_call.pointer("/params/arguments/file"),
|
||||
Some(&schema_filtered_uploaded_file(&server))
|
||||
);
|
||||
assert_eq!(
|
||||
apps_tool_call.pointer("/params/_meta/_codex_apps"),
|
||||
Some(&json!({
|
||||
"call_id": "extract-call-1",
|
||||
"root_turn_id": requests[0].body_json()["client_metadata"]["turn_id"],
|
||||
"resource_uri": DOCUMENT_EXTRACT_TEXT_RESOURCE_URI,
|
||||
"contains_mcp_source": true,
|
||||
"connector_id": "calendar",
|
||||
}))
|
||||
);
|
||||
let requests = server.received_requests().await.expect("capture requests");
|
||||
let upload_request = requests
|
||||
.iter()
|
||||
.find(|request| request.url.path() == "/files")
|
||||
.expect("app tool should create a Files upload");
|
||||
let upload_body: Value =
|
||||
serde_json::from_slice(&upload_request.body).expect("Files request should be JSON");
|
||||
assert_eq!(
|
||||
upload_body.get("codex_connector_id"),
|
||||
Some(&json!("calendar"))
|
||||
);
|
||||
let thread_id = json!(test.session_configured.session_id);
|
||||
assert_eq!(
|
||||
apps_tool_call.pointer("/params/_meta/threadId"),
|
||||
Some(&thread_id)
|
||||
);
|
||||
assert_eq!(upload_body.get("codex_thread_id"), None);
|
||||
assert_eq!(upload_body.get("upload_source"), None);
|
||||
assert_eq!(upload_body.get("store_in_library"), None);
|
||||
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn codex_apps_file_params_pass_uploaded_file_to_post_tool_use_hook() -> Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
mount_file_upload_mocks(&server, /*file_size_bytes*/ 11).await;
|
||||
|
||||
let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url.clone())
|
||||
.with_pre_build_hook(move |home| {
|
||||
if let Err(error) = write_post_tool_use_hook(home) {
|
||||
panic!("failed to write apps file post tool use hook fixture: {error}");
|
||||
}
|
||||
})
|
||||
.with_config(move |config| {
|
||||
trust_discovered_hooks(config);
|
||||
});
|
||||
let test = builder.build(&server).await?;
|
||||
tokio::fs::write(test.cwd.path().join("report.txt"), b"hello world").await?;
|
||||
let _responses = run_extract_turn(&test, &server, PermissionProfile::Disabled).await?;
|
||||
|
||||
let hook_inputs = read_post_tool_use_hook_inputs(test.codex_home_path())?;
|
||||
assert_eq!(hook_inputs.len(), 1);
|
||||
assert_eq!(
|
||||
hook_inputs[0]["tool_input"]["file"],
|
||||
schema_filtered_uploaded_file(&server)
|
||||
);
|
||||
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn codex_apps_file_params_retry_stream_under_restricted_read_policy() -> Result<()> {
|
||||
skip_if_target_windows!(
|
||||
Ok(()),
|
||||
"Windows restricted-token sandbox cannot enforce deny-read policies"
|
||||
);
|
||||
skip_if_sandbox!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
mount_file_upload_mocks(&server, STREAMED_FILE_SIZE as u64).await;
|
||||
Mock::given(method("PUT"))
|
||||
.and(path("/upload/file_123"))
|
||||
.respond_with(ResponseTemplate::new(503).insert_header("x-ms-retry-after-ms", "0"))
|
||||
.with_priority(1)
|
||||
.up_to_n_times(1)
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url)
|
||||
.with_config(|config| restrict_apps_upload_reads(config, "private.txt"))
|
||||
.with_workspace_setup(|cwd, fs| async move {
|
||||
let report_path = PathUri::from_abs_path(&cwd.join("report.txt"));
|
||||
fs.write_file(
|
||||
&report_path,
|
||||
vec![b'x'; STREAMED_FILE_SIZE],
|
||||
Default::default(),
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
let permission_profile = test.config.permissions.permission_profile().clone();
|
||||
|
||||
run_extract_turn(&test, &server, permission_profile).await?;
|
||||
|
||||
let requests = server.received_requests().await.expect("capture requests");
|
||||
let bodies: Vec<_> = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/upload/file_123")
|
||||
.map(|request| request.body.as_slice())
|
||||
.collect();
|
||||
let contents = vec![b'x'; STREAMED_FILE_SIZE];
|
||||
assert_eq!(bodies, vec![contents.as_slice(); 2]);
|
||||
|
||||
let apps_tool_call =
|
||||
recorded_apps_tool_call_by_name(&server, CALENDAR_EXTRACT_TEXT_TOOL_NAME).await;
|
||||
assert_eq!(
|
||||
apps_tool_call.pointer("/params/arguments/file"),
|
||||
Some(&schema_filtered_uploaded_file(&server))
|
||||
);
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn codex_apps_file_params_reject_denied_file_before_upload() -> Result<()> {
|
||||
skip_if_target_windows!(
|
||||
Ok(()),
|
||||
"Windows restricted-token sandbox cannot enforce deny-read policies"
|
||||
);
|
||||
skip_if_sandbox!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url)
|
||||
.with_config(|config| restrict_apps_upload_reads(config, "report.txt"))
|
||||
.with_workspace_setup(|cwd, fs| async move {
|
||||
let report_path = PathUri::from_abs_path(&cwd.join("report.txt"));
|
||||
fs.write_file(
|
||||
&report_path,
|
||||
b"private".to_vec(),
|
||||
Default::default(),
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
let permission_profile = test.config.permissions.permission_profile().clone();
|
||||
|
||||
let responses = run_extract_turn(&test, &server, permission_profile).await?;
|
||||
let requests = responses.requests();
|
||||
let output_item = requests[2].function_call_output("extract-call-1");
|
||||
let output = output_item["output"][1]["text"]
|
||||
.as_str()
|
||||
.context("denied Apps upload should return a tool error")?;
|
||||
|
||||
assert!(
|
||||
output.contains("failed to upload `report.txt`")
|
||||
&& (output.contains("Permission denied") || output.contains("Operation not permitted")),
|
||||
"unexpected upload error: {output}"
|
||||
);
|
||||
assert!(
|
||||
server
|
||||
.received_requests()
|
||||
.await
|
||||
.context("mock server should expose received requests")?
|
||||
.iter()
|
||||
.all(|request| request.url.path() != "/files"),
|
||||
"denied files must not start an upload"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -75,9 +75,6 @@ use wiremock::matchers::query_param;
|
||||
use super::rmcp_client::remote_aware_environment_id;
|
||||
use super::rmcp_client::remote_aware_stdio_server_bin;
|
||||
|
||||
#[path = "request_plugin_install_runtime_auth.rs"]
|
||||
mod runtime_auth_tests;
|
||||
|
||||
const TOOL_SEARCH_TOOL_NAME: &str = "tool_search";
|
||||
const LIST_AVAILABLE_PLUGINS_TO_INSTALL_TOOL_NAME: &str = "list_available_plugins_to_install";
|
||||
const REQUEST_PLUGIN_INSTALL_TOOL_NAME: &str = "request_plugin_install";
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
//! Exercise recommended-plugin metadata after resuming with another account.
|
||||
|
||||
use super::*;
|
||||
use base64::Engine;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_history::ResumedHistory;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use core_test_support::runtime_auth::PROBE_SERVER;
|
||||
use core_test_support::runtime_auth::run_harness_through_proxy;
|
||||
use pretty_assertions::assert_eq;
|
||||
use test_case::test_case;
|
||||
|
||||
fn actor_token(actor: &str) -> String {
|
||||
let claims = json!({
|
||||
"exp": 4_102_444_800_u64,
|
||||
"session_id": format!("session-{actor}"),
|
||||
"iss": "https://auth.openai.com",
|
||||
"https://api.openai.com/auth": {
|
||||
"chatgpt_user_id": format!("user-{actor}"),
|
||||
"chatgpt_account_id": format!("account-{actor}"),
|
||||
},
|
||||
});
|
||||
format!(
|
||||
"e30.{}.c2ln",
|
||||
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(claims.to_string())
|
||||
)
|
||||
}
|
||||
|
||||
#[test_case(RuntimeAuthMode::DualHeader; "dual_header")]
|
||||
#[test_case(RuntimeAuthMode::AssertionOnly; "assertion_only")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn resumed_plugin_install_uses_the_threads_account(mode: RuntimeAuthMode) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
const PLUGIN_ID: &str = "plugin_connector_github";
|
||||
if std::env::var(PROBE_SERVER).is_ok() {
|
||||
let server = start_mock_server().await;
|
||||
let requests = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![ev_completed("original")]),
|
||||
sse(vec![
|
||||
ev_function_call(
|
||||
"install-github",
|
||||
REQUEST_PLUGIN_INSTALL_TOOL_NAME,
|
||||
&json!({
|
||||
"plugin_id": "github@openai-curated-remote",
|
||||
"suggest_reason": "Use GitHub for this request",
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("install"),
|
||||
]),
|
||||
sse(vec![ev_completed("finished")]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
let mut builder = test_codex()
|
||||
.with_auth(CodexAuth::from_external_chatgpt_tokens(
|
||||
&actor_token("a"),
|
||||
"account-a",
|
||||
Some("plus"),
|
||||
)?)
|
||||
.with_config(move |config| {
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(PermissionProfile::Disabled)
|
||||
.expect("test config should allow disabled permissions");
|
||||
configure_apps_without_search_tool(config, "https://chatgpt.com");
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RuntimeAgentInstances)
|
||||
.unwrap();
|
||||
config.runtime_auth_mode = mode;
|
||||
});
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
test.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "Original account".into(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
test.codex.ensure_rollout_materialized().await;
|
||||
test.codex.flush_rollout().await?;
|
||||
let rollout = test.codex.rollout_path().context("original rollout")?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
let _ = test
|
||||
.thread_manager
|
||||
.remove_thread(&test.session_configured.thread_id)
|
||||
.await;
|
||||
let history = test
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id: test.session_configured.thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
let replacement = codex_core::test_support::auth_manager_from_auth_with_home(
|
||||
CodexAuth::from_external_chatgpt_tokens(&actor_token("b"), "account-b", Some("plus"))?,
|
||||
test.codex_home_path().to_path_buf(),
|
||||
);
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
.resume_thread_with_history(
|
||||
test.config.clone(),
|
||||
InitialHistory::Resumed(ResumedHistory {
|
||||
history_revision: None,
|
||||
conversation_id: history.thread_id,
|
||||
history: Arc::new(history.items),
|
||||
rollout_path: Some(rollout),
|
||||
}),
|
||||
replacement,
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
.await?;
|
||||
resumed
|
||||
.thread
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "Use GitHub".into(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
let elicitation = wait_for_event_match(&resumed.thread, |event| match event {
|
||||
EventMsg::ElicitationRequest(request) => Some(Ok(request.clone())),
|
||||
EventMsg::TurnComplete(_) => Some(Err(anyhow::anyhow!(
|
||||
"the resumed account must reach the plugin installation prompt"
|
||||
))),
|
||||
_ => None,
|
||||
})
|
||||
.await?;
|
||||
let ElicitationRequest::Form {
|
||||
meta: Some(meta), ..
|
||||
} = &elicitation.request
|
||||
else {
|
||||
anyhow::bail!("expected plugin installation metadata");
|
||||
};
|
||||
assert_eq!(meta["remote_plugin_id"], PLUGIN_ID);
|
||||
resumed
|
||||
.thread
|
||||
.submit(Op::ResolveElicitation {
|
||||
server_name: elicitation.server_name,
|
||||
request_id: elicitation.id,
|
||||
decision: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
})
|
||||
.await?;
|
||||
wait_for_event(&resumed.thread, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
assert_eq!(requests.requests().len(), 3);
|
||||
resumed.thread.shutdown_and_wait().await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let _apps = AppsTestServer::mount(&server).await?;
|
||||
mount_recommendations(
|
||||
&server,
|
||||
ResponseTemplate::new(200).set_body_json(json!({
|
||||
"enabled": true,
|
||||
"plugins": [{"id": PLUGIN_ID, "name": "github", "display_name": "GitHub"}],
|
||||
})),
|
||||
)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/agent/register"))
|
||||
.respond_with(|request: &wiremock::Request| {
|
||||
let body: Value = request.body_json().unwrap();
|
||||
let actor = if body["actor_auth"]["credential"] == actor_token("a") {
|
||||
"a"
|
||||
} else {
|
||||
"b"
|
||||
};
|
||||
assert_eq!(body["actor_auth"]["credential"], actor_token(actor));
|
||||
ResponseTemplate::new(200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": format!("runtime-{actor}"),
|
||||
"agent_host_id": "host-a",
|
||||
"actor": {
|
||||
"kind": "chatgpt",
|
||||
"user_id": format!("user-{actor}"),
|
||||
"account_id": format!("account-{actor}"),
|
||||
},
|
||||
}))
|
||||
})
|
||||
.expect(2)
|
||||
.mount(&server)
|
||||
.await;
|
||||
Mock::given(method("GET"))
|
||||
.and(path(format!("/ps/plugins/{PLUGIN_ID}")))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"id": PLUGIN_ID, "name": "github", "scope": "GLOBAL", "status": "ENABLED",
|
||||
"installation_policy": "AVAILABLE", "authentication_policy": "ON_USE",
|
||||
"release": {
|
||||
"display_name": "GitHub", "description": "Work with GitHub repositories.",
|
||||
"app_ids": [], "interface": {},
|
||||
},
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let case = match mode {
|
||||
RuntimeAuthMode::DualHeader => "dual_header",
|
||||
RuntimeAuthMode::AssertionOnly => "assertion_only",
|
||||
};
|
||||
run_harness_through_proxy(
|
||||
&server,
|
||||
&format!("suite::request_plugin_install::runtime_auth_tests::resumed_plugin_install_uses_the_threads_account::{case}"),
|
||||
/*realtime_target*/ None,
|
||||
).await?;
|
||||
let requests = server
|
||||
.received_requests()
|
||||
.await
|
||||
.context("recorded requests")?;
|
||||
let metadata = requests
|
||||
.iter()
|
||||
.find(|request| request.url.path() == format!("/ps/plugins/{PLUGIN_ID}"))
|
||||
.context("plugin metadata request")?;
|
||||
let proof = match mode {
|
||||
RuntimeAuthMode::DualHeader => {
|
||||
assert_eq!(
|
||||
metadata.headers["authorization"],
|
||||
format!("Bearer {}", actor_token("b"))
|
||||
);
|
||||
metadata.headers["x-openai-agent-assertion"].to_str()?
|
||||
}
|
||||
RuntimeAuthMode::AssertionOnly => {
|
||||
assert!(!metadata.headers.contains_key("x-openai-agent-assertion"));
|
||||
metadata.headers["authorization"]
|
||||
.to_str()?
|
||||
.strip_prefix("AgentAssertion ")
|
||||
.context("assertion auth")?
|
||||
}
|
||||
};
|
||||
let claims: Value = serde_json::from_slice(
|
||||
&base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(proof.split('.').nth(2).context("assertion payload")?)?,
|
||||
)?;
|
||||
assert_eq!(claims["runtime_agent_instance"], "runtime-b");
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,215 +0,0 @@
|
||||
//! Check terminal runtime failures and credential recovery through complete turns.
|
||||
|
||||
use anyhow::Result;
|
||||
use base64::Engine;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_features::Feature;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::ExternalAuth;
|
||||
use codex_login::ExternalAuthFuture;
|
||||
use codex_login::ExternalAuthRefreshContext;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::runtime_auth::PROBE_SERVER;
|
||||
use core_test_support::runtime_auth::run_harness_through_proxy;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::test_codex::test_codex;
|
||||
use core_test_support::wait_for_event;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::body_string_contains;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
const TEST_NAME: &str =
|
||||
"suite::runtime_auth_denials::turns_stop_on_runtime_denial_but_recover_ordinary_401";
|
||||
const CASES: [&str; 3] = ["revoked", "header-denial", "expired"];
|
||||
const MODES: [(&str, RuntimeAuthMode); 2] = [
|
||||
("dual", RuntimeAuthMode::DualHeader),
|
||||
("assertion", RuntimeAuthMode::AssertionOnly),
|
||||
];
|
||||
|
||||
#[derive(Default)]
|
||||
struct Credentials {
|
||||
refreshes: AtomicUsize,
|
||||
}
|
||||
|
||||
impl ExternalAuth for Credentials {
|
||||
fn resolve(&self) -> ExternalAuthFuture<'_, CodexAuth> {
|
||||
Box::pin(async { Ok(CodexAuth::from_api_key("key-a")) })
|
||||
}
|
||||
|
||||
fn refresh(&self, _: ExternalAuthRefreshContext) -> ExternalAuthFuture<'_, CodexAuth> {
|
||||
self.refreshes.fetch_add(1, Ordering::SeqCst);
|
||||
self.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn turns_stop_on_runtime_denial_but_recover_ordinary_401() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
if std::env::var_os(PROBE_SERVER).is_some() {
|
||||
return exercise_turns().await;
|
||||
}
|
||||
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/agent/register"))
|
||||
.respond_with(|request: &wiremock::Request| {
|
||||
ResponseTemplate::new(200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": request.headers["idempotency-key"].to_str().unwrap(),
|
||||
"agent_host_id": "host-a",
|
||||
"actor": {"kind": "platform", "user_id": "user-a",
|
||||
"organization_id": "org-a", "project_id": null},
|
||||
}))
|
||||
})
|
||||
.expect(6)
|
||||
.mount(&server)
|
||||
.await;
|
||||
for (mode, _) in MODES {
|
||||
for case in CASES {
|
||||
let label = format!("{mode}-{case}");
|
||||
let denial = match case {
|
||||
"revoked" => ResponseTemplate::new(403).set_body_json(json!({
|
||||
"error": {"code": "runtime_instance_revoked", "message": "Runtime revoked"}
|
||||
})),
|
||||
"header-denial" => ResponseTemplate::new(401)
|
||||
.insert_header(
|
||||
"x-error-json",
|
||||
base64::engine::general_purpose::STANDARD
|
||||
.encode(br#"{"error":{"code":"invalid_agent_instance_assertion"}}"#),
|
||||
)
|
||||
.set_body_json(json!({"error": {"message": "Runtime rejected"}})),
|
||||
_ => ResponseTemplate::new(401).set_body_json(json!({
|
||||
"error": {"code": "token_expired", "message": "Credential expired"}
|
||||
})),
|
||||
};
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/responses"))
|
||||
.and(body_string_contains(label.clone()))
|
||||
.respond_with(denial)
|
||||
.with_priority(1)
|
||||
.up_to_n_times(1)
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
// A mistaken retry would complete the turn, making either denial assertion fail.
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/v1/responses"))
|
||||
.and(body_string_contains(label))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.insert_header("content-type", "text/event-stream")
|
||||
.set_body_string(responses::sse_completed("completed")),
|
||||
)
|
||||
.with_priority(2)
|
||||
.expect(u64::from(case == "expired"))
|
||||
.mount(&server)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
run_harness_through_proxy(&server, TEST_NAME, /*realtime_target*/ None).await?;
|
||||
let mut proof_ids = BTreeSet::new();
|
||||
let requests = server.received_requests().await.unwrap();
|
||||
let attempts: Vec<_> = requests
|
||||
.iter()
|
||||
.filter(|request| request.url.path() == "/v1/responses")
|
||||
.collect();
|
||||
assert_eq!(attempts.len(), 8);
|
||||
for request in attempts {
|
||||
let authorization = request.headers["authorization"].to_str()?;
|
||||
let proof = if let Some(proof) = authorization.strip_prefix("AgentAssertion ") {
|
||||
assert!(!request.headers.contains_key("x-openai-agent-assertion"));
|
||||
proof
|
||||
} else {
|
||||
assert_eq!(authorization, "Bearer key-a");
|
||||
request.headers["x-openai-agent-assertion"].to_str()?
|
||||
};
|
||||
let payload: Value = serde_json::from_slice(
|
||||
&base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(proof.split('.').nth(2).unwrap())?,
|
||||
)?;
|
||||
assert!(proof_ids.insert(payload["id"].as_str().unwrap().to_owned()));
|
||||
}
|
||||
server.verify().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exercise_turns() -> Result<()> {
|
||||
let server = MockServer::start().await;
|
||||
for (mode_label, mode) in MODES {
|
||||
for case in CASES {
|
||||
let test = test_codex()
|
||||
.with_auth(CodexAuth::from_api_key("key-a"))
|
||||
.with_config(move |config| {
|
||||
config.model_provider.base_url = Some("https://api.openai.com/v1".into());
|
||||
config.model_provider.env_http_headers = None;
|
||||
config.model_provider.supports_websockets = false;
|
||||
config.model_provider.request_max_retries = Some(2);
|
||||
config.model_provider.stream_max_retries = Some(2);
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RuntimeAgentInstances)
|
||||
.expect("enable runtime agent instances");
|
||||
config.runtime_auth_mode = mode;
|
||||
config.model_catalog = Some(
|
||||
codex_models_manager::bundled_models_response()
|
||||
.expect("load bundled models"),
|
||||
);
|
||||
})
|
||||
.build_with_auto_env(&server)
|
||||
.await?;
|
||||
let credentials = Arc::new(Credentials::default());
|
||||
test.thread_manager
|
||||
.auth_manager()
|
||||
.set_external_auth(credentials.clone())
|
||||
.await?;
|
||||
test.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: format!("{mode_label}-{case}"),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
let mut errors = Vec::new();
|
||||
let mut stream_retries = 0;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
match event {
|
||||
EventMsg::Error(error) => errors.push(error.message.clone()),
|
||||
EventMsg::StreamError(_) => stream_retries += 1,
|
||||
_ => {}
|
||||
}
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
assert_eq!(
|
||||
errors.len(),
|
||||
usize::from(case != "expired"),
|
||||
"{mode_label}-{case}"
|
||||
);
|
||||
assert_eq!(stream_retries, 0, "{mode_label}-{case}");
|
||||
assert_eq!(
|
||||
credentials.refreshes.load(Ordering::SeqCst),
|
||||
usize::from(case == "expired"),
|
||||
"{mode_label}-{case}"
|
||||
);
|
||||
test.codex.submit(Op::Shutdown).await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::ShutdownComplete)
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user