mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-05 04:27:21 +00:00
Upgraded to .NET 10 (#1147)
This commit is contained in:
1 parent
faae2951f7
commit
fc7399e81b
327 files changed
+3059
-3049
No files matched your search
@@ -74,7 +74,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var (original, snippet) = Export(type);
|
||||
var imported = Import(snippet, type).ConfigurationObject;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(Guid.TryParse(imported.Id, out _), Is.True, "Every configuration object needs a GUID as its ID.");
|
||||
Assert.That(imported.Id, Is.Not.EqualTo(original.Id).And.Not.EqualTo(ExportedId(snippet, type)), "Importing the same snippet twice must not create two objects with one ID.");
|
||||
@@ -82,7 +82,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
Assert.That(imported.IsEnterpriseConfiguration, Is.False);
|
||||
Assert.That(imported.EnterpriseConfigurationPluginId, Is.EqualTo(Guid.Empty));
|
||||
Assert.That(imported.Name, Is.EqualTo(original.Name));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -108,7 +108,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var template = (ChatTemplate)original;
|
||||
var imported = (ChatTemplate)Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE).ConfigurationObject;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(imported.SystemPrompt, Is.EqualTo(template.SystemPrompt));
|
||||
Assert.That(imported.PredefinedUserPrompt, Is.EqualTo(template.PredefinedUserPrompt));
|
||||
@@ -121,7 +121,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
Assert.That(imported.ProviderId, Is.EqualTo(template.ProviderId));
|
||||
Assert.That(imported.ProfileId, Is.EqualTo(template.ProfileId));
|
||||
Assert.That(imported.WorkspaceName, Is.EqualTo(template.WorkspaceName));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -131,7 +131,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var policy = (DataDocumentAnalysisPolicy)original;
|
||||
var imported = (DataDocumentAnalysisPolicy)Import(snippet, PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY).ConfigurationObject;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(imported.IsProtected, Is.False, "A configuration plugin protects its policies; the user's own policy is the user's to edit.");
|
||||
Assert.That(imported.PolicyDescription, Is.EqualTo(policy.PolicyDescription));
|
||||
@@ -142,7 +142,7 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
Assert.That(imported.PreselectedProvider, Is.EqualTo(policy.PreselectedProvider));
|
||||
Assert.That(imported.PreselectedProfile, Is.EqualTo(policy.PreselectedProfile));
|
||||
Assert.That(imported.HidePolicyDefinition, Is.EqualTo(policy.HidePolicyDefinition));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -150,22 +150,22 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
{
|
||||
const string PROFILE_WITHOUT_ACTIONS = """CONFIG["PROFILES"][#CONFIG["PROFILES"]+1] = { ["Id"] = "6b8e1a2c-3d4f-4a5b-9c6d-7e8f9a0b1c2d", ["Name"] = "Writer", ["NeedToKnow"] = "I write." }""";
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(ConfigurationSnippetImport.TryImport(PROFILE_WITHOUT_ACTIONS, PluginConfigurationObjectType.PROFILE, out var result, out var issue), Is.False);
|
||||
Assert.That(result, Is.Null);
|
||||
Assert.That(issue, Is.Not.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASnippetWhichCannotBeReadIsRefused()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(ConfigurationSnippetImport.TryImport("CONFIG[\"PROFILES\"] = os.getenv(\"HOME\")", PluginConfigurationObjectType.PROFILE, out _, out var issue), Is.False);
|
||||
Assert.That(issue, Is.Not.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -175,11 +175,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
{
|
||||
var result = Import(ExportProvider(type, Encrypt(API_KEY)).Snippet, type);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Secret, Is.EqualTo(API_KEY));
|
||||
Assert.That(result.Hints, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -226,11 +226,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
""");
|
||||
|
||||
var imported = (IUserProvidedAPIKey)Import(snippetWithPrompt, type).ConfigurationObject;
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(imported.PromptForUserAPIKey, Is.False);
|
||||
Assert.That(imported.AllowUserProvidedAPIKey, Is.False);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -274,12 +274,12 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var result = Import(snippet, PluginConfigurationObjectType.DATA_SOURCE);
|
||||
var dataSource = (DataSourceERI_V1)result.ConfigurationObject;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(dataSource.Username, Is.EqualTo(expectedUsername));
|
||||
Assert.That(dataSource.UsernamePasswordMode, Is.EqualTo(DataSourceERIUsernamePasswordMode.USER_MANAGED), "Only an organization manages the sign-in for its users.");
|
||||
Assert.That(result.Secret, Is.EqualTo(TOKEN));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(null, OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, TestName = "A data source without a level gets the one of a new data source")]
|
||||
@@ -312,11 +312,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var result = Import(ExportChatTemplate([existing, missing, RELATIVE, WINDOWS_SHARE, UNIX_SHARE]), PluginConfigurationObjectType.CHAT_TEMPLATE);
|
||||
var template = (ChatTemplate)result.ConfigurationObject;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(template.FileAttachments.Select(attachment => attachment.FilePath), Is.EqualTo(new[] { existing }));
|
||||
Assert.That(result.AttachmentsToRelink, Is.EqualTo(new[] { missing, RELATIVE, WINDOWS_SHARE, UNIX_SHARE }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -333,11 +333,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
{
|
||||
var result = Import(ExportChatTemplate([]), PluginConfigurationObjectType.CHAT_TEMPLATE);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Is.Empty);
|
||||
Assert.That(result.AttachmentsToRelink, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -349,11 +349,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var copy = this.CreateTokenizerCopy(type, original.Id);
|
||||
var result = Import(snippet, type);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TokenizerPathOf(result.ConfigurationObject), Is.EqualTo(copy), "Imported on the computer it came from, the export leads back to the copy of the provider.");
|
||||
Assert.That(result.Hints, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -368,11 +368,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var storedFingerprint = await TokenizerFingerprint.KeepOrReadAsync(imported.TokenizerPath, imported.TokenizerFingerprint);
|
||||
var fingerprintOfTheCopiedFile = await TokenizerFingerprint.ForFileAsync(copy);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(imported.TokenizerFingerprint, Is.Empty, "The import reads no file before the user agreed to it.");
|
||||
Assert.That(storedFingerprint, Is.Not.Empty.And.EqualTo(fingerprintOfTheCopiedFile), "Without the fingerprint, the embedding signature cannot tell the tokenizer apart from no tokenizer at all.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -381,11 +381,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
{
|
||||
var result = Import(ExportProvider(type, null, Path.Combine(this.temporaryDirectory, "missing-tokenizer.json")).Snippet, type);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TokenizerPathOf(result.ConfigurationObject), Is.Empty, "Saving the provider would fail on a tokenizer which cannot be copied.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains("missing-tokenizer.json"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -395,11 +395,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var tokenizer = this.CreateFile("tokenizer.json");
|
||||
var result = Import(ExportProviderWithTokenizerPath(type, tokenizer), type);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TokenizerPathOf(result.ConfigurationObject), Is.EqualTo(tokenizer), "Versions before v26.10.1 exported the absolute path of the tokenizer.");
|
||||
Assert.That(result.Hints, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(PluginConfigurationObjectType.LLM_PROVIDER)]
|
||||
@@ -410,11 +410,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
File.WriteAllText(Path.Combine(this.dataDirectory, "settings.json"), "{}");
|
||||
var result = Import(ExportProviderWithTokenizerPath(type, "tokenizers/../settings.json"), type);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TokenizerPathOf(result.ConfigurationObject), Is.Empty, "Only the folder of the tokenizers holds what an export may name.");
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -424,14 +424,14 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var snippet = ExportPolicy(preselectedProvider: "missing-provider", preselectedProfile: missingProfileId, allowedToolIds: [TOOL_ID, "missing_tool"]);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(3), "One sentence for each kind of reference.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains("missing-provider"));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingProfileId));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains("missing_tool"));
|
||||
Assert.That(result.Hints, Has.None.Contains(TOOL_ID), "The tool exists.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -443,14 +443,14 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var snippet = ExportChatTemplate([], toolIds: [TOOL_ID, "missing_tool"], dataSourceIds: [missingDataSourceId], providerId: missingProviderId, profileId: missingProfileId);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(4), "One sentence for each kind of reference.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingDataSourceId));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains("missing_tool"));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingProviderId));
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(missingProfileId));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -459,11 +459,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var snippet = ExportChatTemplate([], profileId: Profile.NO_PROFILE.Id);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Is.Empty, "Starting without a profile is a statement, not a reference to a profile which could be missing.");
|
||||
Assert.That(((ChatTemplate)result.ConfigurationObject).ProfileId, Is.EqualTo(Profile.NO_PROFILE.Id));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -478,11 +478,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var snippet = ExportChatTemplate([], providerId: provider.Id);
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1), "The provider exists, but chats started with the template would not use it.");
|
||||
Assert.That(result.Hints, Has.Exactly(1).Contains(provider.InstanceName));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -494,11 +494,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
|
||||
var result = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(snippet, PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, this.CreateRegistry(new TestTool(Definition())));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1), "Whether the profile exists does not matter, since chats ignore it anyway.");
|
||||
Assert.That(result.Hints, Has.None.Contains(missingProfileId));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -515,11 +515,11 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var policy = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportPolicy(provider.Id, profile.Id, [TOOL_ID]), PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY), this.SettingsManager, registry);
|
||||
var template = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportChatTemplate([], [TOOL_ID], [dataSource.Id], provider.Id, profile.Id), PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, registry);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(policy.Hints, Is.Empty);
|
||||
Assert.That(template.Hints, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -531,13 +531,13 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var policy = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportPolicy(allowedToolIds: [TOOL_ID]), PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY), this.SettingsManager, registry);
|
||||
var template = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportChatTemplate([], [TOOL_ID]), PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, registry);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(((DataDocumentAnalysisPolicy)policy.ConfigurationObject).AllowedToolIds, Is.EquivalentTo(new[] { COLLECTION_ID }));
|
||||
Assert.That(((ChatTemplate)template.ConfigurationObject).ToolIds, Is.EquivalentTo(new[] { COLLECTION_ID }));
|
||||
Assert.That(policy.Hints, Is.Empty);
|
||||
Assert.That(template.Hints, Is.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -549,13 +549,13 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
var policy = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportPolicy(allowedToolIds: [TOOL_ID]), PluginConfigurationObjectType.DOCUMENT_ANALYSIS_POLICY), this.SettingsManager, registry);
|
||||
var template = await ConfigurationSnippetImport.ResolveReferencesAsync(Import(ExportChatTemplate([], [TOOL_ID]), PluginConfigurationObjectType.CHAT_TEMPLATE), this.SettingsManager, registry);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(policy.Hints, Is.Empty, "The tool exists on this computer; switching it on again makes the policy use it.");
|
||||
Assert.That(template.Hints, Is.Empty);
|
||||
Assert.That(((DataDocumentAnalysisPolicy)policy.ConfigurationObject).AllowedToolIds, Is.EquivalentTo(new[] { TOOL_ID }), "The import keeps the tool.");
|
||||
Assert.That(((ChatTemplate)template.ConfigurationObject).ToolIds, Is.EquivalentTo(new[] { TOOL_ID }));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -574,21 +574,21 @@ public sealed class ConfigurationSnippetImportTests : ToolRegistryTestBase
|
||||
|
||||
private static void AssertRefused(string snippet, PluginConfigurationObjectType type)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(ConfigurationSnippetImport.TryImport(snippet, type, out var result, out var issue), Is.False);
|
||||
Assert.That(result, Is.Null);
|
||||
Assert.That(issue, Is.Not.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertAPIKeyLeftOut(ConfigurationSnippetImportResult result)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.Secret, Is.Empty);
|
||||
Assert.That(result.Hints, Has.Count.EqualTo(1), "The provider is imported, but the user has to enter a key.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user