Add serialization roundtrip tests for all Protocol namespace types (#1289)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
392e47ea29
commit
4cef394ad5
1 changed files with 3222 additions and 475 deletions
|
|
@ -91,4 +91,51 @@ public static class ToolTests
|
|||
Assert.Contains("\"annotations\":", json);
|
||||
Assert.Contains("\"inputSchema\":", json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void ToolInputSchema_HasValidDefaultSchema()
|
||||
{
|
||||
var tool = new Tool();
|
||||
JsonElement jsonElement = tool.InputSchema;
|
||||
|
||||
Assert.Equal(JsonValueKind.Object, jsonElement.ValueKind);
|
||||
Assert.Single(jsonElement.EnumerateObject());
|
||||
Assert.True(jsonElement.TryGetProperty("type", out JsonElement typeElement));
|
||||
Assert.Equal(JsonValueKind.String, typeElement.ValueKind);
|
||||
Assert.Equal("object", typeElement.GetString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("null")]
|
||||
[InlineData("false")]
|
||||
[InlineData("true")]
|
||||
[InlineData("3.5e3")]
|
||||
[InlineData("[]")]
|
||||
[InlineData("{}")]
|
||||
[InlineData("""{"properties":{}}""")]
|
||||
[InlineData("""{"type":"number"}""")]
|
||||
[InlineData("""{"type":"array"}""")]
|
||||
[InlineData("""{"type":["object"]}""")]
|
||||
public static void ToolInputSchema_RejectsInvalidSchemaDocuments(string invalidSchema)
|
||||
{
|
||||
using var document = JsonDocument.Parse(invalidSchema);
|
||||
var tool = new Tool();
|
||||
|
||||
Assert.Throws<ArgumentException>(() => tool.InputSchema = document.RootElement);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("""{"type":"object"}""")]
|
||||
[InlineData("""{"type":"object", "properties": {}, "required" : [] }""")]
|
||||
[InlineData("""{"type":"object", "title": "MyAwesomeTool", "description": "It's awesome!", "properties": {}, "required" : ["NotAParam"] }""")]
|
||||
public static void ToolInputSchema_AcceptsValidSchemaDocuments(string validSchema)
|
||||
{
|
||||
using var document = JsonDocument.Parse(validSchema);
|
||||
Tool tool = new()
|
||||
{
|
||||
InputSchema = document.RootElement
|
||||
};
|
||||
|
||||
Assert.True(JsonElement.DeepEquals(document.RootElement, tool.InputSchema));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue