From f27bdc4afa5959834ab7f67f458d7e20f1f4a61f Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 19 Oct 2026 21:09:01 -0400 Subject: [PATCH] test(rust): a file named like a sample folder is refused, nothing created (#384) Review 25592, point 1: the pre-check reads exists(), not is_dir(); under is_dir() a file named "Exemple Tangerine" let "Exemple Desjardins" be created before create_dir failed with a raw "File exists". The reviewer's test pins it. Co-Authored-By: Claude Opus 5.5 --- src-tauri/src/commands/fs_commands.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src-tauri/src/commands/fs_commands.rs b/src-tauri/src/commands/fs_commands.rs index 0d90f42..d3ddd43 100644 --- a/src-tauri/src/commands/fs_commands.rs +++ b/src-tauri/src/commands/fs_commands.rs @@ -456,6 +456,23 @@ mod sample_folder_tests { assert_eq!(entries, 1, "nothing but the existing folder"); } + /// A FILE named like a sample folder blocks it as well (#384 review): the + /// check reads `exists()`, not `is_dir()`, so nothing is half-created and + /// the refusal keeps its code instead of a raw "File exists" from + /// `create_dir`. + #[test] + fn refuses_a_file_named_like_a_sample_folder_and_writes_nothing() { + let dir = sandbox("file-tangerine"); + fs::write(dir.join(SAMPLE_TANGERINE_FOLDER), "").unwrap(); + let result = create_sample_import_folders(as_arg(&dir), "2026-09-25".to_string()); + let desjardins_created = dir.join(SAMPLE_DESJARDINS_FOLDER).exists(); + let entries = fs::read_dir(&dir).unwrap().count(); + cleanup(&dir); + assert_eq!(result.unwrap_err(), "sample_folder_exists:Exemple Tangerine"); + assert!(!desjardins_created, "Exemple Desjardins must not be created"); + assert_eq!(entries, 1, "nothing but the existing file"); + } + #[test] fn writes_both_folders_for_the_two_previous_months() { let dir = sandbox("success");