mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Make nested enum config warnings non-blocking
This commit is contained in:
@@ -37,6 +37,7 @@ use codex_model_provider_info::ModelProviderInfo;
|
||||
use codex_model_provider_info::OLLAMA_CHAT_PROVIDER_REMOVED_ERROR;
|
||||
use codex_model_provider_info::OLLAMA_OSS_PROVIDER_ID;
|
||||
use codex_model_provider_info::OPENAI_PROVIDER_ID;
|
||||
use codex_model_provider_info::WireApi;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_protocol::config_types::Personality;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
@@ -1002,7 +1003,30 @@ fn deserialize_model_providers<'de, D>(
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let model_providers = HashMap::<String, ModelProviderInfo>::deserialize(deserializer)?;
|
||||
let raw_model_providers = HashMap::<String, TomlValue>::deserialize(deserializer)?;
|
||||
let mut model_providers = HashMap::new();
|
||||
for (key, value) in raw_model_providers {
|
||||
let provider = match value.clone().try_into::<ModelProviderInfo>() {
|
||||
Ok(provider) => provider,
|
||||
Err(err) => {
|
||||
// Invalid `wire_api` is already reported by the schema warning
|
||||
// pass. Remove just that leaf so the provider can fall back to
|
||||
// its default wire API without hiding unrelated provider errors.
|
||||
let mut without_wire_api = value;
|
||||
let removed_wire_api = without_wire_api
|
||||
.as_table_mut()
|
||||
.and_then(|table| table.remove("wire_api"))
|
||||
.is_some_and(|wire_api| wire_api.try_into::<WireApi>().is_err());
|
||||
if !removed_wire_api {
|
||||
return Err(serde::de::Error::custom(err.to_string()));
|
||||
}
|
||||
without_wire_api
|
||||
.try_into::<ModelProviderInfo>()
|
||||
.map_err(serde::de::Error::custom)?
|
||||
}
|
||||
};
|
||||
model_providers.insert(key, provider);
|
||||
}
|
||||
validate_model_providers(&model_providers).map_err(serde::de::Error::custom)?;
|
||||
Ok(model_providers)
|
||||
}
|
||||
|
||||
@@ -508,6 +508,7 @@ pub enum OtelExporterKind {
|
||||
}
|
||||
|
||||
/// OTEL settings loaded from config.toml. Fields are optional so we can apply defaults.
|
||||
#[serde_as]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct OtelConfigToml {
|
||||
@@ -518,12 +519,18 @@ pub struct OtelConfigToml {
|
||||
pub environment: Option<String>,
|
||||
|
||||
/// Optional log exporter
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub exporter: Option<OtelExporterKind>,
|
||||
|
||||
/// Optional trace exporter
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub trace_exporter: Option<OtelExporterKind>,
|
||||
|
||||
/// Optional metrics exporter
|
||||
#[serde(default)]
|
||||
#[serde_as(deserialize_as = "DefaultOnError")]
|
||||
pub metrics_exporter: Option<OtelExporterKind>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1710,6 +1710,7 @@
|
||||
"$ref": "#/definitions/OtelExporterKind"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional log exporter"
|
||||
},
|
||||
"log_user_prompt": {
|
||||
@@ -1722,6 +1723,7 @@
|
||||
"$ref": "#/definitions/OtelExporterKind"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional metrics exporter"
|
||||
},
|
||||
"trace_exporter": {
|
||||
@@ -1730,6 +1732,7 @@
|
||||
"$ref": "#/definitions/OtelExporterKind"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Optional trace exporter"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -25,6 +25,7 @@ use codex_config::loader::load_config_layers_state;
|
||||
use codex_config::loader::load_requirements_toml;
|
||||
use codex_config::version_for_toml;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_model_provider_info::WireApi;
|
||||
use codex_protocol::config_types::TrustLevel;
|
||||
use codex_protocol::config_types::WebSearchMode;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -33,6 +34,7 @@ use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use tempfile::tempdir;
|
||||
@@ -178,6 +180,64 @@ context_size = "galactic"
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn nested_invalid_enum_values_emit_warnings_without_poisoning_config() -> anyhow::Result<()> {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
let contents = r#"
|
||||
[model_providers.custom]
|
||||
name = "Custom"
|
||||
base_url = "https://example.invalid/v1"
|
||||
wire_api = "telegraph"
|
||||
|
||||
[otel.exporter.otlp-http]
|
||||
endpoint = "http://localhost:4318/v1/logs"
|
||||
protocol = "xml"
|
||||
|
||||
[otel.trace_exporter.otlp-http]
|
||||
endpoint = "http://localhost:4318/v1/traces"
|
||||
protocol = "yaml"
|
||||
"#;
|
||||
let config_path = tmp.path().join(CONFIG_TOML_FILE);
|
||||
std::fs::write(&config_path, contents).expect("write config");
|
||||
|
||||
let cwd = AbsolutePathBuf::try_from(tmp.path()).expect("cwd");
|
||||
let layers = load_config_layers_state(
|
||||
LOCAL_FS.as_ref(),
|
||||
tmp.path(),
|
||||
Some(cwd),
|
||||
&[] as &[(String, TomlValue)],
|
||||
LoaderOverrides::default(),
|
||||
CloudRequirementsLoader::default(),
|
||||
&codex_config::NoopThreadConfigLoader,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (_effective_config, config_toml, enum_warnings) =
|
||||
layers.deserialize_effective_config_with_warnings()?;
|
||||
let otel = config_toml.otel.expect("otel config should deserialize");
|
||||
let expected_warnings = BTreeSet::from([
|
||||
"Ignoring invalid config value at model_providers.custom.wire_api: \"telegraph\""
|
||||
.to_string(),
|
||||
"Ignoring invalid config value at otel.exporter.otlp-http.protocol: \"xml\"".to_string(),
|
||||
"Ignoring invalid config value at otel.trace_exporter.otlp-http.protocol: \"yaml\""
|
||||
.to_string(),
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
(
|
||||
config_toml
|
||||
.model_providers
|
||||
.get("custom")
|
||||
.map(|provider| provider.wire_api),
|
||||
otel.exporter,
|
||||
otel.trace_exporter,
|
||||
enum_warnings.into_iter().collect::<BTreeSet<_>>(),
|
||||
),
|
||||
(Some(WireApi::Responses), None, None, expected_warnings)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn invalid_higher_precedence_enum_warns_without_mutating_merge() -> anyhow::Result<()> {
|
||||
let tmp = tempdir().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user