fix: align local markdown conflict and title behavior

This commit is contained in:
lix-2026
2026-05-24 18:16:05 +08:00
parent 289a44acea
commit 9c4bb58257
9 changed files with 664 additions and 17 deletions
@@ -92,11 +92,7 @@ async fn build_document_events_stream(
match subscription.receiver.recv().await {
Ok(payload) => {
if let Some(expected) = document_relative_path.as_deref() {
let relative_path = payload
.get("relativePath")
.and_then(Value::as_str)
.unwrap_or_default();
if expected != relative_path {
if !document_event_targets_relative_path(&payload, expected) {
continue;
}
}
@@ -239,6 +235,14 @@ fn local_markdown_relative_path_from_document_id(document_id: &str) -> Option<St
decode_local_id_segment(encoded).ok()
}
fn document_event_targets_relative_path(payload: &Value, expected: &str) -> bool {
let relative_path = payload
.get("relativePath")
.and_then(Value::as_str)
.unwrap_or_default();
expected == relative_path
}
fn system_time_ms(time: SystemTime) -> u128 {
time.duration_since(UNIX_EPOCH)
.map(|duration| duration.as_millis())
@@ -368,6 +372,23 @@ mod tests {
);
}
#[test]
fn document_event_filter_rejects_resource_only_changes() {
let payload = json!({
"sourceKind": "local_folder",
"rootUri": "file:///test",
"relativePath": "docs/README/image.png",
"documentId": "",
"eventKind": "Create(File)",
"revision": 1,
});
assert!(
!document_event_targets_relative_path(&payload, "docs/README.md"),
"正文事件流不能把资源文件变化当作 Markdown 正文变化"
);
}
#[test]
fn build_tree_snapshot_payload_has_required_fields() {
let sidebar_projection = json!({