AI-Studio/app/Tests/Tools/ToolCalling/ToolSettingsValueParserTests.cs
Peer Hogeterp 7cedd03adb
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 free address choice to the Read Web Page tool (#997)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
2026-09-27 21:46:16 +02:00

61 lines
2.5 KiB
C#

using AIStudio.Tools.ToolCallingSystem;
namespace AIStudio.Tests.Tools.ToolCalling;
/// <summary>
/// Checks the shared check of a stored choice against the option source it was picked from.
/// </summary>
/// <remarks>
/// A stored value can predate the list it was picked from, or come from an organization's
/// configuration with a typo in it. Every tool with a choice relies on this check to report such
/// a value instead of acting on it, so it is tested here once rather than through each tool.
/// </remarks>
[TestFixture]
public sealed class ToolSettingsValueParserTests
{
private const string KEY = "defaultSafeSearch";
private const string ERROR_FORMAT = "The setting '{0}' holds '{1}'.";
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public void AnEmptyValuePasses(string? value)
{
var settingsValues = value is null ? new Dictionary<string, string>() : new Dictionary<string, string> { [KEY] = value };
var isValid = ToolSettingsValueParser.TryValidateOptionValue(settingsValues, KEY, ToolSettingsOptionSources.SAFE_SEARCH, ERROR_FORMAT, out var error);
Assert.Multiple(() =>
{
Assert.That(isValid, Is.True, "Whether a field may stay empty is for the schema's required list to decide, not for this check.");
Assert.That(error, Is.Empty);
});
}
[Test]
public void AnOfferedValuePasses()
{
var settingsValues = new Dictionary<string, string> { [KEY] = nameof(SafeSearchPolicy.MODERATE) };
var isValid = ToolSettingsValueParser.TryValidateOptionValue(settingsValues, KEY, ToolSettingsOptionSources.SAFE_SEARCH, ERROR_FORMAT, out var error);
Assert.Multiple(() =>
{
Assert.That(isValid, Is.True);
Assert.That(error, Is.Empty);
});
}
[TestCase("moderate")]
[TestCase("MEDIUM")]
public void AValueNotOfferedIsReportedWithKeyAndValue(string value)
{
var settingsValues = new Dictionary<string, string> { [KEY] = value };
var isValid = ToolSettingsValueParser.TryValidateOptionValue(settingsValues, KEY, ToolSettingsOptionSources.SAFE_SEARCH, ERROR_FORMAT, out var error);
Assert.Multiple(() =>
{
Assert.That(isValid, Is.False, "The stored value is compared exactly, the way the option source offers it.");
Assert.That(error, Is.EqualTo($"The setting '{KEY}' holds '{value}'."), "The message has to name the field and the value, or nobody can find what to correct.");
});
}
}