chore: migrate from Config::load_from_base_config_with_overrides to ConfigBuilder (#8276)

https://github.com/openai/codex/pull/8235 introduced `ConfigBuilder` and
this PR updates all call non-test call sites to use it instead of
`Config::load_from_base_config_with_overrides()`.

This is important because `load_from_base_config_with_overrides()` uses
an empty `ConfigRequirements`, which is a reasonable default for testing
so the tests are not influenced by the settings on the host. This method
is now guarded by `#[cfg(test)]` so it cannot be used by business logic.

Because `ConfigBuilder::build()` is `async`, many of the test methods
had to be migrated to be `async`, as well. On the bright side, this made
it possible to eliminate a bunch of `block_on_future()` stuff.
This commit is contained in:
Michael Bolin
2025-12-18 16:12:52 -08:00
committed by GitHub
parent 2d9826098e
commit 3d4ced3ff5
42 changed files with 1081 additions and 1176 deletions

View File

@@ -302,21 +302,19 @@ fn extract_frontmatter(contents: &str) -> Option<String> {
#[cfg(test)]
mod tests {
use super::*;
use crate::config::ConfigOverrides;
use crate::config::ConfigToml;
use crate::config::ConfigBuilder;
use codex_protocol::protocol::SkillScope;
use pretty_assertions::assert_eq;
use std::path::Path;
use std::process::Command;
use tempfile::TempDir;
fn make_config(codex_home: &TempDir) -> Config {
let mut config = Config::load_from_base_config_with_overrides(
ConfigToml::default(),
ConfigOverrides::default(),
codex_home.path().to_path_buf(),
)
.expect("defaults for test should always succeed");
async fn make_config(codex_home: &TempDir) -> Config {
let mut config = ConfigBuilder::default()
.codex_home(codex_home.path().to_path_buf())
.build()
.await
.expect("defaults for test should always succeed");
config.cwd = codex_home.path().to_path_buf();
config
@@ -352,11 +350,11 @@ mod tests {
path
}
#[test]
fn loads_valid_skill() {
#[tokio::test]
async fn loads_valid_skill() {
let codex_home = tempfile::tempdir().expect("tempdir");
write_skill(&codex_home, "demo", "demo-skill", "does things\ncarefully");
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert!(
@@ -376,15 +374,15 @@ mod tests {
);
}
#[test]
fn loads_short_description_from_metadata() {
#[tokio::test]
async fn loads_short_description_from_metadata() {
let codex_home = tempfile::tempdir().expect("tempdir");
let skill_dir = codex_home.path().join("skills/demo");
fs::create_dir_all(&skill_dir).unwrap();
let contents = "---\nname: demo-skill\ndescription: long description\nmetadata:\n short-description: short summary\n---\n\n# Body\n";
fs::write(skill_dir.join(SKILLS_FILENAME), contents).unwrap();
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert!(
outcome.errors.is_empty(),
@@ -398,8 +396,8 @@ mod tests {
);
}
#[test]
fn enforces_short_description_length_limits() {
#[tokio::test]
async fn enforces_short_description_length_limits() {
let codex_home = tempfile::tempdir().expect("tempdir");
let skill_dir = codex_home.path().join("skills/demo");
fs::create_dir_all(&skill_dir).unwrap();
@@ -409,7 +407,7 @@ mod tests {
);
fs::write(skill_dir.join(SKILLS_FILENAME), contents).unwrap();
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert_eq!(outcome.skills.len(), 0);
assert_eq!(outcome.errors.len(), 1);
@@ -422,8 +420,8 @@ mod tests {
);
}
#[test]
fn skips_hidden_and_invalid() {
#[tokio::test]
async fn skips_hidden_and_invalid() {
let codex_home = tempfile::tempdir().expect("tempdir");
let hidden_dir = codex_home.path().join("skills/.hidden");
fs::create_dir_all(&hidden_dir).unwrap();
@@ -438,7 +436,7 @@ mod tests {
fs::create_dir_all(&invalid_dir).unwrap();
fs::write(invalid_dir.join(SKILLS_FILENAME), "---\nname: bad").unwrap();
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert_eq!(outcome.skills.len(), 0);
assert_eq!(outcome.errors.len(), 1);
@@ -450,12 +448,12 @@ mod tests {
);
}
#[test]
fn enforces_length_limits() {
#[tokio::test]
async fn enforces_length_limits() {
let codex_home = tempfile::tempdir().expect("tempdir");
let max_desc = "\u{1F4A1}".repeat(MAX_DESCRIPTION_LEN);
write_skill(&codex_home, "max-len", "max-len", &max_desc);
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert!(
@@ -476,8 +474,8 @@ mod tests {
);
}
#[test]
fn loads_skills_from_repo_root() {
#[tokio::test]
async fn loads_skills_from_repo_root() {
let codex_home = tempfile::tempdir().expect("tempdir");
let repo_dir = tempfile::tempdir().expect("tempdir");
@@ -493,7 +491,7 @@ mod tests {
.join(REPO_ROOT_CONFIG_DIR_NAME)
.join(SKILLS_DIR_NAME);
write_skill_at(&skills_root, "repo", "repo-skill", "from repo");
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = repo_dir.path().to_path_buf();
let repo_root = normalize_path(&skills_root).unwrap_or_else(|_| skills_root.clone());
@@ -509,8 +507,8 @@ mod tests {
assert!(skill.path.starts_with(&repo_root));
}
#[test]
fn loads_skills_from_nearest_codex_dir_under_repo_root() {
#[tokio::test]
async fn loads_skills_from_nearest_codex_dir_under_repo_root() {
let codex_home = tempfile::tempdir().expect("tempdir");
let repo_dir = tempfile::tempdir().expect("tempdir");
@@ -544,7 +542,7 @@ mod tests {
"from nested",
);
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = nested_dir;
let outcome = load_skills(&cfg);
@@ -557,8 +555,8 @@ mod tests {
assert_eq!(outcome.skills[0].name, "nested-skill");
}
#[test]
fn loads_skills_from_codex_dir_when_not_git_repo() {
#[tokio::test]
async fn loads_skills_from_codex_dir_when_not_git_repo() {
let codex_home = tempfile::tempdir().expect("tempdir");
let work_dir = tempfile::tempdir().expect("tempdir");
@@ -572,7 +570,7 @@ mod tests {
"from cwd",
);
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = work_dir.path().to_path_buf();
let outcome = load_skills(&cfg);
@@ -586,8 +584,8 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::Repo);
}
#[test]
fn deduplicates_by_name_preferring_repo_over_user() {
#[tokio::test]
async fn deduplicates_by_name_preferring_repo_over_user() {
let codex_home = tempfile::tempdir().expect("tempdir");
let repo_dir = tempfile::tempdir().expect("tempdir");
@@ -609,7 +607,7 @@ mod tests {
"from repo",
);
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = repo_dir.path().to_path_buf();
let outcome = load_skills(&cfg);
@@ -623,14 +621,14 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::Repo);
}
#[test]
fn loads_system_skills_with_lowest_priority() {
#[tokio::test]
async fn loads_system_skills_with_lowest_priority() {
let codex_home = tempfile::tempdir().expect("tempdir");
write_system_skill(&codex_home, "system", "dupe-skill", "from system");
write_skill(&codex_home, "user", "dupe-skill", "from user");
let cfg = make_config(&codex_home);
let cfg = make_config(&codex_home).await;
let outcome = load_skills(&cfg);
assert!(
outcome.errors.is_empty(),
@@ -642,8 +640,8 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::User);
}
#[test]
fn repo_skills_search_does_not_escape_repo_root() {
#[tokio::test]
async fn repo_skills_search_does_not_escape_repo_root() {
let codex_home = tempfile::tempdir().expect("tempdir");
let outer_dir = tempfile::tempdir().expect("tempdir");
let repo_dir = outer_dir.path().join("repo");
@@ -666,7 +664,7 @@ mod tests {
.expect("git init");
assert!(status.success(), "git init failed");
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = repo_dir;
let outcome = load_skills(&cfg);
@@ -678,8 +676,8 @@ mod tests {
assert_eq!(outcome.skills.len(), 0);
}
#[test]
fn loads_skills_when_cwd_is_file_in_repo() {
#[tokio::test]
async fn loads_skills_when_cwd_is_file_in_repo() {
let codex_home = tempfile::tempdir().expect("tempdir");
let repo_dir = tempfile::tempdir().expect("tempdir");
@@ -702,7 +700,7 @@ mod tests {
let file_path = repo_dir.path().join("some-file.txt");
fs::write(&file_path, "contents").unwrap();
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = file_path;
let outcome = load_skills(&cfg);
@@ -716,8 +714,8 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::Repo);
}
#[test]
fn non_git_repo_skills_search_does_not_walk_parents() {
#[tokio::test]
async fn non_git_repo_skills_search_does_not_walk_parents() {
let codex_home = tempfile::tempdir().expect("tempdir");
let outer_dir = tempfile::tempdir().expect("tempdir");
let nested_dir = outer_dir.path().join("nested/inner");
@@ -733,7 +731,7 @@ mod tests {
"from outer",
);
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = nested_dir;
let outcome = load_skills(&cfg);
@@ -745,14 +743,14 @@ mod tests {
assert_eq!(outcome.skills.len(), 0);
}
#[test]
fn loads_skills_from_system_cache_when_present() {
#[tokio::test]
async fn loads_skills_from_system_cache_when_present() {
let codex_home = tempfile::tempdir().expect("tempdir");
let work_dir = tempfile::tempdir().expect("tempdir");
write_system_skill(&codex_home, "system", "system-skill", "from system");
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = work_dir.path().to_path_buf();
let outcome = load_skills(&cfg);
@@ -766,15 +764,15 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::System);
}
#[test]
fn deduplicates_by_name_preferring_user_over_system() {
#[tokio::test]
async fn deduplicates_by_name_preferring_user_over_system() {
let codex_home = tempfile::tempdir().expect("tempdir");
let work_dir = tempfile::tempdir().expect("tempdir");
write_skill(&codex_home, "user", "dupe-skill", "from user");
write_system_skill(&codex_home, "system", "dupe-skill", "from system");
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = work_dir.path().to_path_buf();
let outcome = load_skills(&cfg);
@@ -788,8 +786,8 @@ mod tests {
assert_eq!(outcome.skills[0].scope, SkillScope::User);
}
#[test]
fn deduplicates_by_name_preferring_repo_over_system() {
#[tokio::test]
async fn deduplicates_by_name_preferring_repo_over_system() {
let codex_home = tempfile::tempdir().expect("tempdir");
let repo_dir = tempfile::tempdir().expect("tempdir");
@@ -811,7 +809,7 @@ mod tests {
);
write_system_skill(&codex_home, "system", "dupe-skill", "from system");
let mut cfg = make_config(&codex_home);
let mut cfg = make_config(&codex_home).await;
cfg.cwd = repo_dir.path().to_path_buf();
let outcome = load_skills(&cfg);