Run package updates outside the project on non-Windows platforms (#58403)

## Why

Package managers search parent directories for project configuration and hooks, which can influence Codex updates launched from a project directory.

## What changed

Run non-Windows update commands with `/` as their working directory.

## Testing

Add a regression test using a fake `pnpm` executable to verify that updates run outside the project even when `TMPDIR` points into it.

GitOrigin-RevId: a39b36872a62f2404aadd0614e1486d0755636fc
This commit is contained in:
viyatb-oai
2026-10-30 18:12:10 +00:00
committed by copyberry
parent a94ba8bdd0
commit e7b8d3a36d
2 changed files with 34 additions and 0 deletions
+32
View File
@@ -1,8 +1,40 @@
#![cfg(test)]
use super::*;
use codex_tui::DaemonUpdateSource;
use pretty_assertions::assert_eq;
use std::os::unix::fs::PermissionsExt;
#[test]
fn package_update_runs_outside_the_project() -> anyhow::Result<()> {
const CHILD: &str = "CODEX_TEST_PACKAGE_UPDATE_CHILD";
if std::env::var_os(CHILD).is_some() {
return run_update_action(UpdateAction::PnpmGlobalLatest, /*cli_executable*/ None);
}
let project = tempfile::tempdir()?;
let bin = tempfile::tempdir()?;
codex_utils_cargo_bin::write_executable(
&bin.path().join("pnpm"),
"#!/bin/sh\npwd -P > \"$0.cwd\"\n",
)?;
assert_cmd::Command::new(std::env::current_exe()?)
.args([
"--exact",
"daemon_update_tests::package_update_runs_outside_the_project",
])
.current_dir(project.path())
.env("TMPDIR", project.path())
.env("PATH", bin.path())
.env(CHILD, "1")
.assert()
.success();
let cwd = std::fs::read_to_string(bin.path().join("pnpm.cwd"))?;
assert!(!std::path::Path::new(cwd.trim_end()).starts_with(project.path().canonicalize()?));
Ok(())
}
#[test]
fn daemon_handoff_uses_selected_executable_and_propagates_failure() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
+2
View File
@@ -848,6 +848,8 @@ fn run_update_action(
.collect();
std::process::Command::new(&command_path)
.args(&normalized_args)
// Package managers search parent directories for project config and hooks.
.current_dir("/")
.status()?
}
};