mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Discover model catalogs from HTTPS gateways (#63807)
## Why A custom gateway can serve a Codex model catalog at its existing `/models` route. Requiring a separate `model_catalog_url` leaves that catalog undiscovered when only `base_url` is configured. ## What changed Probe `/models` automatically for custom providers with a query-free HTTPS base URL and no explicit catalog URL. Use a valid Codex catalog as the model picker inventory. If discovery fails, keep the picker usable with an available catalog or the bundled models. Gateway login and token refresh errors still propagate. ## Testing Add HTTPS app-server tests that verify the authenticated `/v1/models` request, picker population from a Codex catalog, and fallback to bundled models for a generic OpenAI model list or a `403` response. GitOrigin-RevId: 654095be1c221d79d932acde8b7289bc4cad0437
This commit is contained in:
@@ -5,8 +5,11 @@ use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_rustls::TlsAcceptor;
|
||||
use tokio_rustls::rustls;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
use wiremock::MockServer;
|
||||
|
||||
pub(super) async fn tls_listener(home: &Path) -> Result<(TcpListener, TlsAcceptor, PathBuf)> {
|
||||
let cert = rcgen::generate_simple_self_signed(vec!["localhost".into(), "127.0.0.1".into()])?;
|
||||
@@ -25,3 +28,24 @@ pub(super) async fn tls_listener(home: &Path) -> Result<(TcpListener, TlsAccepto
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
Ok((listener, acceptor, ca_path))
|
||||
}
|
||||
|
||||
pub(super) async fn https_mock_server(
|
||||
home: &Path,
|
||||
server: &MockServer,
|
||||
) -> Result<(String, PathBuf, AbortOnDropHandle<()>)> {
|
||||
let (listener, acceptor, ca_path) = tls_listener(home).await?;
|
||||
let origin_url = format!("https://{}", listener.local_addr()?);
|
||||
let origin = *server.address();
|
||||
let tls = AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
let acceptor = acceptor.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut stream = acceptor.accept(stream).await?;
|
||||
let mut upstream = TcpStream::connect(origin).await?;
|
||||
tokio::io::copy_bidirectional(&mut stream, &mut upstream).await?;
|
||||
Ok::<_, std::io::Error>(())
|
||||
});
|
||||
}
|
||||
}));
|
||||
Ok((origin_url, ca_path, tls))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user