From f5e1d523c4a1c1d8e1447fe212c0d76eb35508c1 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Sat, 23 Aug 2025 13:22:42 -0700 Subject: [PATCH] add test, fix ci --- codex-cli/scripts/install_native_deps.sh | 25 +++++++----- codex-rs/Cargo.lock | 1 + codex-rs/apply-patch/Cargo.toml | 1 + codex-rs/apply-patch/tests/cli.rs | 48 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 codex-rs/apply-patch/tests/cli.rs diff --git a/codex-cli/scripts/install_native_deps.sh b/codex-cli/scripts/install_native_deps.sh index 5463b6606b..87da5679fd 100755 --- a/codex-cli/scripts/install_native_deps.sh +++ b/codex-cli/scripts/install_native_deps.sh @@ -75,27 +75,32 @@ gh run download --dir "$ARTIFACTS_DIR" --repo openai/codex "$WORKFLOW_ID" # x64 Linux zstd -d "$ARTIFACTS_DIR/x86_64-unknown-linux-musl/codex-x86_64-unknown-linux-musl.zst" \ -o "$BIN_DIR/codex-x86_64-unknown-linux-musl" -zstd -d "$ARTIFACTS_DIR/x86_64-unknown-linux-musl/apply-patch-x86_64-unknown-linux-musl.zst" \ - -o "$BIN_DIR/apply-patch-x86_64-unknown-linux-musl" +if [ -f "$ARTIFACTS_DIR/x86_64-unknown-linux-musl/apply-patch-x86_64-unknown-linux-musl.zst" ]; then + zstd -d "$ARTIFACTS_DIR/x86_64-unknown-linux-musl/apply-patch-x86_64-unknown-linux-musl.zst" -o "$BIN_DIR/apply-patch-x86_64-unknown-linux-musl" +fi # ARM64 Linux zstd -d "$ARTIFACTS_DIR/aarch64-unknown-linux-musl/codex-aarch64-unknown-linux-musl.zst" \ -o "$BIN_DIR/codex-aarch64-unknown-linux-musl" -zstd -d "$ARTIFACTS_DIR/aarch64-unknown-linux-musl/apply-patch-aarch64-unknown-linux-musl.zst" \ - -o "$BIN_DIR/apply-patch-aarch64-unknown-linux-musl" +if [ -f "$ARTIFACTS_DIR/aarch64-unknown-linux-musl/apply-patch-aarch64-unknown-linux-musl.zst" ]; then + zstd -d "$ARTIFACTS_DIR/aarch64-unknown-linux-musl/apply-patch-aarch64-unknown-linux-musl.zst" -o "$BIN_DIR/apply-patch-aarch64-unknown-linux-musl" +fi # x64 macOS zstd -d "$ARTIFACTS_DIR/x86_64-apple-darwin/codex-x86_64-apple-darwin.zst" \ -o "$BIN_DIR/codex-x86_64-apple-darwin" -zstd -d "$ARTIFACTS_DIR/x86_64-apple-darwin/apply-patch-x86_64-apple-darwin.zst" \ - -o "$BIN_DIR/apply-patch-x86_64-apple-darwin" +if [ -f "$ARTIFACTS_DIR/x86_64-apple-darwin/apply-patch-x86_64-apple-darwin.zst" ]; then + zstd -d "$ARTIFACTS_DIR/x86_64-apple-darwin/apply-patch-x86_64-apple-darwin.zst" -o "$BIN_DIR/apply-patch-x86_64-apple-darwin" +fi # ARM64 macOS zstd -d "$ARTIFACTS_DIR/aarch64-apple-darwin/codex-aarch64-apple-darwin.zst" \ -o "$BIN_DIR/codex-aarch64-apple-darwin" -zstd -d "$ARTIFACTS_DIR/aarch64-apple-darwin/apply-patch-aarch64-apple-darwin.zst" \ - -o "$BIN_DIR/apply-patch-aarch64-apple-darwin" +if [ -f "$ARTIFACTS_DIR/aarch64-apple-darwin/apply-patch-aarch64-apple-darwin.zst" ]; then + zstd -d "$ARTIFACTS_DIR/aarch64-apple-darwin/apply-patch-aarch64-apple-darwin.zst" -o "$BIN_DIR/apply-patch-aarch64-apple-darwin" +fi # x64 Windows zstd -d "$ARTIFACTS_DIR/x86_64-pc-windows-msvc/codex-x86_64-pc-windows-msvc.exe.zst" \ -o "$BIN_DIR/codex-x86_64-pc-windows-msvc.exe" -zstd -d "$ARTIFACTS_DIR/x86_64-pc-windows-msvc/apply-patch-x86_64-pc-windows-msvc.exe.zst" \ - -o "$BIN_DIR/apply-patch-x86_64-pc-windows-msvc.exe" +if [ -f "$ARTIFACTS_DIR/x86_64-pc-windows-msvc/apply-patch-x86_64-pc-windows-msvc.exe.zst" ]; then + zstd -d "$ARTIFACTS_DIR/x86_64-pc-windows-msvc/apply-patch-x86_64-pc-windows-msvc.exe.zst" -o "$BIN_DIR/apply-patch-x86_64-pc-windows-msvc.exe" +fi echo "Installed native dependencies into $BIN_DIR" diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index dbccbd863e..a8e2d5c416 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -635,6 +635,7 @@ name = "codex-apply-patch" version = "0.0.0" dependencies = [ "anyhow", + "assert_cmd", "pretty_assertions", "similar", "tempfile", diff --git a/codex-rs/apply-patch/Cargo.toml b/codex-rs/apply-patch/Cargo.toml index 49f250a02d..33fa037c86 100644 --- a/codex-rs/apply-patch/Cargo.toml +++ b/codex-rs/apply-patch/Cargo.toml @@ -24,3 +24,4 @@ tree-sitter-bash = "0.25.0" [dev-dependencies] pretty_assertions = "1.4.1" tempfile = "3.13.0" +assert_cmd = "2" diff --git a/codex-rs/apply-patch/tests/cli.rs b/codex-rs/apply-patch/tests/cli.rs new file mode 100644 index 0000000000..648845c99b --- /dev/null +++ b/codex-rs/apply-patch/tests/cli.rs @@ -0,0 +1,48 @@ +#![allow(clippy::expect_used, clippy::unwrap_used)] +use assert_cmd::prelude::*; +use std::fs; +use std::process::Command; +use tempfile::tempdir; + +#[test] +fn test_apply_patch_cli_add_and_update() -> anyhow::Result<()> { + let tmp = tempdir()?; + let file = "cli_test.txt"; + let absolute_path = tmp.path().join(file); + + // 1) Add a file + let add_patch = format!( + r#"*** Begin Patch +*** Add File: {file} ++hello +*** End Patch"# + ); + Command::cargo_bin("apply-patch") + .expect("should find apply-patch binary") + .arg(add_patch) + .current_dir(tmp.path()) + .assert() + .success() + .stdout(format!("Success. Updated the following files:\nA {file}\n")); + assert_eq!(fs::read_to_string(&absolute_path)?, "hello\n"); + + // 2) Update the file + let update_patch = format!( + r#"*** Begin Patch +*** Update File: {file} +@@ +-hello ++world +*** End Patch"# + ); + Command::cargo_bin("apply-patch") + .expect("should find apply-patch binary") + .arg(update_patch) + .current_dir(tmp.path()) + .assert() + .success() + .stdout(format!("Success. Updated the following files:\nM {file}\n")); + assert_eq!(fs::read_to_string(&absolute_path)?, "world\n"); + + Ok(()) +}