Fix starred scope page tree and local edit save

This commit is contained in:
lix-2026
2026-05-27 13:50:31 +08:00
parent c01dc2dea2
commit bd7470d03e
8 changed files with 414 additions and 5 deletions
+49 -1
View File
@@ -4,7 +4,7 @@ use crate::error::WebError;
use crate::routes::local_folder_source::{
ensure_local_workspace_read_access_with_state, load_local_folder_file_tree_children_snapshot,
load_local_folder_file_tree_snapshot, load_local_folder_file_tree_snapshot_with_reveal,
load_local_folder_page_tree_snapshot,
load_local_folder_page_tree_scope_snapshot, load_local_folder_page_tree_snapshot,
};
use crate::routes::query_support::resolve_effective_workspace_id;
use crate::routes::snapshot_support::{
@@ -120,6 +120,8 @@ async fn project_projection(
} else {
load_local_folder_file_tree_snapshot(&root_uri)
}
} else if let Some(parent_relative_path) = parent_relative_path.as_deref() {
load_local_folder_page_tree_scope_snapshot(&root_uri, parent_relative_path)
} else {
load_local_folder_page_tree_snapshot(&root_uri)
}
@@ -422,6 +424,52 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
#[tokio::test]
async fn local_folder_page_projection_can_scope_by_parent_path() {
let root = std::env::temp_dir().join(format!(
"mnote-local-kernel-page-scope-{}",
std::process::id()
));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(root.join("design")).expect("create design");
std::fs::write(root.join("Home.md"), "# Home\n").expect("write home");
std::fs::write(root.join("Other.md"), "# Other\n").expect("write other");
std::fs::write(root.join("design").join("Brief.md"), "# Brief\n").expect("write brief");
let root_uri = format!("file://{}", root.display());
initialize_local_workspace_for_actor("dev-user", &root_uri).expect("init local workspace");
let response = app()
.oneshot(
Request::builder()
.uri(format!(
"/api/tree/projections/sidebar?workspaceId=local-ws:dev-user:my-space&sourceKind=local_folder&rootUri={root_uri}&parentRelativePath=design"
))
.header("x-mnote-actor-id", "dev-user")
.header("x-mnote-actor-type", "user")
.body(Body::empty())
.expect("request"),
)
.await
.expect("response");
assert_eq!(response.status(), StatusCode::OK);
let body = to_bytes(response.into_body(), usize::MAX)
.await
.expect("body");
let payload: Value = serde_json::from_slice(&body).expect("json");
let items = payload["result"]["items"].as_array().expect("items");
let titles = items
.iter()
.filter_map(|item| item["title"].as_str())
.collect::<Vec<_>>();
assert_eq!(payload["result"]["parentRelativePath"], "design");
assert!(titles.contains(&"Brief"));
assert!(!titles.contains(&"Home"));
assert!(!titles.contains(&"Other"));
let _ = std::fs::remove_dir_all(&root);
}
#[tokio::test]
async fn local_folder_file_projection_can_load_direct_children_by_parent_path() {
let root = std::env::temp_dir().join(format!(