mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Add Statsig bootstrap to the Codex backend client (#63448)
## What changed Expose `Client::statsig_bootstrap` and `StatsigBootstrapContext` so callers can fetch server-evaluated Statsig values using the client's existing authentication. The client posts the targeting context to the bootstrap endpoint for its configured API and returns the `statsigPayload` string. ## Testing Add a mock-server test that checks the ChatGPT route, bearer token, account header, and JSON request body, and verifies that the client returns the payload string from the response. GitOrigin-RevId: 0bbe812ee036c5bf744f9e07d01b70e9c241cce3
This commit is contained in:
@@ -14,6 +14,7 @@ use pretty_assertions::assert_eq;
|
||||
use wiremock::Mock;
|
||||
use wiremock::MockServer;
|
||||
use wiremock::ResponseTemplate;
|
||||
use wiremock::matchers::body_json;
|
||||
use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
@@ -60,6 +61,52 @@ async fn transcribe_audio_posts_multipart_file_and_returns_text() {
|
||||
assert_eq!(request.body, expected_body);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn statsig_bootstrap_uses_chatgpt_auth_and_unwraps_evaluations() -> Result<()> {
|
||||
let server = MockServer::start().await;
|
||||
let payload = r#"{"feature_gates":{}}"#;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/backend-api/wham/statsig/bootstrap"))
|
||||
.and(header("authorization", "Bearer test-token"))
|
||||
.and(header("chatgpt-account-id", "test-account"))
|
||||
.and(body_json(serde_json::json!({
|
||||
"target_app": "PUBLIC-EVERYTHING-LEAKS-codex-cli",
|
||||
"stable_id": "test-install",
|
||||
"app_version": "1.0",
|
||||
"locale": "en-US",
|
||||
"system_name": "test-os",
|
||||
"system_version": "1",
|
||||
"window_type": "cli",
|
||||
"brand_name": "codex"
|
||||
})))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
|
||||
"statsigPayload": payload
|
||||
})))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let client = Client::new_without_redirects(
|
||||
format!("{}/backend-api", server.uri()),
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
)
|
||||
.with_bearer_token("test-token".into())?
|
||||
.with_chatgpt_account_id("test-account");
|
||||
let values = client
|
||||
.statsig_bootstrap(&crate::StatsigBootstrapContext {
|
||||
target_app: "PUBLIC-EVERYTHING-LEAKS-codex-cli",
|
||||
stable_id: "test-install".into(),
|
||||
app_version: "1.0".into(),
|
||||
locale: Some("en-US".into()),
|
||||
system_name: "test-os".into(),
|
||||
system_version: "1".into(),
|
||||
window_type: "cli",
|
||||
brand_name: "codex",
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(values, payload);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn client_preserves_supplied_factory_and_typed_policy_denial() {
|
||||
let controller = codex_http_client::NetworkPolicyController::default();
|
||||
|
||||
Reference in New Issue
Block a user