Implement Rust web sidebar title and tree interactions

This commit is contained in:
lix-2026
2026-04-30 05:46:36 +08:00
parent 559c5ce652
commit 3cc090ba5e
35 changed files with 3029 additions and 424 deletions
+32
View File
@@ -153,8 +153,19 @@ struct StreamPollState {
}
fn stream_event(event_name: &str, payload: &Value) -> Event {
let event_id = payload
.get("revision")
.and_then(|value| {
value
.as_str()
.map(ToOwned::to_owned)
.or_else(|| value.as_u64().map(|number| number.to_string()))
})
.or_else(|| payload.get("cursor").and_then(Value::as_str).map(ToOwned::to_owned))
.unwrap_or_else(|| "0".into());
Event::default()
.event(event_name)
.id(event_id)
.json_data(payload)
.expect("SSE 事件必须可序列化")
}
@@ -245,4 +256,25 @@ mod tests {
assert!(text.contains("event: snapshot") || text.contains("event:snapshot"));
assert!(text.contains("\"kind\":\"snapshot\""));
}
#[tokio::test]
async fn tree_events_route_includes_event_id_and_revision() {
let response = app()
.oneshot(
Request::builder()
.uri("/api/tree/events?workspaceId=ws_demo&maxPolls=0")
.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 text = String::from_utf8(body.to_vec()).expect("utf8");
assert!(text.contains("id: "));
assert!(text.contains("\"revision\""));
}
}