Lightweight coding agent that runs in your terminal
Rust
chore(apply-patch) scenarios for e2e testing (#7567)
Dylan Hurd073a8533b83f
diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/.gitattributesnew file mode 100644index 0000000000..a42a20ddc5--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/.gitattributes@@ -0,0 +1 @@+** text eol=lfdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/expected/bar.md b/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/expected/bar.mdnew file mode 100644index 0000000000..6dfa057f0d--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/expected/bar.md@@ -0,0 +1 @@+This is a new filediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/patch.txtnew file mode 100644index 0000000000..37735b2a46--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/001_add_file/patch.txt@@ -0,0 +1,4 @@+*** Begin Patch+*** Add File: bar.md++This is a new file+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/modify.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/modify.txtnew file mode 100644index 0000000000..1b2ee3e566--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/modify.txt@@ -0,0 +1,2 @@+line1+changeddiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/nested/new.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/nested/new.txtnew file mode 100644index 0000000000..3151666398--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/expected/nested/new.txt@@ -0,0 +1 @@+createddiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/delete.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/delete.txtnew file mode 100644index 0000000000..6e263abce1--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/delete.txt@@ -0,0 +1 @@+obsoletediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/modify.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/modify.txtnew file mode 100644index 0000000000..c0d0fb45c3--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/input/modify.txt@@ -0,0 +1,2 @@+line1+line2diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/patch.txtnew file mode 100644index 0000000000..673dec2f78--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/002_multiple_operations/patch.txt@@ -0,0 +1,9 @@+*** Begin Patch+*** Add File: nested/new.txt++created+*** Delete File: delete.txt+*** Update File: modify.txt+@@+-line2++changed+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/expected/multi.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/expected/multi.txtnew file mode 100644index 0000000000..9054a72916--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/expected/multi.txt@@ -0,0 +1,4 @@+line1+changed2+line3+changed4diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/input/multi.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/input/multi.txtnew file mode 100644index 0000000000..84275f9939--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/input/multi.txt@@ -0,0 +1,4 @@+line1+line2+line3+line4diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/patch.txtnew file mode 100644index 0000000000..45733c714b--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/003_multiple_chunks/patch.txt@@ -0,0 +1,9 @@+*** Begin Patch+*** Update File: multi.txt+@@+-line2++changed2+@@+-line4++changed4+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/old/other.txtnew file mode 100644index 0000000000..b61039d3df--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/old/other.txt@@ -0,0 +1 @@+unrelated filediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/renamed/dir/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/renamed/dir/name.txtnew file mode 100644index 0000000000..b66ba06d31--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/expected/renamed/dir/name.txt@@ -0,0 +1 @@+new contentdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/name.txtnew file mode 100644index 0000000000..33194a0a6f--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/name.txt@@ -0,0 +1 @@+old contentdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/other.txtnew file mode 100644index 0000000000..b61039d3df--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/input/old/other.txt@@ -0,0 +1 @@+unrelated filediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/patch.txtnew file mode 100644index 0000000000..5e2d723a2b--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/004_move_to_new_directory/patch.txt@@ -0,0 +1,7 @@+*** Begin Patch+*** Update File: old/name.txt+*** Move to: renamed/dir/name.txt+@@+-old content++new content+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/005_rejects_empty_patch/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/005_rejects_empty_patch/patch.txtnew file mode 100644index 0000000000..4fcfecbbc7--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/005_rejects_empty_patch/patch.txt@@ -0,0 +1,2 @@+*** Begin Patch+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/expected/modify.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/expected/modify.txtnew file mode 100644index 0000000000..c0d0fb45c3--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/expected/modify.txt@@ -0,0 +1,2 @@+line1+line2diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/input/modify.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/input/modify.txtnew file mode 100644index 0000000000..c0d0fb45c3--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/input/modify.txt@@ -0,0 +1,2 @@+line1+line2diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/patch.txtnew file mode 100644index 0000000000..488438b12b--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/006_rejects_missing_context/patch.txt@@ -0,0 +1,6 @@+*** Begin Patch+*** Update File: modify.txt+@@+-missing++changed+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/007_rejects_missing_file_delete/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/007_rejects_missing_file_delete/patch.txtnew file mode 100644index 0000000000..6f95531db3--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/007_rejects_missing_file_delete/patch.txt@@ -0,0 +1,3 @@+*** Begin Patch+*** Delete File: missing.txt+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/008_rejects_empty_update_hunk/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/008_rejects_empty_update_hunk/patch.txtnew file mode 100644index 0000000000..d7596a362b--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/008_rejects_empty_update_hunk/patch.txt@@ -0,0 +1,3 @@+*** Begin Patch+*** Update File: foo.txt+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/009_requires_existing_file_for_update/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/009_requires_existing_file_for_update/patch.txtnew file mode 100644index 0000000000..a7de4f24c5--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/009_requires_existing_file_for_update/patch.txt@@ -0,0 +1,6 @@+*** Begin Patch+*** Update File: missing.txt+@@+-old++new+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/old/other.txtnew file mode 100644index 0000000000..b61039d3df--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/old/other.txt@@ -0,0 +1 @@+unrelated filediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/renamed/dir/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/renamed/dir/name.txtnew file mode 100644index 0000000000..3e757656cf--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/expected/renamed/dir/name.txt@@ -0,0 +1 @@+newdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/name.txtnew file mode 100644index 0000000000..3940df7cd8--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/name.txt@@ -0,0 +1 @@+fromdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/other.txtnew file mode 100644index 0000000000..b61039d3df--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/old/other.txt@@ -0,0 +1 @@+unrelated filediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/renamed/dir/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/renamed/dir/name.txtnew file mode 100644index 0000000000..cbaf024e5e--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/input/renamed/dir/name.txt@@ -0,0 +1 @@+existingdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/patch.txtnew file mode 100644index 0000000000..c45ce6d782--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/010_move_overwrites_existing_destination/patch.txt@@ -0,0 +1,7 @@+*** Begin Patch+*** Update File: old/name.txt+*** Move to: renamed/dir/name.txt+@@+-from++new+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/expected/duplicate.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/expected/duplicate.txtnew file mode 100644index 0000000000..b66ba06d31--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/expected/duplicate.txt@@ -0,0 +1 @@+new contentdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/input/duplicate.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/input/duplicate.txtnew file mode 100644index 0000000000..33194a0a6f--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/input/duplicate.txt@@ -0,0 +1 @@+old contentdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/patch.txtnew file mode 100644index 0000000000..bad9cf3fde--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/011_add_overwrites_existing_file/patch.txt@@ -0,0 +1,4 @@+*** Begin Patch+*** Add File: duplicate.txt++new content+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/012_delete_directory_fails/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/012_delete_directory_fails/patch.txtnew file mode 100644index 0000000000..a10bcd9ea9--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/012_delete_directory_fails/patch.txt@@ -0,0 +1,3 @@+*** Begin Patch+*** Delete File: dir+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/013_rejects_invalid_hunk_header/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/013_rejects_invalid_hunk_header/patch.txtnew file mode 100644index 0000000000..b35d7207d7--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/013_rejects_invalid_hunk_header/patch.txt@@ -0,0 +1,3 @@+*** Begin Patch+*** Frobnicate File: foo+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/expected/no_newline.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/expected/no_newline.txtnew file mode 100644index 0000000000..06fcdd77c9--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/expected/no_newline.txt@@ -0,0 +1,2 @@+first line+second linediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/input/no_newline.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/input/no_newline.txtnew file mode 100644index 0000000000..a6e09874b5--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/input/no_newline.txt@@ -0,0 +1 @@+no newline at enddiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/patch.txtnew file mode 100644index 0000000000..4ed5818eb1--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/014_update_file_appends_trailing_newline/patch.txt@@ -0,0 +1,7 @@+*** Begin Patch+*** Update File: no_newline.txt+@@+-no newline at end++first line++second line+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/expected/created.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/expected/created.txtnew file mode 100644index 0000000000..ce01362503--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/expected/created.txt@@ -0,0 +1 @@+hellodiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/patch.txtnew file mode 100644index 0000000000..a6e9709d1f--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/015_failure_after_partial_success_leaves_changes/patch.txt@@ -0,0 +1,8 @@+*** Begin Patch+*** Add File: created.txt++hello+*** Update File: missing.txt+@@+-old++new+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/expected/input.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/expected/input.txtnew file mode 100644index 0000000000..f6d6f0bef8--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/expected/input.txt@@ -0,0 +1,4 @@+line1+line2+added line 1+added line 2diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/input/input.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/input/input.txtnew file mode 100644index 0000000000..c0d0fb45c3--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/input/input.txt@@ -0,0 +1,2 @@+line1+line2diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/patch.txtnew file mode 100644index 0000000000..56337549f9--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/016_pure_addition_update_chunk/patch.txt@@ -0,0 +1,6 @@+*** Begin Patch+*** Update File: input.txt+@@++added line 1++added line 2+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/expected/foo.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/expected/foo.txtnew file mode 100644index 0000000000..3e757656cf--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/expected/foo.txt@@ -0,0 +1 @@+newdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/input/foo.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/input/foo.txtnew file mode 100644index 0000000000..3367afdbbf--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/input/foo.txt@@ -0,0 +1 @@+olddiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/patch.txtnew file mode 100644index 0000000000..21e6c1958d--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/017_whitespace_padded_hunk_header/patch.txt@@ -0,0 +1,6 @@+*** Begin Patch+ *** Update File: foo.txt+@@+-old++new+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/expected/file.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/expected/file.txtnew file mode 100644index 0000000000..f719efd430--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/expected/file.txt@@ -0,0 +1 @@+twodiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/input/file.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/input/file.txtnew file mode 100644index 0000000000..5626abf0f7--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/input/file.txt@@ -0,0 +1 @@+onediff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/patch.txtnew file mode 100644index 0000000000..2648721797--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/018_whitespace_padded_patch_markers/patch.txt@@ -0,0 +1,6 @@+ *** Begin Patch+*** Update File: file.txt+@@+-one++two+*** End Patchdiff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/README.md b/codex-rs/apply-patch/tests/fixtures/scenarios/README.mdnew file mode 100644index 0000000000..65d1fbe2e4--- /dev/null+++ b/codex-rs/apply-patch/tests/fixtures/scenarios/README.md@@ -0,0 +1,18 @@+# Overview+This directory is a collection of end to end tests for the apply-patch specification, meant to be easily portable to other languages or platforms.+++# Specification+Each test case is one directory, composed of input state (input/), the patch operation (patch.txt), and the expected final state (expected/). This structure is designed to keep tests simple (i.e. test exactly one patch at a time) while still providing enough flexibility to test any given operation across files.++Here's what this would look like for a simple test apply-patch test case to create a new file:++```+001_add/+ input/+ foo.md+ expected/+ foo.md+ bar.md+ patch.txt+```diff --git a/codex-rs/apply-patch/tests/suite/mod.rs b/codex-rs/apply-patch/tests/suite/mod.rsindex 882c5a6ffd..7d54de85ad 100644--- a/codex-rs/apply-patch/tests/suite/mod.rs+++ b/codex-rs/apply-patch/tests/suite/mod.rs@@ -1,3 +1,4 @@mod cli;+mod scenarios;#[cfg(not(target_os = "windows"))]mod tool;diff --git a/codex-rs/apply-patch/tests/suite/scenarios.rs b/codex-rs/apply-patch/tests/suite/scenarios.rsnew file mode 100644index 0000000000..4b3eb3c84a--- /dev/null+++ b/codex-rs/apply-patch/tests/suite/scenarios.rs@@ -0,0 +1,114 @@+use assert_cmd::prelude::*;+use pretty_assertions::assert_eq;+use std::collections::BTreeMap;+use std::fs;+use std::path::Path;+use std::path::PathBuf;+use std::process::Command;+use tempfile::tempdir;++#[test]+fn test_apply_patch_scenarios() -> anyhow::Result<()> {+ for scenario in fs::read_dir("tests/fixtures/scenarios")? {+ let scenario = scenario?;+ let path = scenario.path();+ if path.is_dir() {+ run_apply_patch_scenario(&path)?;+ }+ }+ Ok(())+}++/// Reads a scenario directory, copies the input files to a temporary directory, runs apply-patch,+/// and asserts that the final state matches the expected state exactly.+fn run_apply_patch_scenario(dir: &Path) -> anyhow::Result<()> {+ let tmp = tempdir()?;++ // Copy the input files to the temporary directory+ let input_dir = dir.join("input");+ if input_dir.is_dir() {+ copy_dir_recursive(&input_dir, tmp.path())?;+ }++ // Read the patch.txt file+ let patch = fs::read_to_string(dir.join("patch.txt"))?;++ // Run apply_patch in the temporary directory. We intentionally do not assert+ // on the exit status here; the scenarios are specified purely in terms of+ // final filesystem state, which we compare below.+ Command::cargo_bin("apply_patch")?+ .arg(patch)+ .current_dir(tmp.path())+ .output()?;++ // Assert that the final state matches the expected state exactly+ let expected_dir = dir.join("expected");+ let expected_snapshot = snapshot_dir(&expected_dir)?;+ let actual_snapshot = snapshot_dir(tmp.path())?;++ assert_eq!(+ actual_snapshot,+ expected_snapshot,+ "Scenario {} did not match expected final state",+ dir.display()+ );++ Ok(())+}++#[derive(Debug, Clone, PartialEq, Eq)]+enum Entry {+ File(Vec<u8>),+ Dir,+}++fn snapshot_dir(root: &Path) -> anyhow::Result<BTreeMap<PathBuf, Entry>> {+ let mut entries = BTreeMap::new();+ if root.is_dir() {+ snapshot_dir_recursive(root, root, &mut entries)?;+ }+ Ok(entries)+}++fn snapshot_dir_recursive(+ base: &Path,+ dir: &Path,+ entries: &mut BTreeMap<PathBuf, Entry>,+) -> anyhow::Result<()> {+ for entry in fs::read_dir(dir)? {+ let entry = entry?;+ let path = entry.path();+ let Some(stripped) = path.strip_prefix(base).ok() else {+ continue;+ };+ let rel = stripped.to_path_buf();+ let file_type = entry.file_type()?;+ if file_type.is_dir() {+ entries.insert(rel.clone(), Entry::Dir);+ snapshot_dir_recursive(base, &path, entries)?;+ } else if file_type.is_file() {+ let contents = fs::read(&path)?;+ entries.insert(rel, Entry::File(contents));+ }+ }+ Ok(())+}++fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> {+ for entry in fs::read_dir(src)? {+ let entry = entry?;+ let path = entry.path();+ let file_type = entry.file_type()?;+ let dest_path = dst.join(entry.file_name());+ if file_type.is_dir() {+ fs::create_dir_all(&dest_path)?;+ copy_dir_recursive(&path, &dest_path)?;+ } else if file_type.is_file() {+ if let Some(parent) = dest_path.parent() {+ fs::create_dir_all(parent)?;+ }+ fs::copy(&path, &dest_path)?;+ }+ }+ Ok(())+}