2026-09-27 21:46:16 +02:00
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 );
2026-11-01 20:32:16 +01:00
using ( Assert . EnterMultipleScope ())
2026-09-27 21:46:16 +02:00
{
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 );
2026-11-01 20:32:16 +01:00
}
2026-09-27 21:46:16 +02:00
}
[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 );
2026-11-01 20:32:16 +01:00
using ( Assert . EnterMultipleScope ())
2026-09-27 21:46:16 +02:00
{
Assert . That ( isValid , Is . True );
Assert . That ( error , Is . Empty );
2026-11-01 20:32:16 +01:00
}
2026-09-27 21:46:16 +02:00
}
[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 );
2026-11-01 20:32:16 +01:00
using ( Assert . EnterMultipleScope ())
2026-09-27 21:46:16 +02:00
{
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." );
2026-11-01 20:32:16 +01:00
}
2026-09-27 21:46:16 +02:00
}
}