#![allow(clippy::too_many_lines)]
mod support;
use std::collections::HashSet;
use sqry_daemon::ipc::framing::{read_frame_json, write_frame_json};
use sqry_daemon_protocol::{ShimProtocol, ShimRegister, ShimRegisterAck};
use sqry_mcp::tools_schema::DAEMON_SUPPORTED_TOOL_NAMES;
use support::ipc::TestServer;
use tokio::net::UnixStream;
async fn connect_mcp_shim(
server: &TestServer,
) -> (
tokio::io::ReadHalf<UnixStream>,
tokio::io::WriteHalf<UnixStream>,
) {
let stream = UnixStream::connect(&server.path).await.expect("connect");
let (mut read_half, mut write_half) = tokio::io::split(stream);
let shim_reg = ShimRegister {
protocol: ShimProtocol::Mcp,
pid: std::process::id(),
};
write_frame_json(&mut write_half, &shim_reg)
.await
.expect("write ShimRegister");
let ack = read_frame_json::<_, ShimRegisterAck>(&mut read_half)
.await
.expect("read ack")
.expect("ack frame");
assert!(
ack.accepted,
"ShimRegisterAck must be accepted; reason={:?}",
ack.reason
);
(read_half, write_half)
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn daemon_tools_list_exactly_15_names_matches_daemon_supported_tool_names() {
let server = TestServer::new().await;
let (read_half, write_half) = connect_mcp_shim(&server).await;
let running = rmcp::serve_client((), (read_half, write_half))
.await
.expect("rmcp client initialize");
let list_result = running
.peer()
.list_tools(None)
.await
.expect("list_tools must succeed");
let got_names: HashSet<&str> = list_result.tools.iter().map(|t| t.name.as_ref()).collect();
let expected_names: HashSet<&str> = DAEMON_SUPPORTED_TOOL_NAMES.iter().copied().collect();
assert_eq!(
got_names, expected_names,
"daemon tools/list must return exactly DAEMON_SUPPORTED_TOOL_NAMES \
(16 tools after NL07: 15 query tools + sqry_ask). \
Got {got_names:?}, expected {expected_names:?}"
);
assert_eq!(
list_result.tools.len(),
16,
"tools list length must be exactly 16 under default feature flags \
(15 query tools + sqry_ask from NL07)"
);
drop(running);
server.stop().await;
}