50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
// MCP Add/Disconnect error handling tests
|
|
// Catch2 migration from GTest (yams-3s4 / yams-84g)
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <string>
|
|
|
|
#include <yams/mcp/mcp_server.h>
|
|
|
|
#include "../../common/test_helpers_catch2.h"
|
|
|
|
using nlohmann::json;
|
|
using yams::mcp::ITransport;
|
|
using yams::mcp::MCPServer;
|
|
|
|
namespace {
|
|
class NullTransport : public ITransport {
|
|
public:
|
|
yams::mcp::MessageResult receive() override {
|
|
return yams::Error{yams::ErrorCode::NetworkError, "closed"};
|
|
}
|
|
void send(const json&) override {}
|
|
yams::mcp::TransportState getState() const override {
|
|
return yams::mcp::TransportState::Connected;
|
|
}
|
|
bool isConnected() const override { return true; }
|
|
void close() override {}
|
|
};
|
|
} // namespace
|
|
|
|
TEST_CASE("MCP AddDisconnect - Error contains socket and hint", "[mcp][disconnect][catch2]") {
|
|
auto t = std::make_unique<NullTransport>();
|
|
MCPServer svr(std::move(t));
|
|
#if !defined(_WIN32)
|
|
yams::test::ScopedEnvVar runtimeDirectory{"XDG_RUNTIME_DIR", std::string{"/run/user/1002"}};
|
|
#endif
|
|
svr.setEnsureDaemonClientHook([&](const yams::daemon::ClientConfig&) -> yams::Result<void> {
|
|
return yams::Error{yams::ErrorCode::NetworkError, "dial error"};
|
|
});
|
|
json args = {
|
|
{"path", "/does/not/exist.txt"},
|
|
};
|
|
auto res = svr.callToolPublic("add", args);
|
|
REQUIRE(res.contains("error"));
|
|
auto msg = res["error"].value("message", std::string{});
|
|
bool ok = (msg.find("yams-daemon.sock") != std::string::npos &&
|
|
msg.find("YAMS_DAEMON_SOCKET") != std::string::npos) ||
|
|
(msg.find("dial") != std::string::npos);
|
|
CHECK(ok);
|
|
}
|