mirror of
https://github.com/openai/codex.git
synced 2026-04-25 23:24:55 +00:00
This attempts to tighten up the types related to "config layers." Currently, `ConfigLayerEntry` is defined as follows:bef36f4ae7/codex-rs/core/src/config_loader/state.rs (L19-L25)but the `source` field is a bit of a lie, as: - for `ConfigLayerName::Mdm`, it is `"com.openai.codex/config_toml_base64"` - for `ConfigLayerName::SessionFlags`, it is `"--config"` - for `ConfigLayerName::User`, it is `"config.toml"` (just the file name, not the path to the `config.toml` on disk that was read) - for `ConfigLayerName::System`, it seems like it is usually `/etc/codex/managed_config.toml` in practice, though on Windows, it is `%CODEX_HOME%/managed_config.toml`:bef36f4ae7/codex-rs/core/src/config_loader/layer_io.rs (L84-L101)All that is to say, in three out of the four `ConfigLayerName`, `source` is a `PathBuf` that is not an absolute path (or even a true path). This PR tries to uplevel things by eliminating `source` from `ConfigLayerEntry` and turning `ConfigLayerName` into a disjoint union named `ConfigLayerSource` that has the appropriate metadata for each variant, favoring the use of `AbsolutePathBuf` where appropriate: ```rust pub enum ConfigLayerSource { /// Managed preferences layer delivered by MDM (macOS only). #[serde(rename_all = "camelCase")] #[ts(rename_all = "camelCase")] Mdm { domain: String, key: String }, /// Managed config layer from a file (usually `managed_config.toml`). #[serde(rename_all = "camelCase")] #[ts(rename_all = "camelCase")] System { file: AbsolutePathBuf }, /// Session-layer overrides supplied via `-c`/`--config`. SessionFlags, /// User config layer from a file (usually `config.toml`). #[serde(rename_all = "camelCase")] #[ts(rename_all = "camelCase")] User { file: AbsolutePathBuf }, } ```
55 lines
1.9 KiB
Rust
55 lines
1.9 KiB
Rust
#![cfg(not(target_os = "windows"))]
|
|
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
|
|
|
use codex_core::default_client::CODEX_INTERNAL_ORIGINATOR_OVERRIDE_ENV_VAR;
|
|
use core_test_support::responses;
|
|
use core_test_support::test_codex_exec::test_codex_exec;
|
|
use wiremock::matchers::header;
|
|
|
|
/// Verify that when the server reports an error, `codex-exec` exits with a
|
|
/// non-zero status code so automation can detect failures.
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn send_codex_exec_originator() -> anyhow::Result<()> {
|
|
let test = test_codex_exec();
|
|
|
|
let server = responses::start_mock_server().await;
|
|
let body = responses::sse(vec![
|
|
responses::ev_response_created("response_1"),
|
|
responses::ev_assistant_message("response_1", "Hello, world!"),
|
|
responses::ev_completed("response_1"),
|
|
]);
|
|
responses::mount_sse_once_match(&server, header("Originator", "codex_exec"), body).await;
|
|
|
|
test.cmd_with_server(&server)
|
|
.env_remove(CODEX_INTERNAL_ORIGINATOR_OVERRIDE_ENV_VAR)
|
|
.arg("--skip-git-repo-check")
|
|
.arg("tell me something")
|
|
.assert()
|
|
.code(0);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn supports_originator_override() -> anyhow::Result<()> {
|
|
let test = test_codex_exec();
|
|
|
|
let server = responses::start_mock_server().await;
|
|
let body = responses::sse(vec![
|
|
responses::ev_response_created("response_1"),
|
|
responses::ev_assistant_message("response_1", "Hello, world!"),
|
|
responses::ev_completed("response_1"),
|
|
]);
|
|
responses::mount_sse_once_match(&server, header("Originator", "codex_exec_override"), body)
|
|
.await;
|
|
|
|
test.cmd_with_server(&server)
|
|
.env("CODEX_INTERNAL_ORIGINATOR_OVERRIDE", "codex_exec_override")
|
|
.arg("--skip-git-repo-check")
|
|
.arg("tell me something")
|
|
.assert()
|
|
.code(0);
|
|
|
|
Ok(())
|
|
}
|