Files
codex/codex-rs/cli/src/daemon_update_tests.rs
T
jif 595534314f Use descriptor-safe helpers for executable test fixtures (#50018)
## Why

Concurrent Linux test spawns can inherit writable descriptors for executable fixtures, preventing those fixtures from being executed even after the writing test closes its descriptor.

## What changed

Replace direct executable fixture writes and copies across the Rust tests with `codex_utils_cargo_bin::write_executable` and `copy_executable`. These existing helpers complete writes and copies in separate processes on Linux.

Remove the empty temporary inode before creating fake bubblewrap executables, and stage tampered bubblewrap bytes in a separate data file before copying them into the executable fixture. Add the required test dependencies.

GitOrigin-RevId: c875c83088731a4933ef1574e8d79d8cecc12f54
2026-10-01 15:57:03 +00:00

38 lines
1.3 KiB
Rust

use super::*;
use codex_tui::DaemonUpdateSource;
use pretty_assertions::assert_eq;
use std::os::unix::fs::PermissionsExt;
#[test]
fn daemon_handoff_uses_selected_executable_and_propagates_failure() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
let executable = dir.path().join("launching CLI");
let receipt = dir.path().join("launching CLI.args");
codex_utils_cargo_bin::write_executable(
&executable,
"#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$0.args\"\n",
)?;
std::fs::set_permissions(&executable, std::fs::Permissions::from_mode(/*mode*/ 0o700))?;
for (source, expected) in [
(
DaemonUpdateSource::PublicStable,
"app-server\ndaemon\nupdate\n",
),
(
DaemonUpdateSource::ThisCli,
"app-server\ndaemon\nupdate\n--from-cli\n--yes\n",
),
] {
run_update_action(UpdateAction::Daemon(source), Some(&executable))?;
assert_eq!(std::fs::read_to_string(&receipt)?, expected);
}
codex_utils_cargo_bin::write_executable(&executable, "#!/bin/sh\nexit 7\n")?;
let error = run_update_action(
UpdateAction::Daemon(DaemonUpdateSource::ThisCli),
Some(&executable),
)
.unwrap_err();
assert!(error.to_string().contains("Daemon update failed"));
Ok(())
}