Watch
0
0
Fork
You've already forked hyperhive
0

hive-matrix-mcp: test reading, members, joining, files, unread summaries and the MCP tools

This commit is contained in:
damocles 2026-11-17 00:17:42 +01:00 • committed by mara
commit 2e30163d5c

View file

@ -610,3 +610,88 @@ pub async fn serve_http(addr: std::net::SocketAddr, registry: Arc<Registry>) ->
axum::serve(listener, app).await?;
Ok(())
}
#[cfg(test)]
mod tests {
use matrix_sdk::ruma::room_id;
use matrix_sdk::test_utils::mocks::MatrixMockServer;
use super::*;
/// A tool set whose only account, the primary, is a client of `server` that
/// has joined `!room:localhost`.
async fn tools_on(server: &MatrixMockServer) -> MatrixMcp {
let client = server.client_builder().build().await;
server
.sync_joined_room(&client, room_id!("!room:localhost"))
.await;
let registry = Registry::new("main".to_owned());
registry.insert("main".to_owned(), client);
MatrixMcp {
registry: Arc::new(registry),
}
}
#[test]
fn an_ok_is_pretty_json_and_an_error_says_it_is_one() {
let ok = render(DaemonResponse::ok(&serde_json::json!({"a": 1})));
assert_eq!(ok, "{\n \"a\": 1\n}");
assert_eq!(
render(DaemonResponse::error("no room")),
"matrix error: no room"
);
}
#[tokio::test]
async fn a_tool_acts_as_the_primary_account_when_none_is_named() {
let server = MatrixMockServer::new().await;
let tools = tools_on(&server).await;
let out = tools
.list_rooms(Parameters(ListRoomsArgs { account: None }))
.await;
assert!(out.contains("!room:localhost"), "{out}");
}
#[tokio::test]
async fn a_tool_for_an_unknown_account_says_which_ones_exist() {
let server = MatrixMockServer::new().await;
let tools = tools_on(&server).await;
let out = tools
.list_rooms(Parameters(ListRoomsArgs {
account: Some("other".to_owned()),
}))
.await;
assert!(out.starts_with("matrix error: "), "{out}");
assert!(out.contains("available accounts: [main]"), "{out}");
}
#[tokio::test]
async fn the_unread_summary_endpoint_answers_for_the_primary_account() {
let server = MatrixMockServer::new().await;
let tools = tools_on(&server).await;
server.mock_room_state_encryption().plain().mount().await;
server
.mock_room_messages()
.ok(matrix_sdk::test_utils::mocks::RoomMessagesResponseTemplate::default())
.mount()
.await;
let axum::Json(body) = unread_summary_handler(axum::extract::State(tools.registry)).await;
assert_eq!(body["kind"], "ok");
assert_eq!(body["payload"], serde_json::json!([]));
}
#[tokio::test]
async fn the_unread_summary_endpoint_reports_a_registry_without_accounts() {
let registry = Arc::new(Registry::new("main".to_owned()));
let axum::Json(body) = unread_summary_handler(axum::extract::State(registry)).await;
assert_eq!(body["kind"], "error");
}
}