forked from modelcontextprotocol/ruby-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogress_test.rb
More file actions
71 lines (57 loc) · 2.37 KB
/
progress_test.rb
File metadata and controls
71 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
require "test_helper"
module MCP
class ProgressTest < ActiveSupport::TestCase
class MockTransport < Transport
attr_reader :notifications
def initialize(server)
super
@notifications = []
end
def send_notification(method, params = nil)
@notifications << { method: method, params: params }
true
end
def send_response(response); end
def open; end
def close; end
def handle_request(request); end
end
setup do
@server = Server.new(name: "test_server")
@transport = MockTransport.new(@server)
@session = ServerSession.new(server: @server, transport: @transport)
end
test "#report is a no-op when progress_token is nil" do
progress = Progress.new(notification_target: @session, progress_token: nil)
progress.report(50, total: 100, message: "halfway")
assert_equal 0, @transport.notifications.size
end
test "#report is a no-op when notification_target is nil" do
progress = Progress.new(notification_target: nil, progress_token: "token-1")
progress.report(50, total: 100, message: "halfway")
assert_equal 0, @transport.notifications.size
end
test "#report sends notification when progress_token is present" do
progress = Progress.new(notification_target: @session, progress_token: "token-1")
progress.report(50, total: 100, message: "halfway")
assert_equal 1, @transport.notifications.size
notification = @transport.notifications.first
assert_equal Methods::NOTIFICATIONS_PROGRESS, notification[:method]
assert_equal "token-1", notification[:params]["progressToken"]
assert_equal 50, notification[:params]["progress"]
assert_equal 100, notification[:params]["total"]
assert_equal "halfway", notification[:params]["message"]
end
test "#report omits total and message when not provided" do
progress = Progress.new(notification_target: @session, progress_token: "token-1")
progress.report(50)
assert_equal 1, @transport.notifications.size
notification = @transport.notifications.first
assert_equal "token-1", notification[:params]["progressToken"]
assert_equal 50, notification[:params]["progress"]
refute notification[:params].key?("total")
refute notification[:params].key?("message")
end
end
end