WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,6 @@ doctest = false
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
codex-agent-identity = { workspace = true }
|
||||
codex-runtime-agent-instance = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
codex-api = { workspace = true }
|
||||
codex-config = { workspace = true }
|
||||
|
||||
@@ -981,7 +981,7 @@ async fn sample_configured_conversation_history_with_delivery(
|
||||
}
|
||||
let builder = test_codex()
|
||||
.with_extensions(Arc::new(extensions.build()))
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_auth(CodexAuth::from_api_key("Test API Key"))
|
||||
.with_model_info_override("codex-auto-review", |model_info| {
|
||||
model_info
|
||||
.model_messages
|
||||
|
||||
@@ -23,14 +23,11 @@ use codex_core::cyber_access_program::ApiKeyCyberAccessPrograms;
|
||||
use codex_extension_api::ExtensionMetrics;
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_login::AgentIdentityAuthPolicy;
|
||||
use codex_model_provider::SharedModelProvider;
|
||||
use codex_model_provider::WorkspaceRoutingContext;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
use thiserror::Error;
|
||||
use tokio::sync::oneshot;
|
||||
@@ -51,14 +48,8 @@ pub struct LunaSamplerConfig {
|
||||
pub api_key_cyber_access_programs: ApiKeyCyberAccessPrograms,
|
||||
/// False when the parent host confines its explicit program to that thread.
|
||||
pub inherit_parent_cyber_access_program: bool,
|
||||
/// Routing scope and retained configuration layers for the owning thread.
|
||||
pub workspace_routing: WorkspaceRoutingContext,
|
||||
/// Effective proxy, custom-CA, and cookie configuration.
|
||||
pub http_client_factory: HttpClientFactory,
|
||||
/// Agent-identity policy selected for the owning thread.
|
||||
pub agent_identity_policy: AgentIdentityAuthPolicy,
|
||||
/// Host-resolved source used to scope agent-identity authentication.
|
||||
pub session_source: SessionSource,
|
||||
/// Owning runtime session identifier.
|
||||
pub session_id: String,
|
||||
/// Owning thread identifier.
|
||||
|
||||
@@ -34,9 +34,6 @@ use codex_login::default_client::ClientRedirectPolicy;
|
||||
use codex_login::default_client::add_originator_header;
|
||||
use codex_login::default_client::create_client_for_route_async;
|
||||
use codex_login::default_client::default_headers;
|
||||
use codex_model_provider::ACCOUNT_ROUTING_HEADER;
|
||||
use codex_model_provider::AgentIdentitySessionFallback;
|
||||
use codex_model_provider::ProviderAuthScope;
|
||||
use codex_model_provider::ResponsesConnectionKey;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_websocket_client::WebSocketConnector;
|
||||
@@ -84,6 +81,9 @@ struct HttpTransport {
|
||||
transport: OnceCell<ReqwestTransport>,
|
||||
}
|
||||
|
||||
/// The guardian classifier request mode is a ChatGPT-backend-only route.
|
||||
const GUARDIAN_CLASSIFIER_BACKEND_AVAILABLE: bool = false;
|
||||
|
||||
pub(super) struct PooledConnection {
|
||||
connection: ResponsesWebsocketConnection,
|
||||
request_kind: RequestMode,
|
||||
@@ -92,7 +92,6 @@ pub(super) struct PooledConnection {
|
||||
pub(super) expires_at: Instant,
|
||||
auth_changes: Option<tokio::sync::watch::Receiver<AuthChangeState>>,
|
||||
key: ResponsesConnectionKey,
|
||||
runtime_id: Option<String>,
|
||||
auth_owner: Option<AuthOwner>,
|
||||
_permit: OwnedSemaphorePermit,
|
||||
}
|
||||
@@ -101,7 +100,6 @@ pub(super) struct PooledConnection {
|
||||
struct ClientSetup {
|
||||
provider: Provider,
|
||||
http_client_factory: HttpClientFactory,
|
||||
runtime_id: Option<String>,
|
||||
auth_owner: Option<AuthOwner>,
|
||||
request_kind: RequestMode,
|
||||
auth: SharedAuthProvider,
|
||||
@@ -160,10 +158,6 @@ impl ConnectionPool {
|
||||
}
|
||||
|
||||
fn start_refill(self: &Arc<Self>, guard: OwnedMutexGuard<()>) -> Option<JoinHandle<()>> {
|
||||
// Runtime sources must be reauthenticated when a classification is admitted.
|
||||
if self.config.provider.runtime_auth().is_some() {
|
||||
return None;
|
||||
}
|
||||
let mut retry_after = self
|
||||
.retry_after
|
||||
.lock()
|
||||
@@ -232,12 +226,10 @@ impl ConnectionPool {
|
||||
.map_err(|error| LunaSamplerError::Api(ApiError::Stream(error.to_string())))?;
|
||||
let admitted = Instant::now();
|
||||
let setup = self.client_setup().await?;
|
||||
let fresh_connection = self.runtime_connection(&setup).await?;
|
||||
let ClientSetup {
|
||||
mut provider,
|
||||
auth,
|
||||
http_client_factory,
|
||||
runtime_id,
|
||||
auth_owner,
|
||||
request_kind,
|
||||
redirect_policy,
|
||||
@@ -245,32 +237,27 @@ impl ConnectionPool {
|
||||
auth_changes,
|
||||
} = setup;
|
||||
let setup_finished = Instant::now();
|
||||
let connection = if runtime_id.is_some() {
|
||||
fresh_connection
|
||||
} else {
|
||||
loop {
|
||||
let idle = self
|
||||
.idle_connections
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.pop();
|
||||
match idle {
|
||||
Some(connection)
|
||||
if connection.key == key
|
||||
&& connection.runtime_id == runtime_id
|
||||
&& connection.auth_owner == auth_owner
|
||||
&& connection
|
||||
.auth_changes
|
||||
.as_ref()
|
||||
.is_none_or(|auth| !auth.has_changed().unwrap_or(true))
|
||||
&& Instant::now() < connection.expires_at
|
||||
&& !connection.connection.is_closed().await =>
|
||||
{
|
||||
break Some(connection);
|
||||
}
|
||||
Some(_) => {}
|
||||
None => break None,
|
||||
let connection = loop {
|
||||
let idle = self
|
||||
.idle_connections
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.pop();
|
||||
match idle {
|
||||
Some(connection)
|
||||
if connection.key == key
|
||||
&& connection.auth_owner == auth_owner
|
||||
&& connection
|
||||
.auth_changes
|
||||
.as_ref()
|
||||
.is_none_or(|auth| !auth.has_changed().unwrap_or(true))
|
||||
&& Instant::now() < connection.expires_at
|
||||
&& !connection.connection.is_closed().await =>
|
||||
{
|
||||
break Some(connection);
|
||||
}
|
||||
Some(_) => {}
|
||||
None => break None,
|
||||
}
|
||||
};
|
||||
let (connection, thread_id, request_kind) = match connection {
|
||||
@@ -293,11 +280,6 @@ impl ConnectionPool {
|
||||
// Sampling owns the retry budget across both transports.
|
||||
provider.retry.max_attempts = 0;
|
||||
let url = provider.url_for_path("/responses");
|
||||
let redirect_policy = if provider.headers.contains_key(ACCOUNT_ROUTING_HEADER) {
|
||||
ClientRedirectPolicy::Reject
|
||||
} else {
|
||||
redirect_policy
|
||||
};
|
||||
let transport = {
|
||||
let mut cached = self
|
||||
.http_transport
|
||||
@@ -385,12 +367,6 @@ impl ConnectionPool {
|
||||
async fn client_setup(&self) -> Result<ClientSetup, LunaSamplerError> {
|
||||
let setup = codex_model_provider::resolve_request(
|
||||
self.config.provider.as_ref(),
|
||||
Some(ProviderAuthScope {
|
||||
agent_identity_policy: self.config.agent_identity_policy,
|
||||
session_source: self.config.session_source.clone(),
|
||||
agent_identity_session_fallback: AgentIdentitySessionFallback::default(),
|
||||
}),
|
||||
Some(&self.config.workspace_routing),
|
||||
self.config.http_client_factory.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -412,7 +388,6 @@ impl ConnectionPool {
|
||||
auth: setup.api_auth,
|
||||
redirect_policy: setup.redirect_policy,
|
||||
http_client_factory: setup.http_client_factory,
|
||||
runtime_id: setup.runtime_id,
|
||||
auth_owner: setup.auth_owner,
|
||||
request_kind,
|
||||
key,
|
||||
@@ -455,7 +430,9 @@ impl ConnectionPool {
|
||||
}
|
||||
fn responses_request_kind(&self, auth: Option<&CodexAuth>) -> RequestMode {
|
||||
let provider = self.config.provider.info();
|
||||
if auth.is_some_and(CodexAuth::uses_codex_backend)
|
||||
// The guardian classifier mode is served only by the ChatGPT backend, which
|
||||
// aKode never authenticates to.
|
||||
if auth.is_some_and(|_| GUARDIAN_CLASSIFIER_BACKEND_AVAILABLE)
|
||||
&& provider.is_openai()
|
||||
&& provider.requires_openai_auth
|
||||
&& provider.env_key.is_none()
|
||||
@@ -469,53 +446,6 @@ impl ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
async fn runtime_connection(
|
||||
&self,
|
||||
setup: &ClientSetup,
|
||||
) -> Result<Option<PooledConnection>, LunaSamplerError> {
|
||||
if setup.runtime_id.is_none() || !self.config.provider.info().supports_websockets {
|
||||
return Ok(None);
|
||||
}
|
||||
if self
|
||||
.retry_after
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.is_some_and(|deadline| Instant::now() < deadline)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let Ok(permit) = Arc::clone(&self.sockets).try_acquire_owned() else {
|
||||
return Ok(None);
|
||||
};
|
||||
match self.open_connection_with_setup(permit, setup.clone()).await {
|
||||
Ok(connection) => Ok(Some(connection)),
|
||||
Err(LunaSamplerError::ConnectionTimeout) => {
|
||||
*self
|
||||
.retry_after
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) =
|
||||
Some(Instant::now() + CONNECT_COOLDOWN);
|
||||
Ok(None)
|
||||
}
|
||||
Err(
|
||||
error @ LunaSamplerError::Api(ApiError::Transport(
|
||||
TransportError::Policy(_) | TransportError::Build(_),
|
||||
)),
|
||||
) => Err(error),
|
||||
Err(
|
||||
error @ LunaSamplerError::Api(ApiError::Transport(TransportError::Http {
|
||||
status:
|
||||
http::StatusCode::UNAUTHORIZED
|
||||
| http::StatusCode::FORBIDDEN
|
||||
| http::StatusCode::TOO_MANY_REQUESTS,
|
||||
..
|
||||
})),
|
||||
) => Err(error),
|
||||
// Unsupported upgrades and connection failures can still use HTTP.
|
||||
Err(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
async fn open_connection(
|
||||
&self,
|
||||
permit: OwnedSemaphorePermit,
|
||||
@@ -533,7 +463,6 @@ impl ConnectionPool {
|
||||
provider,
|
||||
auth,
|
||||
http_client_factory,
|
||||
runtime_id,
|
||||
auth_owner,
|
||||
request_kind,
|
||||
redirect_policy: _,
|
||||
@@ -616,7 +545,6 @@ impl ConnectionPool {
|
||||
expires_at: Instant::now() + MAX_WEBSOCKET_AGE,
|
||||
auth_changes,
|
||||
key,
|
||||
runtime_id,
|
||||
auth_owner,
|
||||
_permit: permit,
|
||||
})
|
||||
@@ -664,7 +592,6 @@ impl ConnectionLease {
|
||||
|
||||
pub(super) async fn reuse(self) {
|
||||
if let Connection::Websocket(connection) = self.connection
|
||||
&& connection.runtime_id.is_none()
|
||||
&& !connection.connection.is_closed().await
|
||||
{
|
||||
self.pool
|
||||
|
||||
@@ -12,10 +12,6 @@ use anyhow::Result;
|
||||
use codex_guardian_context::TranscriptCursor;
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::WorkspaceRouting;
|
||||
use codex_login::WorkspaceRoutingRequest;
|
||||
use codex_login::WorkspaceRoutingResolver;
|
||||
use codex_model_provider::ModelProviderFuture;
|
||||
use codex_model_provider::create_model_provider;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use core_test_support::responses;
|
||||
@@ -206,7 +202,7 @@ async fn cold_pool_uses_http_during_open_timeout_then_recovers_after_cooldown()
|
||||
config.provider = create_model_provider(
|
||||
ModelProviderInfo::create_openai_provider(Some(base_url)),
|
||||
Some(AuthManager::from_auth_for_testing(if uses_codex_backend {
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing()
|
||||
CodexAuth::from_api_key("Test API Key")
|
||||
} else {
|
||||
CodexAuth::from_api_key("test-api-key")
|
||||
})),
|
||||
@@ -502,17 +498,6 @@ async fn cancellation_closes_http_before_headers_and_while_draining_the_body() -
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct RoutingPolicy(Mutex<Option<WorkspaceRouting>>);
|
||||
|
||||
impl WorkspaceRoutingResolver for RoutingPolicy {
|
||||
fn resolve(
|
||||
&self,
|
||||
_request: WorkspaceRoutingRequest,
|
||||
) -> ModelProviderFuture<'_, std::io::Result<Option<WorkspaceRouting>>> {
|
||||
Box::pin(async { Ok(self.0.lock().unwrap().clone()) })
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sampling_uses_new_credentials_after_logout_and_login() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -579,13 +564,9 @@ async fn sampling_uses_new_credentials_after_logout_and_login() -> Result<()> {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn http_cache_preserves_no_constraint_redirect_policy_and_configured_headers() -> Result<()> {
|
||||
async fn http_cache_reuses_transport_with_default_redirect_policy() -> Result<()> {
|
||||
let base_url = "https://localhost:9/backend-api/codex".to_owned();
|
||||
let auth =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let resolver = Arc::new(RoutingPolicy(Mutex::new(None)));
|
||||
let routing_owner: Arc<dyn WorkspaceRoutingResolver> = resolver.clone();
|
||||
auth.set_workspace_routing_resolver(Arc::downgrade(&routing_owner));
|
||||
let auth = AuthManager::from_auth_for_testing(CodexAuth::from_api_key("Test API Key"));
|
||||
let mut config = sampler_config(base_url.clone());
|
||||
config.provider = create_model_provider(
|
||||
ModelProviderInfo::create_openai_provider(Some(base_url)),
|
||||
@@ -595,19 +576,9 @@ async fn http_cache_preserves_no_constraint_redirect_policy_and_configured_heade
|
||||
// Exercise HTTP leases without starting a background WebSocket opener.
|
||||
*pool.retry_after.lock().unwrap() = Some(Instant::now() + CONNECT_COOLDOWN);
|
||||
let mut previous: Option<Arc<HttpTransport>> = None;
|
||||
for (routing, expected_policy) in [
|
||||
(None, ClientRedirectPolicy::Default),
|
||||
(Some("NO_CONSTRAINT"), ClientRedirectPolicy::Reject),
|
||||
(Some("NO_CONSTRAINT"), ClientRedirectPolicy::Reject),
|
||||
(None, ClientRedirectPolicy::Default),
|
||||
] {
|
||||
*resolver.0.lock().unwrap() = routing.map(|account_routing_override| WorkspaceRouting {
|
||||
chatgpt_account_id: "account_id".into(),
|
||||
backend_origin: "https://localhost:9".into(),
|
||||
account_routing_override: account_routing_override.into(),
|
||||
});
|
||||
for _ in 0..2 {
|
||||
let setup = pool.client_setup().await?;
|
||||
assert!(!setup.provider.headers.contains_key(ACCOUNT_ROUTING_HEADER));
|
||||
assert_eq!(setup.redirect_policy, ClientRedirectPolicy::Default);
|
||||
let lease = pool.lease().await?;
|
||||
assert!(matches!(lease.connection, Connection::Http(_)));
|
||||
let cached = Arc::clone(pool.http_transport.lock().unwrap().as_ref().unwrap());
|
||||
@@ -615,293 +586,13 @@ async fn http_cache_preserves_no_constraint_redirect_policy_and_configured_heade
|
||||
(cached.url.as_str(), cached.redirect_policy),
|
||||
(
|
||||
"https://localhost:9/backend-api/codex/responses",
|
||||
expected_policy
|
||||
ClientRedirectPolicy::Default
|
||||
),
|
||||
);
|
||||
if let Some(previous) = previous {
|
||||
assert_eq!(
|
||||
Arc::ptr_eq(&previous, &cached),
|
||||
previous.redirect_policy == expected_policy,
|
||||
);
|
||||
assert!(Arc::ptr_eq(&previous, &cached));
|
||||
}
|
||||
previous = Some(cached);
|
||||
}
|
||||
|
||||
let mut config = sampler_config("https://localhost:9/v1".into());
|
||||
let mut info = config.provider.info().clone();
|
||||
info.http_headers = Some(std::collections::HashMap::from([(
|
||||
ACCOUNT_ROUTING_HEADER.into(),
|
||||
"us".into(),
|
||||
)]));
|
||||
config.provider = create_model_provider(info, config.provider.auth_manager());
|
||||
let pool = ConnectionPool::new(Arc::new(config));
|
||||
*pool.retry_after.lock().unwrap() = Some(Instant::now() + CONNECT_COOLDOWN);
|
||||
assert_eq!(
|
||||
pool.client_setup().await?.redirect_policy,
|
||||
ClientRedirectPolicy::Default
|
||||
);
|
||||
let lease = pool.lease().await?;
|
||||
assert!(matches!(lease.connection, Connection::Http(_)));
|
||||
assert_eq!(
|
||||
pool.http_transport
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.redirect_policy,
|
||||
ClientRedirectPolicy::Reject,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn runtime_transports_authenticate_each_classification() -> Result<()> {
|
||||
use base64::Engine;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_runtime_agent_instance::AgentHostAuthorization;
|
||||
use codex_runtime_agent_instance::RuntimeAuthManager;
|
||||
use codex_runtime_agent_instance::RuntimeRegistrationMetadata;
|
||||
use codex_runtime_agent_instance::RuntimeRole;
|
||||
use serde_json::json;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
struct MutableAuth(Mutex<CodexAuth>);
|
||||
impl codex_login::ExternalAuth for MutableAuth {
|
||||
fn resolve(&self) -> codex_login::ExternalAuthFuture<'_, CodexAuth> {
|
||||
Box::pin(async { Ok(self.0.lock().unwrap().clone()) })
|
||||
}
|
||||
|
||||
fn refresh(
|
||||
&self,
|
||||
_context: codex_login::ExternalAuthRefreshContext,
|
||||
) -> codex_login::ExternalAuthFuture<'_, CodexAuth> {
|
||||
self.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
skip_if_no_network!(Ok(()));
|
||||
for mode in [RuntimeAuthMode::DualHeader, RuntimeAuthMode::AssertionOnly] {
|
||||
for transport in [
|
||||
"http",
|
||||
"websocket",
|
||||
"upgrade_required",
|
||||
"legacy_endpoint",
|
||||
"changed_auth",
|
||||
"denied",
|
||||
] {
|
||||
let websocket = transport == "websocket";
|
||||
let denied = transport == "denied";
|
||||
let changed_auth = transport == "changed_auth";
|
||||
let source = Arc::new(MutableAuth(Mutex::new(CodexAuth::from_api_key(
|
||||
"guardian-key",
|
||||
))));
|
||||
let registration = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/register"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"runtime_agent_instance_id": "runtime-guardian",
|
||||
"agent_host_id": "host-guardian",
|
||||
"actor": {"kind": "platform", "user_id": "actor", "organization_id": "org", "project_id": null},
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(®istration)
|
||||
.await;
|
||||
let response = vec![
|
||||
responses::ev_output_text_delta("low"),
|
||||
responses::ev_completed("score"),
|
||||
];
|
||||
let ws = if websocket {
|
||||
// Each peer leaves another response available, so closure cannot force the retry.
|
||||
Some(
|
||||
responses::start_websocket_server(vec![
|
||||
vec![response.clone(), response.clone()],
|
||||
vec![response.clone(), response.clone()],
|
||||
])
|
||||
.await,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let http = MockServer::start().await;
|
||||
let upgrade_response = if denied {
|
||||
ResponseTemplate::new(403).set_body_json(json!({"error": {
|
||||
"code": "runtime_instance_paused", "type": "runtime_agent_error",
|
||||
"message": "The runtime agent instance is paused."
|
||||
}}))
|
||||
} else if transport == "legacy_endpoint" {
|
||||
ResponseTemplate::new(404)
|
||||
} else {
|
||||
ResponseTemplate::new(426)
|
||||
};
|
||||
let handshake_source = Arc::clone(&source);
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/responses"))
|
||||
.respond_with(move |_request: &wiremock::Request| {
|
||||
if changed_auth {
|
||||
*handshake_source.0.lock().unwrap() =
|
||||
CodexAuth::from_api_key("replacement-key");
|
||||
}
|
||||
upgrade_response.clone()
|
||||
})
|
||||
.expect(match transport {
|
||||
"upgrade_required" | "legacy_endpoint" => 2,
|
||||
"changed_auth" | "denied" => 1,
|
||||
_ => 0,
|
||||
})
|
||||
.mount(&http)
|
||||
.await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/responses"))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.insert_header("content-type", "text/event-stream")
|
||||
.set_body_string(responses::sse(response)),
|
||||
)
|
||||
.expect(if websocket || denied {
|
||||
0
|
||||
} else if changed_auth {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
})
|
||||
.mount(&http)
|
||||
.await;
|
||||
let url = ws.as_ref().map_or_else(
|
||||
|| http.uri(),
|
||||
|ws| ws.uri().replacen("ws://", "http://", /*count*/ 1),
|
||||
);
|
||||
let mut config = sampler_config(url);
|
||||
let credentials =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::from_api_key("guardian-key"));
|
||||
if changed_auth {
|
||||
credentials.set_external_auth(source.clone()).await?;
|
||||
}
|
||||
let runtime = Arc::new(RuntimeAuthManager::new(
|
||||
Arc::clone(&credentials),
|
||||
AgentHostAuthorization::InstallationId {
|
||||
installation_id: uuid::Uuid::nil(),
|
||||
},
|
||||
RuntimeRegistrationMetadata {
|
||||
harness: Some("codex".into()),
|
||||
harness_version: None,
|
||||
role: RuntimeRole::Orchestrator,
|
||||
},
|
||||
format!("{}/register", registration.uri()).parse()?,
|
||||
));
|
||||
let mut info = config.provider.info().clone();
|
||||
info.supports_websockets = transport != "http";
|
||||
config.provider = codex_model_provider::test_support::runtime_model_provider(
|
||||
info,
|
||||
Arc::clone(&credentials),
|
||||
(runtime, mode),
|
||||
);
|
||||
let sampler = LunaSampler::new(config);
|
||||
sampler.prewarm().await;
|
||||
if let Some(ws) = &ws {
|
||||
assert!(
|
||||
ws.handshakes().is_empty(),
|
||||
"prewarming must not admit runtime work"
|
||||
);
|
||||
}
|
||||
if denied {
|
||||
let error = sampler.sample(sample_request("denied")).await.unwrap_err();
|
||||
assert!(
|
||||
matches!(
|
||||
error,
|
||||
LunaSamplerError::Api(ApiError::Transport(TransportError::Http {
|
||||
status: http::StatusCode::FORBIDDEN,
|
||||
..
|
||||
}))
|
||||
),
|
||||
"{error:?}"
|
||||
);
|
||||
} else {
|
||||
assert_eq!(sampler.sample(sample_request("first")).await?, "low");
|
||||
if changed_auth {
|
||||
assert_eq!(
|
||||
credentials.auth().await.unwrap().get_token()?,
|
||||
"replacement-key"
|
||||
);
|
||||
} else {
|
||||
assert_eq!(sampler.sample(sample_request("second")).await?, "low");
|
||||
}
|
||||
}
|
||||
let headers = if let Some(ws) = &ws {
|
||||
assert_eq!(
|
||||
ws.connections().iter().map(Vec::len).collect::<Vec<_>>(),
|
||||
vec![1, 1]
|
||||
);
|
||||
ws.handshakes()
|
||||
.iter()
|
||||
.map(|h| {
|
||||
(
|
||||
h.header("authorization").unwrap(),
|
||||
h.header("x-openai-agent-assertion"),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
http.received_requests()
|
||||
.await
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|request| {
|
||||
(
|
||||
request.headers["authorization"]
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_owned(),
|
||||
request
|
||||
.headers
|
||||
.get("x-openai-agent-assertion")
|
||||
.map(|value| value.to_str().unwrap().to_owned()),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let expected_attempts = match transport {
|
||||
"upgrade_required" | "legacy_endpoint" => 4,
|
||||
"denied" => 1,
|
||||
_ => 2,
|
||||
};
|
||||
assert_eq!(headers.len(), expected_attempts);
|
||||
let mut proofs = std::collections::BTreeSet::new();
|
||||
for (authorization, supplemental) in headers {
|
||||
let proof = match mode {
|
||||
RuntimeAuthMode::DualHeader => {
|
||||
assert_eq!(authorization, "Bearer guardian-key");
|
||||
supplemental.unwrap()
|
||||
}
|
||||
RuntimeAuthMode::AssertionOnly => {
|
||||
assert!(supplemental.is_none());
|
||||
authorization
|
||||
.strip_prefix("AgentAssertion ")
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
}
|
||||
};
|
||||
let payload: serde_json::Value = serde_json::from_slice(
|
||||
&base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(proof.split('.').nth(/*n*/ 2).unwrap())?,
|
||||
)?;
|
||||
assert_eq!(payload["runtime_agent_instance"], "runtime-guardian");
|
||||
assert!(
|
||||
proofs.insert(proof),
|
||||
"each attempt must authenticate afresh"
|
||||
);
|
||||
}
|
||||
registration.verify().await;
|
||||
http.verify().await;
|
||||
drop(sampler);
|
||||
if let Some(ws) = ws {
|
||||
ws.shutdown().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Keeps classifier evidence within its owning account and thread routing binding.
|
||||
//! Keeps classifier evidence within the credential owner that started the request.
|
||||
|
||||
use super::connect_sampler;
|
||||
use super::proxy_websocket_servers;
|
||||
@@ -10,66 +10,23 @@ use codex_login::CodexAuth;
|
||||
use codex_login::ExternalAuth;
|
||||
use codex_login::ExternalAuthFuture;
|
||||
use codex_login::ExternalAuthRefreshContext;
|
||||
use codex_login::WorkspaceRouting;
|
||||
use codex_login::WorkspaceRoutingRequest;
|
||||
use codex_login::WorkspaceRoutingResolver;
|
||||
use codex_model_provider::ModelProviderFuture;
|
||||
use codex_model_provider::create_model_provider;
|
||||
use codex_model_provider_info::ModelProviderInfo;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::responses::WebSocketConnectionConfig;
|
||||
use core_test_support::responses::ev_assistant_message;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
|
||||
type RoutingFuture<'a> = ModelProviderFuture<'a, std::io::Result<Option<WorkspaceRouting>>>;
|
||||
|
||||
struct UnavailableRouting;
|
||||
|
||||
impl WorkspaceRoutingResolver for UnavailableRouting {
|
||||
fn resolve(&self, _request: WorkspaceRoutingRequest) -> RoutingFuture<'_> {
|
||||
Box::pin(async { Err(std::io::Error::other("discovery unavailable")) })
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn failed_routing_blocks_a_prewarmed_classifier_connection() -> Result<()> {
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
let response = vec![vec![ev_assistant_message("r1", "low"), ev_completed("r1")]];
|
||||
let server = responses::start_websocket_server(vec![response.clone(), response]).await;
|
||||
let base_url = proxy_websocket_servers(&[&server, &server])
|
||||
.await?
|
||||
.replace("/v1", "/backend-api/codex");
|
||||
let auth =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let mut config = sampler_config(base_url.clone());
|
||||
config.provider = create_model_provider(
|
||||
ModelProviderInfo::create_openai_provider(Some(base_url)),
|
||||
Some(auth.clone()),
|
||||
);
|
||||
let sampler = connect_sampler(config).await?;
|
||||
let resolver: Arc<dyn WorkspaceRoutingResolver> = Arc::new(UnavailableRouting);
|
||||
auth.set_workspace_routing_resolver(Arc::downgrade(&resolver));
|
||||
let error = sampler.sample(sample_request("turn-1")).await.unwrap_err();
|
||||
assert!(
|
||||
error.to_string().contains("discovery unavailable"),
|
||||
"{error}"
|
||||
);
|
||||
assert!(server.connections().iter().all(Vec::is_empty));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct AuthAfterRouting {
|
||||
/// Host-supplied credentials that switch to a different key once `resolved` is set.
|
||||
struct SwitchingAuth {
|
||||
initial: CodexAuth,
|
||||
updated: CodexAuth,
|
||||
resolved: AtomicBool,
|
||||
}
|
||||
|
||||
impl ExternalAuth for AuthAfterRouting {
|
||||
impl ExternalAuth for SwitchingAuth {
|
||||
fn resolve(&self) -> ExternalAuthFuture<'_, CodexAuth> {
|
||||
Box::pin(async {
|
||||
Ok(if self.resolved.load(Ordering::SeqCst) {
|
||||
@@ -85,152 +42,9 @@ impl ExternalAuth for AuthAfterRouting {
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceRoutingResolver for AuthAfterRouting {
|
||||
fn resolve(&self, _request: WorkspaceRoutingRequest) -> RoutingFuture<'_> {
|
||||
Box::pin(async {
|
||||
self.resolved.store(/*val*/ true, Ordering::SeqCst);
|
||||
Ok(None)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn classification_retries_refreshes_but_never_switches_accounts() -> Result<()> {
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
// Both tokens identify the same user; their signatures differ after refresh.
|
||||
let token =
|
||||
"header.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF91c2VyX2lkIjoidXNlci1hIn19";
|
||||
for account in ["workspace-a", "workspace-b"] {
|
||||
let server = responses::start_mock_server().await;
|
||||
let response = responses::mount_sse_once(
|
||||
&server,
|
||||
responses::sse(vec![
|
||||
ev_assistant_message("score", "low"),
|
||||
ev_completed("score"),
|
||||
]),
|
||||
)
|
||||
.await;
|
||||
let home = tempfile::tempdir()?;
|
||||
let changes = Arc::new(AuthAfterRouting {
|
||||
initial: CodexAuth::from_external_chatgpt_tokens(
|
||||
&format!("{token}.initial"),
|
||||
"workspace-a",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?,
|
||||
updated: CodexAuth::from_external_chatgpt_tokens(
|
||||
&format!("{token}.refreshed"),
|
||||
account,
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?,
|
||||
resolved: AtomicBool::new(/*v*/ false),
|
||||
});
|
||||
let auth = AuthManager::from_auth_for_testing_with_home(
|
||||
changes.initial.clone(),
|
||||
home.path().to_owned(),
|
||||
);
|
||||
auth.set_external_auth(changes.clone()).await?;
|
||||
let resolver: Arc<dyn WorkspaceRoutingResolver> = changes;
|
||||
auth.set_workspace_routing_resolver(Arc::downgrade(&resolver));
|
||||
let mut config = sampler_config(format!("{}/backend-api/codex", server.uri()));
|
||||
config.provider = create_model_provider(config.provider.info().clone(), Some(auth));
|
||||
let sampler = super::LunaSampler::new(config);
|
||||
let result = sampler.sample(sample_request("turn-1")).await;
|
||||
if account == "workspace-a" {
|
||||
assert_eq!(result?, "low");
|
||||
let request = response.single_request();
|
||||
assert_eq!(
|
||||
(
|
||||
request.header("chatgpt-account-id"),
|
||||
request.header("authorization")
|
||||
),
|
||||
(
|
||||
Some("workspace-a".into()),
|
||||
Some(format!("Bearer {token}.refreshed"))
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert!(result.unwrap_err().to_string().contains("account changed"));
|
||||
assert!(
|
||||
response.requests().is_empty(),
|
||||
"evidence must not reach the new account"
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct ChangedBootstrap(AtomicBool);
|
||||
|
||||
impl WorkspaceRoutingResolver for ChangedBootstrap {
|
||||
fn resolve(&self, request: WorkspaceRoutingRequest) -> RoutingFuture<'_> {
|
||||
Box::pin(async move {
|
||||
if request.previously_routed {
|
||||
Err(std::io::Error::other(
|
||||
"bootstrap changed; start a new thread",
|
||||
))
|
||||
} else if self.0.swap(/*val*/ false, Ordering::SeqCst) {
|
||||
Ok(Some(WorkspaceRouting {
|
||||
chatgpt_account_id: "account_id".into(),
|
||||
backend_origin: "https://gov.chatgpt.com".into(),
|
||||
account_routing_override: "us_cr".into(),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn idle_classifier_retains_the_owning_threads_workspace_binding() -> Result<()> {
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
let auth =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let thread_server = responses::start_mock_server().await;
|
||||
let test = core_test_support::test_codex::test_codex()
|
||||
.with_auth_manager(Arc::clone(&auth))
|
||||
.build_with_auto_env(&thread_server)
|
||||
.await?;
|
||||
let server = responses::start_mock_server().await;
|
||||
let resolver: Arc<dyn WorkspaceRoutingResolver> =
|
||||
Arc::new(ChangedBootstrap(AtomicBool::new(/*v*/ true)));
|
||||
auth.set_workspace_routing_resolver(Arc::downgrade(&resolver));
|
||||
let mut config = test.config.clone();
|
||||
config.model_provider = ModelProviderInfo::create_openai_provider(Some(format!(
|
||||
"{}/backend-api/codex",
|
||||
server.uri()
|
||||
)));
|
||||
let session_store = codex_extension_api::ExtensionData::new("session-1");
|
||||
let input = codex_extension_api::ThreadStartInput {
|
||||
config: &config,
|
||||
session_source: &codex_protocol::protocol::SessionSource::Exec,
|
||||
persistent_thread_state_available: false,
|
||||
environments: &[],
|
||||
mcp_resource_client: None,
|
||||
extension_metrics: None,
|
||||
session_store: &session_store,
|
||||
thread_store: test.codex.thread_extension_data(),
|
||||
};
|
||||
let owning_context = input
|
||||
.thread_store
|
||||
.get::<codex_model_provider::WorkspaceRoutingContext>()
|
||||
.expect("Core seeds the owning thread's routing context before extensions start");
|
||||
let classifier = crate::async_scorer::startup::sampler_config(&input, /*manager*/ None).await;
|
||||
classifier
|
||||
.provider
|
||||
.responses_api_provider(&owning_context)
|
||||
.await?;
|
||||
let sampler = super::LunaSampler::new(classifier);
|
||||
let error = sampler.sample(sample_request("turn-1")).await.unwrap_err();
|
||||
assert!(error.to_string().contains("start a new thread"), "{error}");
|
||||
assert!(server.received_requests().await.unwrap().is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn account_switch_cancels_request_opening_and_first_token_waits() -> Result<()> {
|
||||
core_test_support::skip_if_no_network!(Ok(()));
|
||||
let token = "header.eyJodHRwczovL2FwaS5vcGVuYWkuY29tL2F1dGgiOnsiY2hhdGdwdF91c2VyX2lkIjoidXNlci1hIn19.signature";
|
||||
for transport in ["http", "websocket"] {
|
||||
let http = responses::start_mock_server().await;
|
||||
let opening = responses::mount_response_once(
|
||||
@@ -245,17 +59,9 @@ async fn account_switch_cancels_request_opening_and_first_token_waits() -> Resul
|
||||
close_after_requests: false,
|
||||
};
|
||||
let websocket = responses::start_websocket_server_with_headers(vec![stalled; 2]).await;
|
||||
let changes = Arc::new(AuthAfterRouting {
|
||||
initial: CodexAuth::from_external_chatgpt_tokens(
|
||||
token,
|
||||
"workspace-a",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?,
|
||||
updated: CodexAuth::from_external_chatgpt_tokens(
|
||||
token,
|
||||
"workspace-b",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)?,
|
||||
let changes = Arc::new(SwitchingAuth {
|
||||
initial: CodexAuth::from_api_key("key-a"),
|
||||
updated: CodexAuth::from_api_key("key-b"),
|
||||
resolved: AtomicBool::new(/*v*/ false),
|
||||
});
|
||||
let home = tempfile::tempdir()?;
|
||||
|
||||
@@ -7,7 +7,6 @@ use codex_extension_api::ExtensionMetrics;
|
||||
use codex_guardian_context::PreviousReviews;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::OutboundProxyPolicy;
|
||||
use codex_login::AgentIdentityAuthPolicy;
|
||||
use codex_login::AuthHeaders;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
@@ -23,7 +22,6 @@ use codex_protocol::TranscriptFormat;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
use codex_protocol_test_support::uuid_v7_item_id_generator_for_test;
|
||||
use core_test_support::responses;
|
||||
@@ -243,9 +241,6 @@ pub(in crate::async_scorer) fn sampler_config(base_url: String) -> LunaSamplerCo
|
||||
LunaSamplerConfig {
|
||||
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
|
||||
inherit_parent_cyber_access_program: true,
|
||||
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
|
||||
"https://chatgpt.com/backend-api".into(),
|
||||
),
|
||||
provider: create_model_provider(
|
||||
ModelProviderInfo::create_openai_provider(Some(base_url)),
|
||||
Some(AuthManager::from_auth_for_testing(CodexAuth::from_api_key(
|
||||
@@ -253,8 +248,6 @@ pub(in crate::async_scorer) fn sampler_config(base_url: String) -> LunaSamplerCo
|
||||
))),
|
||||
),
|
||||
http_client_factory: HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
agent_identity_policy: AgentIdentityAuthPolicy::JwtOnly,
|
||||
session_source: SessionSource::Exec,
|
||||
session_id: "session-1".to_owned(),
|
||||
thread_id: "thread-1".to_owned(),
|
||||
originator: Some("guardian-v2-test".to_owned()),
|
||||
@@ -539,7 +532,7 @@ async fn classifier_sends_guardian_header_only_with_codex_backend_auth() -> Resu
|
||||
|
||||
for (auth, base_path, expected_header, expected_service_tier) in [
|
||||
(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
CodexAuth::from_api_key("Test API Key"),
|
||||
"/backend-api/codex",
|
||||
Some("classifier"),
|
||||
None,
|
||||
@@ -557,7 +550,7 @@ async fn classifier_sends_guardian_header_only_with_codex_backend_auth() -> Resu
|
||||
Some("priority"),
|
||||
),
|
||||
(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
CodexAuth::from_api_key("Test API Key"),
|
||||
"/v1",
|
||||
Some("classifier"),
|
||||
None,
|
||||
@@ -660,13 +653,8 @@ async fn preconnected_sampler_reuses_authenticated_websocket_for_classifications
|
||||
let sampler = connect_sampler(LunaSamplerConfig {
|
||||
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
|
||||
inherit_parent_cyber_access_program: true,
|
||||
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
|
||||
"https://chatgpt.com/backend-api".into(),
|
||||
),
|
||||
provider,
|
||||
http_client_factory: HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
agent_identity_policy: AgentIdentityAuthPolicy::JwtOnly,
|
||||
session_source: SessionSource::Exec,
|
||||
session_id: "session-1".to_owned(),
|
||||
thread_id: "thread-1".to_owned(),
|
||||
originator: Some("guardian-v2-test".to_owned()),
|
||||
@@ -843,13 +831,8 @@ async fn sampler_returns_classification_token_before_terminal_response_events()
|
||||
let sampler = connect_sampler(LunaSamplerConfig {
|
||||
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::Disabled,
|
||||
inherit_parent_cyber_access_program: true,
|
||||
workspace_routing: codex_model_provider::WorkspaceRoutingContext::new(
|
||||
"https://chatgpt.com/backend-api".into(),
|
||||
),
|
||||
provider,
|
||||
http_client_factory: HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
agent_identity_policy: AgentIdentityAuthPolicy::JwtOnly,
|
||||
session_source: SessionSource::Exec,
|
||||
session_id: "session-1".to_owned(),
|
||||
thread_id: "thread-1".to_owned(),
|
||||
originator: None,
|
||||
@@ -1230,9 +1213,9 @@ async fn parent_response_id_survives_classifier_transport_retry() -> Result<()>
|
||||
"{}/backend-api/codex",
|
||||
base_url.trim_end_matches("/v1")
|
||||
))),
|
||||
Some(AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
)),
|
||||
Some(AuthManager::from_auth_for_testing(CodexAuth::from_api_key(
|
||||
"Test API Key",
|
||||
))),
|
||||
);
|
||||
}
|
||||
let metrics = Arc::new(RecordingMetrics::default());
|
||||
|
||||
@@ -8,8 +8,6 @@ use codex_core::config::Config;
|
||||
use codex_core::cyber_access_program::ApiKeyCyberAccessPrograms;
|
||||
use codex_extension_api::ThreadOriginator;
|
||||
use codex_extension_api::ThreadStartInput;
|
||||
use codex_features::Feature;
|
||||
use codex_login::AgentIdentityAuthPolicy;
|
||||
|
||||
use super::sampler::LunaSamplerConfig;
|
||||
use super::sampler::MODEL;
|
||||
@@ -49,19 +47,8 @@ pub(super) async fn sampler_config(
|
||||
LunaSamplerConfig {
|
||||
api_key_cyber_access_programs: ApiKeyCyberAccessPrograms::from_config(input.config),
|
||||
inherit_parent_cyber_access_program,
|
||||
workspace_routing: input
|
||||
.thread_store
|
||||
.get_or_init(|| input.config.workspace_routing_context())
|
||||
.as_ref()
|
||||
.clone(),
|
||||
provider: auth.model_provider(input.config.model_provider.clone()),
|
||||
http_client_factory: input.config.http_client_factory(),
|
||||
agent_identity_policy: if input.config.features.enabled(Feature::UseAgentIdentity) {
|
||||
AgentIdentityAuthPolicy::ChatGptAuth
|
||||
} else {
|
||||
AgentIdentityAuthPolicy::JwtOnly
|
||||
},
|
||||
session_source: input.session_source.clone(),
|
||||
session_id: input.session_store.level_id().to_string(),
|
||||
thread_id: input.thread_store.level_id().to_string(),
|
||||
originator: input
|
||||
|
||||
@@ -122,7 +122,7 @@ async fn trusts_connector_declared_by_home_owned_plugin() -> Result<()> {
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let test = test_codex()
|
||||
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
|
||||
.with_auth(CodexAuth::from_api_key("Test API Key"))
|
||||
.with_pre_build_hook(|home| {
|
||||
let plugin_root = home.join("plugins/cache/test/trusted/local");
|
||||
std::fs::create_dir_all(plugin_root.join(".codex-plugin"))
|
||||
|
||||
Reference in New Issue
Block a user