Skip to content

Commit 9486c63

Browse files
authored
Merge pull request #117 from koic/extract_tool_annotations_tests
Extract `MCP::Tool::Annotations` unit tests
2 parents aec8fb8 + 092aebf commit 9486c63

File tree

2 files changed

+75
-67
lines changed

2 files changed

+75
-67
lines changed

test/mcp/tool/annotations_test.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
module MCP
6+
class Tool
7+
class AnnotationsTest < ActiveSupport::TestCase
8+
test "Tool::Annotations initializes with all properties" do
9+
annotations = Tool::Annotations.new(
10+
title: "Test Tool",
11+
read_only_hint: true,
12+
destructive_hint: false,
13+
idempotent_hint: true,
14+
open_world_hint: false,
15+
)
16+
17+
assert_equal "Test Tool", annotations.title
18+
assert annotations.read_only_hint
19+
refute annotations.destructive_hint
20+
assert annotations.idempotent_hint
21+
refute annotations.open_world_hint
22+
end
23+
24+
test "Tool::Annotations initializes with partial properties" do
25+
annotations = Tool::Annotations.new(
26+
title: "Test Tool",
27+
read_only_hint: true,
28+
)
29+
30+
assert_equal "Test Tool", annotations.title
31+
assert annotations.read_only_hint
32+
assert_nil annotations.destructive_hint
33+
assert_nil annotations.idempotent_hint
34+
assert_nil annotations.open_world_hint
35+
end
36+
37+
test "Tool::Annotations#to_h omits nil values" do
38+
annotations = Tool::Annotations.new(
39+
title: "Test Tool",
40+
read_only_hint: true,
41+
)
42+
43+
expected = {
44+
title: "Test Tool",
45+
readOnlyHint: true,
46+
}
47+
assert_equal expected, annotations.to_h
48+
end
49+
50+
test "Tool::Annotations#to_h handles all properties" do
51+
annotations = Tool::Annotations.new(
52+
title: "Test Tool",
53+
read_only_hint: true,
54+
destructive_hint: false,
55+
idempotent_hint: true,
56+
open_world_hint: false,
57+
)
58+
59+
expected = {
60+
title: "Test Tool",
61+
readOnlyHint: true,
62+
destructiveHint: false,
63+
idempotentHint: true,
64+
openWorldHint: false,
65+
}
66+
assert_equal expected, annotations.to_h
67+
end
68+
69+
test "Tool::Annotations#to_h returns empty hash when all values are nil" do
70+
annotations = Tool::Annotations.new
71+
assert_empty annotations.to_h
72+
end
73+
end
74+
end
75+
end

test/mcp/tool_test.rb

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -145,73 +145,6 @@ class InputSchemaTool < Tool
145145
assert_equal({ readOnlyHint: true, title: "Mock Tool" }, tool.annotations_value.to_h)
146146
end
147147

148-
# Tests for Tool::Annotations class
149-
test "Tool::Annotations initializes with all properties" do
150-
annotations = Tool::Annotations.new(
151-
title: "Test Tool",
152-
read_only_hint: true,
153-
destructive_hint: false,
154-
idempotent_hint: true,
155-
open_world_hint: false,
156-
)
157-
158-
assert_equal "Test Tool", annotations.title
159-
assert annotations.read_only_hint
160-
refute annotations.destructive_hint
161-
assert annotations.idempotent_hint
162-
refute annotations.open_world_hint
163-
end
164-
165-
test "Tool::Annotations initializes with partial properties" do
166-
annotations = Tool::Annotations.new(
167-
title: "Test Tool",
168-
read_only_hint: true,
169-
)
170-
171-
assert_equal "Test Tool", annotations.title
172-
assert annotations.read_only_hint
173-
assert_nil annotations.destructive_hint
174-
assert_nil annotations.idempotent_hint
175-
assert_nil annotations.open_world_hint
176-
end
177-
178-
test "Tool::Annotations#to_h omits nil values" do
179-
annotations = Tool::Annotations.new(
180-
title: "Test Tool",
181-
read_only_hint: true,
182-
)
183-
184-
expected = {
185-
title: "Test Tool",
186-
readOnlyHint: true,
187-
}
188-
assert_equal expected, annotations.to_h
189-
end
190-
191-
test "Tool::Annotations#to_h handles all properties" do
192-
annotations = Tool::Annotations.new(
193-
title: "Test Tool",
194-
read_only_hint: true,
195-
destructive_hint: false,
196-
idempotent_hint: true,
197-
open_world_hint: false,
198-
)
199-
200-
expected = {
201-
title: "Test Tool",
202-
readOnlyHint: true,
203-
destructiveHint: false,
204-
idempotentHint: true,
205-
openWorldHint: false,
206-
}
207-
assert_equal expected, annotations.to_h
208-
end
209-
210-
test "Tool::Annotations#to_h returns empty hash when all values are nil" do
211-
annotations = Tool::Annotations.new
212-
assert_empty annotations.to_h
213-
end
214-
215148
test "Tool class method annotations can be set and retrieved" do
216149
class AnnotationsTestTool < Tool
217150
tool_name "annotations_test"

0 commit comments

Comments
 (0)