From 092aebf1a4beb506e459cc33422263b57b04fa14 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 27 Aug 2025 13:23:12 +0900 Subject: [PATCH] Extract `MCP::Tool::Annotations` unit tests The tests related to `MCP::Tool::Annotations` will be extracted from the `MCP::ToolTest` test class into a dedicated `MCP::Tool::AnnotationsTest` unit test class as a testing pair. This improves test clarity, file level test independence, and file level execution speed. It also ensures consistent placement as a testing pair under `MCP::Tool::*`: ```console $ ls lib/mcp/tool/ annotations.rb input_schema.rb response.rb $ ls test/mcp/tool/ annotations_test.rb input_schema_test.rb response_test.rb ``` --- test/mcp/tool/annotations_test.rb | 75 +++++++++++++++++++++++++++++++ test/mcp/tool_test.rb | 67 --------------------------- 2 files changed, 75 insertions(+), 67 deletions(-) create mode 100644 test/mcp/tool/annotations_test.rb diff --git a/test/mcp/tool/annotations_test.rb b/test/mcp/tool/annotations_test.rb new file mode 100644 index 00000000..7615ea82 --- /dev/null +++ b/test/mcp/tool/annotations_test.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require "test_helper" + +module MCP + class Tool + class AnnotationsTest < ActiveSupport::TestCase + test "Tool::Annotations initializes with all properties" do + annotations = Tool::Annotations.new( + title: "Test Tool", + read_only_hint: true, + destructive_hint: false, + idempotent_hint: true, + open_world_hint: false, + ) + + assert_equal "Test Tool", annotations.title + assert annotations.read_only_hint + refute annotations.destructive_hint + assert annotations.idempotent_hint + refute annotations.open_world_hint + end + + test "Tool::Annotations initializes with partial properties" do + annotations = Tool::Annotations.new( + title: "Test Tool", + read_only_hint: true, + ) + + assert_equal "Test Tool", annotations.title + assert annotations.read_only_hint + assert_nil annotations.destructive_hint + assert_nil annotations.idempotent_hint + assert_nil annotations.open_world_hint + end + + test "Tool::Annotations#to_h omits nil values" do + annotations = Tool::Annotations.new( + title: "Test Tool", + read_only_hint: true, + ) + + expected = { + title: "Test Tool", + readOnlyHint: true, + } + assert_equal expected, annotations.to_h + end + + test "Tool::Annotations#to_h handles all properties" do + annotations = Tool::Annotations.new( + title: "Test Tool", + read_only_hint: true, + destructive_hint: false, + idempotent_hint: true, + open_world_hint: false, + ) + + expected = { + title: "Test Tool", + readOnlyHint: true, + destructiveHint: false, + idempotentHint: true, + openWorldHint: false, + } + assert_equal expected, annotations.to_h + end + + test "Tool::Annotations#to_h returns empty hash when all values are nil" do + annotations = Tool::Annotations.new + assert_empty annotations.to_h + end + end + end +end diff --git a/test/mcp/tool_test.rb b/test/mcp/tool_test.rb index a7002c10..f2e3838a 100644 --- a/test/mcp/tool_test.rb +++ b/test/mcp/tool_test.rb @@ -145,73 +145,6 @@ class InputSchemaTool < Tool assert_equal({ readOnlyHint: true, title: "Mock Tool" }, tool.annotations_value.to_h) end - # Tests for Tool::Annotations class - test "Tool::Annotations initializes with all properties" do - annotations = Tool::Annotations.new( - title: "Test Tool", - read_only_hint: true, - destructive_hint: false, - idempotent_hint: true, - open_world_hint: false, - ) - - assert_equal "Test Tool", annotations.title - assert annotations.read_only_hint - refute annotations.destructive_hint - assert annotations.idempotent_hint - refute annotations.open_world_hint - end - - test "Tool::Annotations initializes with partial properties" do - annotations = Tool::Annotations.new( - title: "Test Tool", - read_only_hint: true, - ) - - assert_equal "Test Tool", annotations.title - assert annotations.read_only_hint - assert_nil annotations.destructive_hint - assert_nil annotations.idempotent_hint - assert_nil annotations.open_world_hint - end - - test "Tool::Annotations#to_h omits nil values" do - annotations = Tool::Annotations.new( - title: "Test Tool", - read_only_hint: true, - ) - - expected = { - title: "Test Tool", - readOnlyHint: true, - } - assert_equal expected, annotations.to_h - end - - test "Tool::Annotations#to_h handles all properties" do - annotations = Tool::Annotations.new( - title: "Test Tool", - read_only_hint: true, - destructive_hint: false, - idempotent_hint: true, - open_world_hint: false, - ) - - expected = { - title: "Test Tool", - readOnlyHint: true, - destructiveHint: false, - idempotentHint: true, - openWorldHint: false, - } - assert_equal expected, annotations.to_h - end - - test "Tool::Annotations#to_h returns empty hash when all values are nil" do - annotations = Tool::Annotations.new - assert_empty annotations.to_h - end - test "Tool class method annotations can be set and retrieved" do class AnnotationsTestTool < Tool tool_name "annotations_test"