AI-Studio/app/Tests/Tools/ToolCalling/ToolParameterSchemaBuilderTests.cs
Thorsten Sommer 1eaca9b12f
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Added a semantic search tool (#1005)
2026-09-27 16:26:52 +02:00

52 lines
2.1 KiB
C#

using System.Text.Json.Nodes;
using AIStudio.Tools.ToolCallingSystem;
namespace AIStudio.Tests.Tools.ToolCalling;
/// <summary>
/// Checks the plain JSON Schema a tool describes its arguments with.
/// </summary>
/// <remarks>
/// This is the form Anthropic and every host without strict mode receive as written, so it has to
/// mean exactly what the tool expects. The translation for strict mode is checked on its own, see
/// OpenAIStrictToolSchemaTests.
/// </remarks>
[TestFixture]
public sealed class ToolParameterSchemaBuilderTests
{
[Test]
public void AListOfChoicesRestrictsEveryEntry()
{
var schema = Built(ToolParameterSchemaBuilder.Create().OptionalStringArray("data_source_ids", "The data sources.", "first", "second"));
var property = schema["properties"]!["data_source_ids"]!;
Assert.Multiple(() =>
{
Assert.That(property["type"]!.GetValue<string>(), Is.EqualTo("array"));
Assert.That(property["description"]!.GetValue<string>(), Is.EqualTo("The data sources."));
Assert.That(property["items"]!["type"]!.GetValue<string>(), Is.EqualTo("string"));
Assert.That(property["items"]!["enum"]!.AsArray().Select(value => value!.GetValue<string>()), Is.EqualTo(new[] { "first", "second" }));
});
}
[Test]
public void AListWithoutChoicesTakesAnyString()
{
var items = Built(ToolParameterSchemaBuilder.Create().OptionalStringArray("tags", "Some tags."))["properties"]!["tags"]!["items"]!;
Assert.That(items["enum"], Is.Null, "An empty enum would allow no entry at all rather than any.");
}
[Test]
public void AnOptionalListIsNotRequired()
{
var schema = Built(ToolParameterSchemaBuilder.Create()
.RequiredString("query", "The search query.")
.OptionalStringArray("data_source_ids", "The data sources.", "first"));
Assert.That(schema["required"]!.AsArray().Select(name => name!.GetValue<string>()), Is.EqualTo(new[] { "query" }));
}
private static JsonNode Built(ToolParameterSchemaBuilder builder) => JsonNode.Parse(builder.Build().GetRawText())!;
}