Conversation
|
|
||
| /// DEPRECATED: Use [Config::load_with_cli_overrides()] instead because this | ||
| /// codepath is not guaranteed to honor [ConfigRequirements]. | ||
| pub async fn load_config_as_toml_with_cli_overrides( |
There was a problem hiding this comment.
load_config_as_toml_with_cli_overrides is returning ConfigToml while load_with_cli_overrides returns Config. How are they substituting each other?
There was a problem hiding this comment.
Also what is [ConfigRequirements]
There was a problem hiding this comment.
Sorry, some of this came from my in-flight PR that I have stacked on top and then I split it out to create a smaller PR.
ConfigRequirements is a new abstraction we are introducing to ensure enterprise-level restrictions are enforced when creating a Config.
Admittedly, one is not a substitute for the other, but the higher-level goal is that callers should generally never work with ConfigToml directly, only a fully-instantiated Config, because using a raw ConfigToml runs the risk that you are using a value where ConfigRequirements have not been enforced.
| impl Config { | ||
| /// Meant to be used exclusively for tests: `load_with_overrides()` should | ||
| /// be used in all other cases. | ||
| /// Meant to be used exclusively for tests: |
There was a problem hiding this comment.
This comment always confused me. It's saying exclusive for tests but it's used in normal code and doesn't have cfg test around it.
There was a problem hiding this comment.
I know...the problem is that it needs to access things that are private to this file, but we also need to make it available to integration tests. Adding #[cfg(test)] would make it so it is not available to integration tests, so we're kinda stuck.
There was a problem hiding this comment.
some places in the code is using #[cfg(any(test, feature = "test-support"))] not sure if this is possible here. we probably have core tests that are using it. It's still being used in non tests load_with_cli_overrides and load_with_cli_overrides_and_harness_overrides. Is this expected?
This PR does various types of cleanup before I can proceed with more ambitious changes to config loading.
First, I noticed duplicated code across these two methods:
codex/codex-rs/core/src/config/mod.rs
Lines 314 to 324 in 774bd9e
codex/codex-rs/core/src/config/mod.rs
Lines 334 to 344 in 774bd9e
This has now been consolidated in
load_config_as_toml_with_cli_overrides().Further, I noticed that
Config::load_with_cli_overrides()took two similar arguments:codex/codex-rs/core/src/config/mod.rs
Lines 308 to 311 in 774bd9e
The difference between
cli_overridesandoverrideswas not immediately obvious to me. At first glance, it appears that one should be able to be expressed in terms of the other, but it turns out that some fields ofConfigOverrides(such ascwdandcodex_linux_sandbox_exe) are, by design, not configurable via a.tomlfile or a command-line--configflag.That said, I discovered that many callers of
Config::load_with_cli_overrides()were passingConfigOverrides::default()foroverrides, so I created two separate methods:Config::load_with_cli_overrides(cli_overrides: Vec<(String, TomlValue)>)Config::load_with_cli_overrides_and_harness_overrides(cli_overrides: Vec<(String, TomlValue)>, harness_overrides: ConfigOverrides)The latter has a long name, as it is not what should be used in the common case, so the extra typing is designed to draw attention to this fact. I tried to update the existing callsites to use the shorter name, where possible.
Further, in the cases where
ConfigOverridesis used, usually only a limited subset of fields are actually set, so I updated the declarations to leverage..Default::default()where possible.