29th platform `openai-codex` (uses_oauth, Responses wire). PKCE-localhost login at auth.openai.com (client app_EMoamEEZ73f0CkXaXp7hrann, redirect localhost:1455/auth/ callback, form token exchange, fresh-random state) reusing the claude-pro-max flow; OAuthFlow::PkceLocalhost gained a redirect_path and OAuthConfig an authorize_extra (empty elsewhere, so claude/xai/copilot authorize URLs stay byte-identical). Codex-specific: the access token is a JWT carrying chatgpt_account_id, which becomes the `chatgpt-account-id` inference header. It is derived STATELESSLY from whichever bearer rides each request (so a rotated token needs no persisted field), and BOTH login and refresh fail fast when the claim is absent — gated on the explicit OAuthConfig.requires_chatgpt_account_id fact, never inferred from the token-body encoding (a plain form endpoint is the OAuth norm and must not inherit this). Inference rides the existing Responses wire at chatgpt.com/backend-api/codex → /responses, with codex headers (chatgpt-account-id, originator, OpenAI-Beta responses=experimental, codex UA) gated on SamplerConfig.openai_codex so API-key `openai` stays byte-identical; store:false was already the global Responses default. Catalog is HARDCODED (no live endpoint exists for this backend; read from the official Codex CLI's model cache): gpt-5.6-sol/terra/luna + gpt-5.5, ctx 272000, each with its real reasoning levels (low..ultra — ReasoningEffort gained Ultra). Excluded: gpt-5.3-codex-spark (supported_in_api=false), gpt-5.4/-mini and codex-auto-review (hidden) — they would list but fail at inference. The fetch short-circuits before any HTTP; Kigi never shells out to the codex CLI or reads ~/.codex. Security review fixes: redact any `account-id` header from request logs (it was reaching debug logs), strict 3-segment JWT check (fail closed), refresh no longer fails open on a missing claim. Inherits leak-safe pooled routing (scope oauth/openai-codex) — never the Kimi token. Full gate green (234 suites, 0 warnings).
65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
//! Shared helpers for kigi-shell integration tests.
|
|
|
|
use kigi_shell::sampling::{ApiBackend, Client, SamplerConfig};
|
|
|
|
/// Create a sampling client configured for a mock server. Shared by the
|
|
/// integration tests so the ~30-field `SamplerConfig` literal lives in one
|
|
/// place (`SamplerConfig` has no `Default`).
|
|
pub fn create_test_client(base_url: &str, api_backend: ApiBackend) -> Client {
|
|
create_test_client_with_extra_headers(base_url, api_backend, &[])
|
|
}
|
|
|
|
/// Like [`create_test_client`] but seeds `SamplerConfig::extra_headers`, so a
|
|
/// test can assert that session-injected headers reach the wire.
|
|
pub fn create_test_client_with_extra_headers(
|
|
base_url: &str,
|
|
api_backend: ApiBackend,
|
|
extra_headers: &[(&str, &str)],
|
|
) -> Client {
|
|
Client::new(test_sampler_config(base_url, api_backend, extra_headers)).unwrap()
|
|
}
|
|
|
|
/// The shared mock-server `SamplerConfig`; tests needing a non-default field
|
|
/// (e.g. `doom_loop_recovery`) mutate the returned value before building the
|
|
/// client themselves.
|
|
pub fn test_sampler_config(
|
|
base_url: &str,
|
|
api_backend: ApiBackend,
|
|
extra_headers: &[(&str, &str)],
|
|
) -> SamplerConfig {
|
|
// Shell `Client` is `kigi_sampler::SamplingClient`, which takes a
|
|
// `SamplerConfig` directly. Construct one inline here.
|
|
SamplerConfig {
|
|
api_key: Some("test-api-key".to_string()),
|
|
base_url: base_url.to_string(),
|
|
model: "test-model".to_string(),
|
|
max_completion_tokens: Some(1000),
|
|
temperature: Some(0.7),
|
|
top_p: None,
|
|
api_backend,
|
|
auth_scheme: Default::default(),
|
|
anthropic_oauth: false,
|
|
github_copilot: false,
|
|
openai_codex: false,
|
|
chat_compat: Default::default(),
|
|
extra_headers: extra_headers
|
|
.iter()
|
|
.map(|(k, v)| (k.to_string(), v.to_string()))
|
|
.collect(),
|
|
context_window: 256_000,
|
|
force_http1: false,
|
|
max_retries: None,
|
|
stream_tool_calls: false,
|
|
idle_timeout_secs: None,
|
|
reasoning_effort: None,
|
|
origin_client: None,
|
|
attribution_callback: None,
|
|
bearer_resolver: None,
|
|
supports_backend_search: false,
|
|
compactions_remaining: None,
|
|
compaction_at_tokens: None,
|
|
doom_loop_recovery: None,
|
|
header_injector: None,
|
|
}
|
|
}
|