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"), + "目录名称无效" + ); + } +}