Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

feat: ignore keyring on 0.0.0 (#17221)

jif-oai4ffe6c2ce639
diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs
index a205b2041c..0ae1f55690 100644
--- a/codex-rs/core/src/config/config_tests.rs
+++ b/codex-rs/core/src/config/config_tests.rs
@@ -1525,7 +1525,7 @@ fn config_defaults_to_file_cli_auth_store_mode() -> std::io::Result<()> {
}
#[test]
-fn config_honors_explicit_keyring_auth_store_mode() -> std::io::Result<()> {
+fn config_resolves_explicit_keyring_auth_store_mode() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
let cfg = ConfigToml {
cli_auth_credentials_store: Some(AuthCredentialsStoreMode::Keyring),
@@ -1540,14 +1540,17 @@ fn config_honors_explicit_keyring_auth_store_mode() -> std::io::Result<()> {
assert_eq!(
config.cli_auth_credentials_store_mode,
- AuthCredentialsStoreMode::Keyring,
+ resolve_cli_auth_credentials_store_mode(
+ AuthCredentialsStoreMode::Keyring,
+ env!("CARGO_PKG_VERSION"),
+ ),
);
Ok(())
}
#[test]
-fn config_defaults_to_auto_oauth_store_mode() -> std::io::Result<()> {
+fn config_resolves_default_oauth_store_mode() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
let cfg = ConfigToml::default();
@@ -1559,12 +1562,66 @@ fn config_defaults_to_auto_oauth_store_mode() -> std::io::Result<()> {
assert_eq!(
config.mcp_oauth_credentials_store_mode,
- OAuthCredentialsStoreMode::Auto,
+ resolve_mcp_oauth_credentials_store_mode(
+ OAuthCredentialsStoreMode::Auto,
+ env!("CARGO_PKG_VERSION"),
+ ),
);
Ok(())
}
+#[test]
+fn local_dev_builds_force_file_cli_auth_store_modes() {
+ assert_eq!(
+ resolve_cli_auth_credentials_store_mode(
+ AuthCredentialsStoreMode::Keyring,
+ LOCAL_DEV_BUILD_VERSION,
+ ),
+ AuthCredentialsStoreMode::File,
+ );
+ assert_eq!(
+ resolve_cli_auth_credentials_store_mode(
+ AuthCredentialsStoreMode::Auto,
+ LOCAL_DEV_BUILD_VERSION,
+ ),
+ AuthCredentialsStoreMode::File,
+ );
+ assert_eq!(
+ resolve_cli_auth_credentials_store_mode(
+ AuthCredentialsStoreMode::Ephemeral,
+ LOCAL_DEV_BUILD_VERSION,
+ ),
+ AuthCredentialsStoreMode::Ephemeral,
+ );
+ assert_eq!(
+ resolve_cli_auth_credentials_store_mode(AuthCredentialsStoreMode::Keyring, "1.2.3"),
+ AuthCredentialsStoreMode::Keyring,
+ );
+}
+
+#[test]
+fn local_dev_builds_force_file_mcp_oauth_store_modes() {
+ assert_eq!(
+ resolve_mcp_oauth_credentials_store_mode(
+ OAuthCredentialsStoreMode::Keyring,
+ LOCAL_DEV_BUILD_VERSION,
+ ),
+ OAuthCredentialsStoreMode::File,
+ );
+ assert_eq!(
+ resolve_mcp_oauth_credentials_store_mode(
+ OAuthCredentialsStoreMode::Auto,
+ LOCAL_DEV_BUILD_VERSION,
+ ),
+ OAuthCredentialsStoreMode::File,
+ );
+ assert_eq!(
+ resolve_mcp_oauth_credentials_store_mode(OAuthCredentialsStoreMode::Keyring, "1.2.3"),
+ OAuthCredentialsStoreMode::Keyring,
+ );
+}
+
#[test]
fn feedback_enabled_defaults_to_true() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
@@ -1922,7 +1979,10 @@ async fn managed_config_overrides_oauth_store_mode() -> anyhow::Result<()> {
)?;
assert_eq!(
final_config.mcp_oauth_credentials_store_mode,
- OAuthCredentialsStoreMode::Keyring,
+ resolve_mcp_oauth_credentials_store_mode(
+ OAuthCredentialsStoreMode::Keyring,
+ env!("CARGO_PKG_VERSION"),
+ ),
);
Ok(())
@@ -4514,7 +4574,10 @@ fn test_precedence_fixture_with_o3_profile() -> std::io::Result<()> {
cwd: fixture.cwd(),
cli_auth_credentials_store_mode: Default::default(),
mcp_servers: Constrained::allow_any(HashMap::new()),
- mcp_oauth_credentials_store_mode: Default::default(),
+ mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(
+ Default::default(),
+ LOCAL_DEV_BUILD_VERSION,
+ ),
mcp_oauth_callback_port: None,
mcp_oauth_callback_url: None,
model_providers: fixture.model_provider_map.clone(),
@@ -4660,7 +4723,10 @@ fn test_precedence_fixture_with_gpt3_profile() -> std::io::Result<()> {
cwd: fixture.cwd(),
cli_auth_credentials_store_mode: Default::default(),
mcp_servers: Constrained::allow_any(HashMap::new()),
- mcp_oauth_credentials_store_mode: Default::default(),
+ mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(
+ Default::default(),
+ LOCAL_DEV_BUILD_VERSION,
+ ),
mcp_oauth_callback_port: None,
mcp_oauth_callback_url: None,
model_providers: fixture.model_provider_map.clone(),
@@ -4804,7 +4870,10 @@ fn test_precedence_fixture_with_zdr_profile() -> std::io::Result<()> {
cwd: fixture.cwd(),
cli_auth_credentials_store_mode: Default::default(),
mcp_servers: Constrained::allow_any(HashMap::new()),
- mcp_oauth_credentials_store_mode: Default::default(),
+ mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(
+ Default::default(),
+ LOCAL_DEV_BUILD_VERSION,
+ ),
mcp_oauth_callback_port: None,
mcp_oauth_callback_url: None,
model_providers: fixture.model_provider_map.clone(),
@@ -4934,7 +5003,10 @@ fn test_precedence_fixture_with_gpt5_profile() -> std::io::Result<()> {
cwd: fixture.cwd(),
cli_auth_credentials_store_mode: Default::default(),
mcp_servers: Constrained::allow_any(HashMap::new()),
- mcp_oauth_credentials_store_mode: Default::default(),
+ mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(
+ Default::default(),
+ LOCAL_DEV_BUILD_VERSION,
+ ),
mcp_oauth_callback_port: None,
mcp_oauth_callback_url: None,
model_providers: fixture.model_provider_map.clone(),
diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs
index 9b2b06e0a8..d6d08c4d90 100644
--- a/codex-rs/core/src/config/mod.rs
+++ b/codex-rs/core/src/config/mod.rs
@@ -124,6 +124,7 @@ pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB
pub(crate) const DEFAULT_AGENT_MAX_THREADS: Option<usize> = Some(6);
pub(crate) const DEFAULT_AGENT_MAX_DEPTH: i32 = 1;
pub(crate) const DEFAULT_AGENT_JOB_MAX_RUNTIME_SECONDS: Option<u64> = None;
+const LOCAL_DEV_BUILD_VERSION: &str = "0.0.0";
pub const CONFIG_TOML_FILE: &str = "config.toml";
@@ -141,6 +142,32 @@ fn resolve_sqlite_home_env(resolved_cwd: &Path) -> Option<PathBuf> {
}
}
+fn resolve_cli_auth_credentials_store_mode(
+ configured: AuthCredentialsStoreMode,
+ package_version: &str,
+) -> AuthCredentialsStoreMode {
+ match (package_version, configured) {
+ (
+ LOCAL_DEV_BUILD_VERSION,
+ AuthCredentialsStoreMode::Keyring | AuthCredentialsStoreMode::Auto,
+ ) => AuthCredentialsStoreMode::File,
+ (_, mode) => mode,
+ }
+}
+
+fn resolve_mcp_oauth_credentials_store_mode(
+ configured: OAuthCredentialsStoreMode,
+ package_version: &str,
+) -> OAuthCredentialsStoreMode {
+ match (package_version, configured) {
+ (
+ LOCAL_DEV_BUILD_VERSION,
+ OAuthCredentialsStoreMode::Keyring | OAuthCredentialsStoreMode::Auto,
+ ) => OAuthCredentialsStoreMode::File,
+ (_, mode) => mode,
+ }
+}
+
#[cfg(test)]
pub(crate) fn test_config() -> Config {
let codex_home = tempfile::tempdir().expect("create temp dir");
@@ -2014,11 +2041,17 @@ impl Config {
include_environment_context,
// The config.toml omits "_mode" because it's a config file. However, "_mode"
// is important in code to differentiate the mode from the store implementation.
- cli_auth_credentials_store_mode: cfg.cli_auth_credentials_store.unwrap_or_default(),
+ cli_auth_credentials_store_mode: resolve_cli_auth_credentials_store_mode(
+ cfg.cli_auth_credentials_store.unwrap_or_default(),
+ env!("CARGO_PKG_VERSION"),
+ ),
mcp_servers,
// The config.toml omits "_mode" because it's a config file. However, "_mode"
// is important in code to differentiate the mode from the store implementation.
- mcp_oauth_credentials_store_mode: cfg.mcp_oauth_credentials_store.unwrap_or_default(),
+ mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(
+ cfg.mcp_oauth_credentials_store.unwrap_or_default(),
+ env!("CARGO_PKG_VERSION"),
+ ),
mcp_oauth_callback_port: cfg.mcp_oauth_callback_port,
mcp_oauth_callback_url: cfg.mcp_oauth_callback_url.clone(),
model_providers,