feat: reorganize admin llm settings
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Security.Cryptography;
|
||||
using MiaoJiZhang.Api.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace MiaoJiZhang.Api.Tests;
|
||||
|
||||
public sealed class LlmSecretProtectorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Protect_RoundTripsWithoutEmbeddingPlaintext()
|
||||
{
|
||||
var encryptionKey = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["Secrets:EncryptionKey"] = encryptionKey,
|
||||
})
|
||||
.Build();
|
||||
var protector = new LlmSecretProtector(configuration);
|
||||
|
||||
var encrypted = protector.Protect("sk-test-secret-1234");
|
||||
|
||||
Assert.DoesNotContain("sk-test-secret-1234", encrypted);
|
||||
Assert.Equal("sk-test-secret-1234", protector.Unprotect(encrypted));
|
||||
Assert.Equal("••••1234", LlmSecretProtector.Mask("sk-test-secret-1234"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Protect_RejectsMissingEncryptionKey()
|
||||
{
|
||||
var protector = new LlmSecretProtector(new ConfigurationBuilder().Build());
|
||||
|
||||
var exception = Assert.Throws<InvalidOperationException>(
|
||||
() => protector.Protect("sk-test"));
|
||||
|
||||
Assert.Contains("Secrets__EncryptionKey", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Defaults_UseStableGenerationParameters()
|
||||
{
|
||||
Assert.Equal("1024", AppConfigDefaults.Values["llm.max_tokens"]);
|
||||
Assert.Equal("0.7", AppConfigDefaults.Values["llm.temperature"]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user