From dfb7617cbb2eb50768743a55f4a4069c800efa52 Mon Sep 17 00:00:00 2001 From: Linghong Date: Tue, 15 Sep 2026 14:42:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85AGC=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=88=9B=E5=BB=BA=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 覆盖子目录创建、重名和路径分隔符校验 --- .../src-tauri/src/commands.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/apps/ai-game-creator-shell/src-tauri/src/commands.rs b/apps/ai-game-creator-shell/src-tauri/src/commands.rs index d8dd83cae..e97c894a1 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/commands.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/commands.rs @@ -5399,3 +5399,47 @@ pub(crate) fn write_project_permission_policy( let _lock = acquire_project_write_lock(root, "project.policy_write")?; write_project_permission_policy_at(root, policy) } + +#[cfg(test)] +mod custom_directory_tests { + use super::create_local_project_directory; + use std::fs; + + #[test] + fn creates_child_directory_without_touching_parent_contents() { + let root = tempfile::tempdir().expect("temp parent"); + let created = create_local_project_directory( + root.path().to_string_lossy().into_owned(), + "new-game".to_string(), + ) + .expect("create directory"); + let path = std::path::PathBuf::from(created); + assert!(path.is_dir()); + assert!(fs::read_dir(root.path()) + .expect("read parent") + .next() + .is_some()); + } + + #[test] + fn rejects_existing_child_and_path_separator() { + let root = tempfile::tempdir().expect("temp parent"); + fs::create_dir(root.path().join("existing")).expect("existing"); + assert_eq!( + create_local_project_directory( + root.path().to_string_lossy().into_owned(), + "existing".to_string(), + ) + .expect_err("duplicate must fail"), + "目录已存在" + ); + assert_eq!( + create_local_project_directory( + root.path().to_string_lossy().into_owned(), + "nested/name".to_string(), + ) + .expect_err("separator must fail"), + "目录名称无效" + ); + } +}