mirror of
https://github.com/openai/codex.git
synced 2026-05-21 19:45:26 +00:00
Isolate tmp-dependent tests from ambient git
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -1726,16 +1726,49 @@ async fn non_git_repo_skills_search_does_not_walk_parents() {
|
||||
fs::create_dir_all(&nested_dir).unwrap();
|
||||
|
||||
write_skill_at(
|
||||
&outer_dir
|
||||
.path()
|
||||
.join(REPO_ROOT_CONFIG_DIR_NAME)
|
||||
.join(SKILLS_DIR_NAME),
|
||||
&outer_dir.path().join(AGENTS_DIR_NAME).join(SKILLS_DIR_NAME),
|
||||
"outer",
|
||||
"outer-skill",
|
||||
"from outer",
|
||||
);
|
||||
|
||||
let cfg = make_config_for_cwd(&codex_home, nested_dir).await;
|
||||
let mut system_config = toml::map::Map::new();
|
||||
system_config.insert(
|
||||
"project_root_markers".to_string(),
|
||||
TomlValue::Array(vec![TomlValue::String(
|
||||
"__codex_test_project_root_marker_that_does_not_exist__".to_string(),
|
||||
)]),
|
||||
);
|
||||
let user_config_path = codex_home.path().join(CONFIG_TOML_FILE);
|
||||
let system_config_path = codex_home.path().join("etc/codex/config.toml");
|
||||
fs::create_dir_all(
|
||||
system_config_path
|
||||
.parent()
|
||||
.expect("system config path should have a parent"),
|
||||
)
|
||||
.expect("create fake system config dir");
|
||||
let cfg = TestConfig {
|
||||
cwd: nested_dir.abs(),
|
||||
config_layer_stack: ConfigLayerStack::new(
|
||||
vec![
|
||||
ConfigLayerEntry::new(
|
||||
ConfigLayerSource::System {
|
||||
file: config_file(system_config_path),
|
||||
},
|
||||
TomlValue::Table(system_config),
|
||||
),
|
||||
ConfigLayerEntry::new(
|
||||
ConfigLayerSource::User {
|
||||
file: config_file(user_config_path),
|
||||
},
|
||||
TomlValue::Table(toml::map::Map::new()),
|
||||
),
|
||||
],
|
||||
ConfigRequirements::default(),
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("valid config layer stack"),
|
||||
};
|
||||
|
||||
let outcome = load_skills_for_test(&cfg).await;
|
||||
assert!(
|
||||
|
||||
@@ -188,12 +188,21 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn environment_id_fallback_has_cwd_prefix() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let env_id = environment_id_from_cwd(dir.path());
|
||||
let canonical = dir
|
||||
.path()
|
||||
let unique = tempfile::Builder::new()
|
||||
.prefix("codex-secrets-test-")
|
||||
.tempdir()
|
||||
.expect("tempdir");
|
||||
let cwd = PathBuf::from(std::path::MAIN_SEPARATOR.to_string()).join(
|
||||
unique
|
||||
.path()
|
||||
.file_name()
|
||||
.expect("tempdir should have a file name"),
|
||||
);
|
||||
drop(unique);
|
||||
let env_id = environment_id_from_cwd(&cwd);
|
||||
let canonical = cwd
|
||||
.canonicalize()
|
||||
.expect("tempdir canonical path should exist")
|
||||
.unwrap_or_else(|_| cwd.clone())
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use super::*;
|
||||
use codex_app_server_protocol::PluginAvailability;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
pub(super) async fn test_config() -> Config {
|
||||
// Start from the built-in defaults so tests do not inherit host/system config.
|
||||
@@ -16,7 +18,7 @@ pub(super) async fn test_config() -> Config {
|
||||
config.codex_home = codex_home.abs();
|
||||
config.sqlite_home = codex_home.clone();
|
||||
config.log_dir = codex_home.join("log");
|
||||
config.cwd = PathBuf::from(test_path_display("/tmp/project")).abs();
|
||||
config.cwd = test_project_path().abs();
|
||||
config.config_layer_stack = ConfigLayerStack::default();
|
||||
config.startup_warnings.clear();
|
||||
config.user_instructions = None;
|
||||
@@ -24,7 +26,22 @@ pub(super) async fn test_config() -> Config {
|
||||
}
|
||||
|
||||
pub(super) fn test_project_path() -> PathBuf {
|
||||
PathBuf::from(test_path_display("/tmp/project"))
|
||||
let project = tempfile::Builder::new()
|
||||
.rand_bytes("project".len())
|
||||
.tempdir_in(std::env::temp_dir())
|
||||
.expect("tempdir")
|
||||
.keep();
|
||||
std::fs::create_dir_all(project.join(".git")).expect("create test project git marker");
|
||||
isolated_test_project_paths()
|
||||
.lock()
|
||||
.expect("test project path registry")
|
||||
.push(project.clone());
|
||||
project
|
||||
}
|
||||
|
||||
fn isolated_test_project_paths() -> &'static Mutex<Vec<PathBuf>> {
|
||||
static TEST_PROJECT_PATHS: OnceLock<Mutex<Vec<PathBuf>>> = OnceLock::new();
|
||||
TEST_PROJECT_PATHS.get_or_init(|| Mutex::new(Vec::new()))
|
||||
}
|
||||
|
||||
pub(super) fn truncated_path_variants(path: &str) -> Vec<String> {
|
||||
@@ -37,6 +54,14 @@ pub(super) fn truncated_path_variants(path: &str) -> Vec<String> {
|
||||
pub(super) fn normalize_snapshot_paths(text: impl Into<String>) -> String {
|
||||
let mut text = text.into();
|
||||
|
||||
for isolated_project in isolated_test_project_paths()
|
||||
.lock()
|
||||
.expect("test project path registry")
|
||||
.iter()
|
||||
{
|
||||
text = text.replace(isolated_project.to_string_lossy().as_ref(), "/tmp/project");
|
||||
}
|
||||
|
||||
for unix_path in ["/tmp/project", "/tmp/hooks.json"] {
|
||||
let platform_path = test_path_display(unix_path);
|
||||
if platform_path != unix_path {
|
||||
@@ -68,7 +93,7 @@ pub(super) fn normalized_backend_snapshot<T: std::fmt::Display>(value: &T) -> St
|
||||
let rendered = format!("{value}");
|
||||
|
||||
if platform_test_cwd == "/tmp/project" {
|
||||
return rendered;
|
||||
return normalize_snapshot_paths(rendered);
|
||||
}
|
||||
|
||||
rendered
|
||||
|
||||
@@ -1973,10 +1973,10 @@ async fn status_line_model_with_reasoning_includes_fast_for_fast_capable_models(
|
||||
set_fast_mode_test_catalog(&mut chat);
|
||||
assert!(get_available_model(&chat, "gpt-5.4").supports_fast_mode());
|
||||
chat.refresh_status_line();
|
||||
let test_cwd = test_path_display("/tmp/project");
|
||||
let test_cwd = normalize_snapshot_paths(test_path_display("/tmp/project"));
|
||||
|
||||
assert_eq!(
|
||||
status_line_text(&chat),
|
||||
status_line_text(&chat).map(normalize_snapshot_paths),
|
||||
Some(format!("gpt-5.4 xhigh fast · Context 0% used · {test_cwd}"))
|
||||
);
|
||||
|
||||
@@ -1984,7 +1984,7 @@ async fn status_line_model_with_reasoning_includes_fast_for_fast_capable_models(
|
||||
chat.refresh_status_line();
|
||||
|
||||
assert_eq!(
|
||||
status_line_text(&chat),
|
||||
status_line_text(&chat).map(normalize_snapshot_paths),
|
||||
Some(format!(
|
||||
"gpt-5.3-codex xhigh · Context 0% used · {test_cwd}"
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user