Base: codex-main originale (prima del fork aKode)

This commit is contained in:
Andrea
2026-11-09 10:37:42 +01:00
commit 7874033c81
10166 changed files with 2728937 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#![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()?;
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(())
}