修正策划文件删除逻辑的 Rust 格式
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m29s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 2m1s
Project CI / Backend tests (pull_request) Successful in 3m48s
Project CI / Frontend tests (pull_request) Successful in 1m47s
Project CI / Native shell tests (pull_request) Successful in 5m49s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 8m35s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 8m40s
Project CI / Repository checks (pull_request) Successful in 2m30s
Project CI / AI game creator shell web tests (pull_request) Successful in 2m3s

按 cargo fmt 整理删除路径解析与回归测试断言的换行
This commit is contained in:
2026-09-29 10:14:41 +01:00
parent 541fe07a7e
commit d10ab9c77b
@@ -843,7 +843,8 @@ fn design_path_is_link(path: &Path) -> bool {
}
fn remove_design_path(workspace: &Path, path: &Path) -> Result<(), String> {
let metadata = fs::symlink_metadata(path).map_err(|error| format!("读取删除目标失败:{error}"))?;
let metadata =
fs::symlink_metadata(path).map_err(|error| format!("读取删除目标失败:{error}"))?;
if design_path_is_link(path) {
// Windows 目录链接 / junction 使用 RemoveDirectory,且不能解析到链接目标。
#[cfg(windows)]
@@ -857,9 +858,10 @@ fn remove_design_path(workspace: &Path, path: &Path) -> Result<(), String> {
return fs::remove_file(path).map_err(|error| format!("删除失败:{error}"));
}
if metadata.is_dir() {
let target = fs::canonicalize(path).map_err(|error| format!("解析删除目标失败:{error}"))?;
let workspace = fs::canonicalize(workspace)
.map_err(|error| format!("解析策划工作区失败:{error}"))?;
let target =
fs::canonicalize(path).map_err(|error| format!("解析删除目标失败:{error}"))?;
let workspace =
fs::canonicalize(workspace).map_err(|error| format!("解析策划工作区失败:{error}"))?;
if workspace.starts_with(&target) {
return Err("不能删除工作区根目录或包含它的上级目录".to_string());
}
@@ -946,7 +948,10 @@ mod tests {
let error = execute_design_file_tool(root, "delete_path", &json!({"path":path}))
.expect_err("protect workspace and ancestors");
assert!(error.contains("不能删除工作区根目录"));
assert_eq!(fs::read_to_string(workspace.join("keep.md")).unwrap(), "keep");
assert_eq!(
fs::read_to_string(workspace.join("keep.md")).unwrap(),
"keep"
);
assert!(workspace.join("child").is_dir());
}
}