mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
test(exec): cover output symlink rejection
Co-authored-by: Codex noreply@openai.com
This commit is contained in:
co-authored by
Codex noreply@openai.com
parent
808ea21a5d
commit
1154d09249
@@ -6,6 +6,7 @@ mod auth_env;
|
||||
mod ephemeral;
|
||||
mod mcp_required_exit;
|
||||
mod originator;
|
||||
mod output_last_message;
|
||||
mod output_schema;
|
||||
mod prompt_stdin;
|
||||
mod resume;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#![cfg(unix)]
|
||||
|
||||
use core_test_support::responses;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
use predicates::str::contains;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn output_last_message_does_not_follow_symlink() -> anyhow::Result<()> {
|
||||
let test = test_codex_exec();
|
||||
let target_path = test.cwd_path().join("target.md");
|
||||
let output_path = test.cwd_path().join("output.md");
|
||||
std::fs::write(&target_path, "original")?;
|
||||
std::os::unix::fs::symlink(&target_path, &output_path)?;
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let body = responses::sse(vec![
|
||||
responses::ev_response_created("resp1"),
|
||||
responses::ev_assistant_message("m1", "replacement"),
|
||||
responses::ev_completed("resp1"),
|
||||
]);
|
||||
let _response_mock = responses::mount_sse_once(&server, body).await;
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("--output-last-message")
|
||||
.arg(&output_path)
|
||||
.arg("write a response")
|
||||
.assert()
|
||||
.success()
|
||||
.stderr(contains("Failed to write last message file"));
|
||||
|
||||
assert_eq!(std::fs::read_to_string(&target_path)?, "original");
|
||||
Ok(())
|
||||
}
|
||||
@@ -144,7 +144,10 @@ pub fn write_atomically(write_path: &Path, contents: &str) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Opens a file for writing without following symlinks in any path component.
|
||||
/// Creates or truncates a file for writing without following symlinks in any path component.
|
||||
///
|
||||
/// Relative paths are resolved from the process's current directory. The returned file uses mode
|
||||
/// `0o666`, subject to the process umask.
|
||||
#[cfg(unix)]
|
||||
pub fn open_file_for_write_no_follow(path: &Path) -> io::Result<File> {
|
||||
open_file_no_follow(
|
||||
|
||||
Reference in New Issue
Block a user