Skip to content

Commit bee97a7

Browse files
fix(test): CLI init test patching not triggered (#1846)
The patching doesn't work because cargo still tries to fetch from git first before doing the patch, so instead we use a find replace approach. I have tested this with v1.4.0-rc.0 to ensure it works.
1 parent 3ad8ebb commit bee97a7

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

crates/cli/tests/app_e2e.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
use std::{env, fs::OpenOptions, io::Write, path::Path, process::Command};
1+
use std::{
2+
env,
3+
fs::{self, read_to_string},
4+
path::Path,
5+
process::Command,
6+
};
27

38
use eyre::Result;
9+
use itertools::Itertools;
410
use tempfile::tempdir;
511

612
#[test]
@@ -124,6 +130,7 @@ fn test_cli_init_build() -> Result<()> {
124130
let manifest_path = temp_path.join("Cargo.toml");
125131
run_cmd("cargo", &["install", "--path", ".", "--force"])?;
126132

133+
// Cargo will not respect patches if run within a workspace
127134
run_cmd(
128135
"cargo",
129136
&[
@@ -135,7 +142,7 @@ fn test_cli_init_build() -> Result<()> {
135142
],
136143
)?;
137144
if matches!(env::var("USE_LOCAL_OPENVM"), Ok(x) if x == "1") {
138-
append_patch_to_cargo_toml(&manifest_path)?;
145+
replace_with_local_openvm(&manifest_path)?;
139146
}
140147

141148
run_cmd(
@@ -175,25 +182,30 @@ fn run_cmd(program: &str, args: &[&str]) -> Result<()> {
175182
Ok(())
176183
}
177184

178-
fn append_patch_to_cargo_toml(file_path: impl AsRef<Path>) -> Result<()> {
185+
fn replace_with_local_openvm(file_path: impl AsRef<Path>) -> Result<()> {
179186
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
180187
let openvm_path = Path::new(MANIFEST_DIR)
181188
.parent()
182189
.unwrap()
183190
.join("toolchain")
184191
.join("openvm");
185-
let mut file = OpenOptions::new()
186-
.create(false)
187-
.append(true)
188-
.open(file_path)?;
189-
190-
// Add a newline first to ensure proper formatting
191-
writeln!(file)?;
192-
writeln!(
193-
file,
194-
r#"[patch."https://github.com/openvm-org/openvm.git"]"#
195-
)?;
196-
writeln!(file, r#"openvm = {{ path = "{}" }}"#, openvm_path.display())?;
192+
let content = read_to_string(&file_path)?;
193+
let lines = content.lines().collect::<Vec<_>>();
194+
let new_content = lines
195+
.iter()
196+
.map(|line| {
197+
if line.starts_with("openvm = { git = \"https://github.com/openvm-org/openvm.git\"") {
198+
format!(
199+
r#"openvm = {{ path = "{}", features = ["std"] }}"#,
200+
openvm_path.display()
201+
)
202+
} else {
203+
line.to_string()
204+
}
205+
})
206+
.join("\n");
207+
208+
fs::write(file_path, new_content)?;
197209

198210
Ok(())
199211
}

0 commit comments

Comments
 (0)