2026-11-21 19:47:10 +01:00
using AIStudio.Provider ;
using AIStudio.Settings ;
using Microsoft.Extensions.Logging.Abstractions ;
namespace AIStudio.Tests.Settings ;
/// <summary>
2026-11-27 12:08:00 +01:00
/// Checks when the minimum confidence of an AI task applies.
2026-11-21 19:47:10 +01:00
/// </summary>
/// <remarks>
/// The text content cleaner, the data source selection, and the retrieval context validation apply their
/// provider and their minimum only while their preselection is switched on, like the assistants. The audit
/// of plugins has no such switch, so its minimum always applies. Names are written out in full where a short
/// one would find a namespace of this assembly first, see AIOperationProviderResolverTests.
/// </remarks>
[TestFixture]
2026-11-27 12:08:00 +01:00
public sealed class AITaskMinimumConfidenceTests
2026-11-21 19:47:10 +01:00
{
[Test]
public void TheTextContentCleanerAppliesItsMinimumOnlyWithItsPreselection ()
{
var settingsManager = CreateSettingsManager ();
settingsManager . ConfigurationData . TextContentCleaner . MinimumProviderConfidence = ConfidenceLevel . HIGH ;
2026-11-27 12:08:00 +01:00
AssertMinimumFollowsPreselection ( settingsManager , AIStudio . Tools . Components . AI_TASK_TEXT_CONTENT_CLEANER , on => settingsManager . ConfigurationData . TextContentCleaner . PreselectOptions = on );
2026-11-21 19:47:10 +01:00
}
[Test]
public void TheDataSourceSelectionAppliesItsMinimumOnlyWithItsPreselection ()
{
var settingsManager = CreateSettingsManager ();
2026-11-27 12:08:00 +01:00
settingsManager . ConfigurationData . DataSourceSelection . MinimumProviderConfidence = ConfidenceLevel . HIGH ;
2026-11-21 19:47:10 +01:00
2026-11-27 12:08:00 +01:00
AssertMinimumFollowsPreselection ( settingsManager , AIStudio . Tools . Components . AI_TASK_DATA_SOURCE_SELECTION , on => settingsManager . ConfigurationData . DataSourceSelection . PreselectOptions = on );
2026-11-21 19:47:10 +01:00
}
[Test]
public void TheRetrievalContextValidationAppliesItsMinimumOnlyWithItsPreselection ()
{
var settingsManager = CreateSettingsManager ();
2026-11-27 12:08:00 +01:00
settingsManager . ConfigurationData . RetrievalContextValidation . MinimumProviderConfidence = ConfidenceLevel . HIGH ;
2026-11-21 19:47:10 +01:00
2026-11-27 12:08:00 +01:00
AssertMinimumFollowsPreselection ( settingsManager , AIStudio . Tools . Components . AI_TASK_RETRIEVAL_CONTEXT_VALIDATION , on => settingsManager . ConfigurationData . RetrievalContextValidation . PreselectOptions = on );
2026-11-21 19:47:10 +01:00
}
[Test]
public void ThePluginAuditAlwaysAppliesItsMinimum ()
{
var settingsManager = CreateSettingsManager ();
settingsManager . ConfigurationData . AssistantPluginAudit . MinimumProviderConfidence = ConfidenceLevel . HIGH ;
2026-11-27 12:08:00 +01:00
Assert . That ( AIStudio . Tools . ComponentsExtensions . MinimumConfidence ( AIStudio . Tools . Components . AI_TASK_ASSISTANT_PLUGIN_AUDIT , settingsManager ), Is . EqualTo ( ConfidenceLevel . HIGH ), "The audit has no preselection switch, so nothing may turn its minimum off." );
2026-11-21 19:47:10 +01:00
}
2026-11-27 16:35:51 +01:00
[Test]
public void TheChatCompressionAlwaysAppliesItsMinimum ()
{
var settingsManager = CreateSettingsManager ();
settingsManager . ConfigurationData . ChatCompression . MinimumProviderConfidence = ConfidenceLevel . HIGH ;
Assert . That ( AIStudio . Tools . ComponentsExtensions . MinimumConfidence ( AIStudio . Tools . Components . AI_TASK_CHAT_COMPRESSION , settingsManager ), Is . EqualTo ( ConfidenceLevel . HIGH ), "The chat compression has no preselection switch, so nothing may turn its minimum off." );
}
2026-11-21 19:47:10 +01:00
private static void AssertMinimumFollowsPreselection ( SettingsManager settingsManager , AIStudio . Tools . Components component , Action < bool > setPreselection )
{
setPreselection ( false );
var minimumWithoutPreselection = AIStudio . Tools . ComponentsExtensions . MinimumConfidence ( component , settingsManager );
setPreselection ( true );
var minimumWithPreselection = AIStudio . Tools . ComponentsExtensions . MinimumConfidence ( component , settingsManager );
Assert . Multiple (() =>
{
Assert . That ( minimumWithoutPreselection , Is . EqualTo ( ConfidenceLevel . NONE ), "With the preselection switched off, the stored minimum must not apply." );
Assert . That ( minimumWithPreselection , Is . EqualTo ( ConfidenceLevel . HIGH ));
});
}
/// <summary>
/// Builds a settings manager without the rust service, which reading a minimum never asks.
/// </summary>
private static SettingsManager CreateSettingsManager () => new ( NullLogger < SettingsManager >. Instance , null !);
}