mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-06 07:49:40 +00:00
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-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 / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
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 }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
69 lines
3.3 KiB
C#
69 lines
3.3 KiB
C#
using AIStudio.Settings.DataModel;
|
|
|
|
namespace AIStudio.Tests.Tools.ToolCalling;
|
|
|
|
/// <summary>
|
|
/// Checks that a tool which does not exist right now appears nowhere, and comes back with its preview.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The mail tools belong to a preview. While it is switched off, a tool in the selection or in the
|
|
/// settings would promise something AI Studio does not offer yet, and a request would hand the
|
|
/// model a tool for mailboxes nobody can configure. A selection which names such a tool must not
|
|
/// lose it, though: switching the preview on again brings the tool back where it was selected.
|
|
/// </remarks>
|
|
[TestFixture]
|
|
[NonParallelizable]
|
|
public sealed class ToolAvailabilityTests : ToolRegistryTestBase
|
|
{
|
|
private const string PREVIEW_TOOL_ID = "preview_tool";
|
|
|
|
[Test]
|
|
public async Task AnUnavailableToolAppearsInNoList()
|
|
{
|
|
var previewTool = PreviewTool(isAvailable: false);
|
|
var registry = this.CreateRegistry(new TestTool(Definition()), previewTool);
|
|
|
|
var forTheChat = await registry.GetCatalogAsync(AIStudio.Tools.Components.CHAT);
|
|
var forTheSettings = await registry.GetCatalogAsync(registry.GetAllDefinitions());
|
|
var handedInDirectly = await registry.GetCatalogAsync([previewTool.GetDefinition()]);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(registry.GetDefinitionsForComponent(AIStudio.Tools.Components.CHAT).Select(definition => definition.Id), Is.EqualTo(new[] { TOOL_ID }));
|
|
Assert.That(registry.GetAllDefinitions().Select(definition => definition.Id), Is.EqualTo(new[] { TOOL_ID }));
|
|
Assert.That(forTheChat.Select(item => item.Id), Is.EqualTo(new[] { TOOL_ID }), "The selection below the message field.");
|
|
Assert.That(forTheSettings.Select(item => item.Id), Is.EqualTo(new[] { TOOL_ID }), "The tool list of the app settings.");
|
|
Assert.That(handedInDirectly, Is.Empty, "Whoever hands in the definition directly does not get it listed either.");
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void TheTokenCountLeavesAnUnavailableToolOut()
|
|
{
|
|
var registry = this.CreateRegistry(new TestTool(Definition()), PreviewTool(isAvailable: false));
|
|
|
|
var counted = registry.FilterToolIdsForProvider(ToolCapableProvider(), [TOOL_ID, PREVIEW_TOOL_ID], OutboundDataRestriction.UNRESTRICTED);
|
|
|
|
Assert.That(counted, Is.EquivalentTo(new[] { TOOL_ID }));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ASelectedToolComesBackWithItsPreview()
|
|
{
|
|
var previewTool = PreviewTool(isAvailable: false);
|
|
var registry = this.CreateRegistry(previewTool);
|
|
string[] selection = [PREVIEW_TOOL_ID];
|
|
|
|
var whileSwitchedOff = await registry.GetRunnableToolsAsync(this.ContextFor(ToolCapableProvider()), selection, mayRunTools: true);
|
|
previewTool.IsAvailable = true;
|
|
var afterSwitchingOn = await registry.GetRunnableToolsAsync(this.ContextFor(ToolCapableProvider()), selection, mayRunTools: true);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(whileSwitchedOff, Is.Empty);
|
|
Assert.That(afterSwitchingOn.Select(tool => tool.Definition.Id), Is.EqualTo(new[] { PREVIEW_TOOL_ID }), "The selection kept the tool all along.");
|
|
});
|
|
}
|
|
|
|
private static TestTool PreviewTool(bool isAvailable) => new(Definition(PREVIEW_TOOL_ID)) { IsAvailable = isAvailable };
|
|
} |