From cd5f6bdd568118ad464c8ba06d273912ce8c4c2b Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Mon, 11 Aug 2025 10:23:38 -0700 Subject: [PATCH 1/2] [apply-patch] Support applypatch command string --- codex-rs/apply-patch/src/lib.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rs index 61b1b68f9e14..b8c8977b4f2b 100644 --- a/codex-rs/apply-patch/src/lib.rs +++ b/codex-rs/apply-patch/src/lib.rs @@ -81,9 +81,10 @@ pub struct ApplyPatchArgs { pub hunks: Vec, } +const APPLY_PATCH_COMMANDS: [&str; 2] = ["apply_patch", "applypatch"]; pub fn maybe_parse_apply_patch(argv: &[String]) -> MaybeApplyPatch { match argv { - [cmd, body] if cmd == "apply_patch" => match parse_patch(body) { + [cmd, body] if APPLY_PATCH_COMMANDS.contains(&cmd.as_str()) => match parse_patch(body) { Ok(source) => MaybeApplyPatch::Body(source), Err(e) => MaybeApplyPatch::PatchParseError(e), }, @@ -722,6 +723,31 @@ mod tests { } } + #[test] + fn test_literal_applypatch() { + let args = strs_to_strings(&[ + "applypatch", + r#"*** Begin Patch +*** Add File: foo ++hi +*** End Patch +"#, + ]); + + match maybe_parse_apply_patch(&args) { + MaybeApplyPatch::Body(ApplyPatchArgs { hunks, patch: _ }) => { + assert_eq!( + hunks, + vec![Hunk::AddFile { + path: PathBuf::from("foo"), + contents: "hi\n".to_string() + }] + ); + } + result => panic!("expected MaybeApplyPatch::Body got {result:?}"), + } + } + #[test] fn test_heredoc() { let args = strs_to_strings(&[ From cacd333596b445eb28d9ad838828b4d154bb54be Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Mon, 11 Aug 2025 12:16:30 -0700 Subject: [PATCH 2/2] mv const inside fn --- codex-rs/apply-patch/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rs index b8c8977b4f2b..262d219d6dbc 100644 --- a/codex-rs/apply-patch/src/lib.rs +++ b/codex-rs/apply-patch/src/lib.rs @@ -81,8 +81,8 @@ pub struct ApplyPatchArgs { pub hunks: Vec, } -const APPLY_PATCH_COMMANDS: [&str; 2] = ["apply_patch", "applypatch"]; pub fn maybe_parse_apply_patch(argv: &[String]) -> MaybeApplyPatch { + const APPLY_PATCH_COMMANDS: [&str; 2] = ["apply_patch", "applypatch"]; match argv { [cmd, body] if APPLY_PATCH_COMMANDS.contains(&cmd.as_str()) => match parse_patch(body) { Ok(source) => MaybeApplyPatch::Body(source),