Added a semantic search tool (#1005)
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

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-09-27 16:26:52 +02:00
1 parent 4baf21656a
commit 1eaca9b12f
91 files changed
+4248 -487

No files matched your search

@@ -0,0 +1,54 @@
using System.Text.Json;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
namespace AIStudio.Tests.Settings;
/// <summary>
/// Checks that the data source defaults of new chats survive the settings file.
/// </summary>
/// <remarks>
/// The settings file holds each of these defaults twice: as a field of its own, and inside the
/// legacy nested object, see documentation/compatibility-shims/2026-07-chat-data-source-options.md.
/// The nested object is read after the fields and therefore wins. A default which the nested object
/// forgets to carry would go back to the app default with every start, and nobody would notice
/// before wondering why the choice never sticks.
/// </remarks>
[TestFixture]
public sealed class ChatDataSourceDefaultsTests
{
[Test]
public void TheRetrievalModeSurvivesTheSettingsFile()
{
var written = new DataChat { PreselectedDataSourcesRetrievalMode = DataSourceRetrievalMode.EVERY_MESSAGE };
var json = JsonSerializer.Serialize(written, SettingsManager.JSON_OPTIONS);
var read = JsonSerializer.Deserialize<DataChat>(json, SettingsManager.JSON_OPTIONS)!;
Assert.That(read.PreselectedDataSourcesRetrievalMode, Is.EqualTo(DataSourceRetrievalMode.EVERY_MESSAGE), "Semantic search is the default, so only the other choice shows that the settings file keeps it.");
}
[Test]
public void ASettingsFileFromBeforeTheChoiceGetsSemanticSearch()
{
const string LEGACY_JSON = """
{
"PreselectedDataSourceOptions": {
"DisableDataSources": false,
"AutomaticDataSourceSelection": true,
"AutomaticValidation": true,
"PreselectedDataSourceIds": []
}
}
""";
var read = JsonSerializer.Deserialize<DataChat>(LEGACY_JSON, SettingsManager.JSON_OPTIONS)!;
Assert.Multiple(() =>
{
Assert.That(read.PreselectedDataSourcesDisabled, Is.False, "The legacy nested object has to reach the individual fields, or this test checks nothing.");
Assert.That(read.PreselectedDataSourcesRetrievalMode, Is.EqualTo(DataSourceRetrievalMode.SEMANTIC_SEARCH));
});
}
}
@@ -34,6 +34,7 @@ public sealed class ChatTemplateConfigurationTests
DisableDataSources = false,
AutomaticDataSourceSelection = false,
AutomaticValidation = true,
RetrievalMode = DataSourceRetrievalMode.EVERY_MESSAGE,
PreselectedDataSourceIds = ["11111111-1111-1111-1111-111111111111"],
},
};
@@ -47,6 +48,7 @@ public sealed class ChatTemplateConfigurationTests
Assert.That(read.DataSourceOptions!.DisableDataSources, Is.False);
Assert.That(read.DataSourceOptions.AutomaticDataSourceSelection, Is.False);
Assert.That(read.DataSourceOptions.AutomaticValidation, Is.True);
Assert.That(read.DataSourceOptions.RetrievalMode, Is.EqualTo(DataSourceRetrievalMode.EVERY_MESSAGE), "Semantic search is the default, so only the other choice shows that the export carries it.");
Assert.That(read.DataSourceOptions.PreselectedDataSourceIds, Is.EqualTo(written.DataSourceOptions!.PreselectedDataSourceIds));
});
}
@@ -129,10 +131,34 @@ public sealed class ChatTemplateConfigurationTests
Assert.That(read.DataSourceOptions!.DisableDataSources, Is.False, "Writing this table is already the statement that the template wants data sources, so an omitted switch must not turn them off again.");
Assert.That(read.DataSourceOptions.AutomaticDataSourceSelection, Is.False);
Assert.That(read.DataSourceOptions.AutomaticValidation, Is.False);
Assert.That(read.DataSourceOptions.RetrievalMode, Is.EqualTo(DataSourceRetrievalMode.SEMANTIC_SEARCH));
Assert.That(read.DataSourceOptions.PreselectedDataSourceIds, Is.EqualTo(new[] { "11111111-1111-1111-1111-111111111111" }));
});
}
[TestCase("'EVERY_MESSAGE'", DataSourceRetrievalMode.EVERY_MESSAGE)]
[TestCase("'every_message'", DataSourceRetrievalMode.EVERY_MESSAGE)]
[TestCase("'1'", DataSourceRetrievalMode.SEMANTIC_SEARCH)]
[TestCase("1", DataSourceRetrievalMode.SEMANTIC_SEARCH)]
[TestCase("'SEMANTIC_SEARCH, EVERY_MESSAGE'", DataSourceRetrievalMode.SEMANTIC_SEARCH)]
[TestCase("'every message'", DataSourceRetrievalMode.SEMANTIC_SEARCH)]
[TestCase("true", DataSourceRetrievalMode.SEMANTIC_SEARCH)]
public async Task OnlyTheNameOfARetrievalModeCounts(string luaValue, DataSourceRetrievalMode expectedMode)
{
var read = await ParseAsync($$"""
CONFIG["CHAT_TEMPLATES"][#CONFIG["CHAT_TEMPLATES"]+1] = {
["Id"] = "33333333-3333-3333-3333-333333333333",
["Name"] = "Intranet Research",
["SystemPrompt"] = "You are a research assistant.",
["DataSourceOptions"] = {
["RetrievalMode"] = {{luaValue}},
},
}
""");
Assert.That(read.DataSourceOptions!.RetrievalMode, Is.EqualTo(expectedMode), "Parsing alone would read a number, or several names at once, as searching with every message.");
}
[Test]
public async Task AnUnusableEntryIsSkippedAndTheRestOfTheListSurvives()
{
+61
View File
@@ -0,0 +1,61 @@
using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
namespace AIStudio.Tests.Settings;
/// <summary>
/// Checks that a value written by hand counts only when it names one member of its enum.
/// </summary>
/// <remarks>
/// Enum.TryParse reads a number and several names at once as well. Neither is a mistake it
/// reports: both come back as some value, often one which a member has, so a configuration which
/// meant nothing of the sort gets a choice nobody wrote.
/// </remarks>
[TestFixture]
public sealed class EnumNamesTests
{
[TestCase("EVERY_MESSAGE")]
[TestCase("every_message")]
[TestCase(" Every_Message ")]
public void ANameCountsWhateverItsCase(string text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out var mode), Is.True);
Assert.That(mode, Is.EqualTo(DataSourceRetrievalMode.EVERY_MESSAGE));
}
[TestCase("1")]
[TestCase("-1")]
[TestCase("0x1")]
public void ANumberDoesNotCountEvenWhenAMemberHasIt(string text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out _), Is.False, "Enum.TryParse would read 1 as EVERY_MESSAGE.");
}
[Test]
public void SeveralNamesDoNotCount()
{
Assert.Multiple(() =>
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>("SEMANTIC_SEARCH, EVERY_MESSAGE", out _), Is.False, "Enum.TryParse would combine them to EVERY_MESSAGE.");
Assert.That(EnumNames.TryParse<ConfidenceLevel>("HIGH, MEDIUM", out _), Is.False, "Enum.TryParse would combine them to a confidence level above HIGH.");
});
}
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
[TestCase("EVERY MESSAGE")]
public void NoNameDoesNotCount(string? text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out var mode), Is.False);
Assert.That(mode, Is.EqualTo(default(DataSourceRetrievalMode)));
}
[Test]
public void TheEnumMayBeGivenAsAType()
{
Assert.That(EnumNames.TryParse(typeof(ConfidenceLevel), "moderate", out var level), Is.True);
Assert.That(level, Is.EqualTo(ConfidenceLevel.MODERATE));
}
}