From 38a1d87d435db20ec4c8453d4aaea5a1108a80dd Mon Sep 17 00:00:00 2001 From: Marcin Jahn <10273406+marcinjahn@users.noreply.github.com> Date: Mon, 2 Mar 2026 19:16:49 +0100 Subject: [PATCH 1/2] Fix windows tests --- tests/e2e/helpers.bash | 9 +++++++++ tests/e2e/migration.bats | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/e2e/helpers.bash b/tests/e2e/helpers.bash index c058db5..4e6ea22 100644 --- a/tests/e2e/helpers.bash +++ b/tests/e2e/helpers.bash @@ -1,6 +1,15 @@ REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)" export PATH="$REPO_ROOT/target/release:$PATH" +# Converts an MSYS/Cygwin path to Windows-native format (no-op on Unix) +native_path() { + if command -v cygpath &>/dev/null; then + cygpath -m "$1" + else + printf '%s' "$1" + fi +} + setup_puff_env() { export PUFF_CONFIG_PATH PUFF_CONFIG_PATH="$(mktemp -d)" diff --git a/tests/e2e/migration.bats b/tests/e2e/migration.bats index f4cdf04..ab41546 100644 --- a/tests/e2e/migration.bats +++ b/tests/e2e/migration.bats @@ -45,15 +45,22 @@ teardown() { teardown_puff_env; } } @test "migration: symlinks updated after migration" { - # Set up old-style layout with an associated project + symlink + # Set up old-style layout with an associated project + symlink. + # Use native_path so that config.json and symlink targets contain + # Windows-native paths when running under MSYS/Git Bash — the Rust + # binary cannot resolve MSYS-style paths like /tmp/tmp.XXX. mkdir -p "$PUFF_CONFIG_PATH/configs/myproject" echo "SECRET=1" >"$PUFF_CONFIG_PATH/configs/myproject/.env" cat >"$PUFF_CONFIG_PATH/config.json" < Date: Mon, 2 Mar 2026 19:52:41 +0100 Subject: [PATCH 2/2] fix unit tests --- src/commands/add_command.rs | 42 ++++++++++++++----------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/commands/add_command.rs b/src/commands/add_command.rs index 946dd3c..830a727 100644 --- a/src/commands/add_command.rs +++ b/src/commands/add_command.rs @@ -145,11 +145,10 @@ impl<'a> AddCommand<'a> { #[cfg(test)] mod tests { - use std::fs::{self, File}; + use std::fs; use super::AddCommand; - use crate::config::locations::LocationsProvider; - use std::io::Write; + use crate::config::{app_config::{AppConfig, Project}, locations::LocationsProvider}; #[test] fn add_file_when_project_does_not_exist() { @@ -162,8 +161,8 @@ mod tests { let user_file = current_dir.path().join("file"); let config_file = config_dir.path().join("config.json"); - let mut file = File::create(&config_file).unwrap(); - write!(file, "{{\"projects\":[]}}").unwrap(); + let config = AppConfig { projects: vec![] }; + fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap(); let sut = AddCommand::new(&locations_provider); @@ -187,13 +186,10 @@ mod tests { let user_file = current_dir.path().join("file"); let config_file = config_dir.path().join("config.json"); - let mut file = File::create(&config_file).unwrap(); - write!( - file, - "{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}", - current_dir.path().to_str().unwrap() - ) - .unwrap(); + let config = AppConfig { + projects: vec![Project { name: "proj1".into(), id: "1".into(), path: current_dir.path().to_path_buf() }], + }; + fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap(); let sut = AddCommand::new(&locations_provider); @@ -210,13 +206,10 @@ mod tests { LocationsProvider::new(config_dir.path().to_path_buf(), data_dir.path().to_path_buf()); let config_file = config_dir.path().join("config.json"); - let mut file = File::create(&config_file).unwrap(); - write!( - file, - "{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}", - project_root.path().to_str().unwrap() - ) - .unwrap(); + let config = AppConfig { + projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }], + }; + fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap(); let subdir = project_root.path().join("config"); fs::create_dir_all(&subdir).unwrap(); @@ -239,13 +232,10 @@ mod tests { LocationsProvider::new(config_dir.path().to_path_buf(), data_dir.path().to_path_buf()); let config_file = config_dir.path().join("config.json"); - let mut file = File::create(&config_file).unwrap(); - write!( - file, - "{{\"projects\":[{{\"name\":\"proj1\", \"path\":\"{}\", \"id\":\"1\"}}]}}", - project_root.path().to_str().unwrap() - ) - .unwrap(); + let config = AppConfig { + projects: vec![Project { name: "proj1".into(), id: "1".into(), path: project_root.path().to_path_buf() }], + }; + fs::write(&config_file, serde_json::to_string(&config).unwrap()).unwrap(); let subdir = project_root.path().join("config"); fs::create_dir_all(&subdir).unwrap();