sln build fix (again), tests fixes, audit work and doctors work
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Doctor.Models;
|
||||
using StellaOps.Doctor.Plugins;
|
||||
using StellaOps.Doctor.Plugins.AI;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Doctor.Plugins.AI.Tests;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class AIPluginTests
|
||||
{
|
||||
[Fact]
|
||||
public void PluginId_ReturnsExpectedValue()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
|
||||
Assert.Equal("stellaops.doctor.ai", plugin.PluginId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisplayName_ReturnsExpectedValue()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
|
||||
Assert.Equal("AI / LLM", plugin.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Category_ReturnsAI()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
|
||||
Assert.Equal(DoctorCategory.AI, plugin.Category);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Version_ReturnsValidVersion()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
|
||||
Assert.NotNull(plugin.Version);
|
||||
Assert.True(plugin.Version >= new Version(1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MinEngineVersion_ReturnsValidVersion()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
|
||||
Assert.NotNull(plugin.MinEngineVersion);
|
||||
Assert.True(plugin.MinEngineVersion >= new Version(1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsAvailable_ReturnsTrue()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
|
||||
Assert.True(plugin.IsAvailable(services));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ReturnsFiveChecks()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Equal(5, checks.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsLlmProviderConfigurationCheck()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.ai.llm.config");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsClaudeProviderCheck()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.ai.provider.claude");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsOpenAiProviderCheck()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.ai.provider.openai");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsOllamaProviderCheck()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.ai.provider.ollama");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsLocalInferenceCheck()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.ai.provider.local");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeAsync_CompletesSuccessfully()
|
||||
{
|
||||
var plugin = new AIPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
await plugin.InitializeAsync(context, CancellationToken.None);
|
||||
|
||||
// Should complete without throwing
|
||||
}
|
||||
|
||||
private static DoctorPluginContext CreateTestContext(IConfiguration? configuration = null)
|
||||
{
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
configuration ??= new ConfigurationBuilder().Build();
|
||||
|
||||
return new DoctorPluginContext
|
||||
{
|
||||
Services = services,
|
||||
Configuration = configuration,
|
||||
TimeProvider = TimeProvider.System,
|
||||
Logger = NullLogger.Instance,
|
||||
EnvironmentName = "Test",
|
||||
PluginConfig = configuration.GetSection("Doctor:Plugins:AI")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Doctor.Models;
|
||||
using StellaOps.Doctor.Plugins;
|
||||
using StellaOps.Doctor.Plugins.AI.Checks;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Doctor.Plugins.AI.Tests.Checks;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class LlmProviderConfigurationCheckTests
|
||||
{
|
||||
[Fact]
|
||||
public void CheckId_ReturnsExpectedValue()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
|
||||
Assert.Equal("check.ai.llm.config", check.CheckId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_ReturnsExpectedValue()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
|
||||
Assert.Equal("LLM Configuration", check.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultSeverity_IsInfo()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
|
||||
Assert.Equal(DoctorSeverity.Info, check.DefaultSeverity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tags_ContainsAi()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
|
||||
Assert.Contains("ai", check.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tags_ContainsLlm()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
|
||||
Assert.Contains("llm", check.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanRun_ReturnsTrue()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
var context = CreateTestContext();
|
||||
|
||||
Assert.True(check.CanRun(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RunAsync_WhenAiDisabled_ReturnsInfoResult()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["AdvisoryAI:Enabled"] = "false"
|
||||
})
|
||||
.Build();
|
||||
var context = CreateTestContext(config);
|
||||
|
||||
var result = await check.RunAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(DoctorSeverity.Info, result.Severity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RunAsync_WhenNoProvidersConfigured_ReturnsInfoResult()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var result = await check.RunAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(DoctorSeverity.Info, result.Severity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RunAsync_WhenClaudeConfigured_ReturnsPassResult()
|
||||
{
|
||||
var check = new LlmProviderConfigurationCheck();
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["AdvisoryAI:LlmProviders:Claude:ApiKey"] = "test-api-key"
|
||||
})
|
||||
.Build();
|
||||
var context = CreateTestContext(config);
|
||||
|
||||
var result = await check.RunAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(DoctorSeverity.Pass, result.Severity);
|
||||
}
|
||||
|
||||
private static DoctorPluginContext CreateTestContext(IConfiguration? configuration = null)
|
||||
{
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
configuration ??= new ConfigurationBuilder().Build();
|
||||
|
||||
return new DoctorPluginContext
|
||||
{
|
||||
Services = services,
|
||||
Configuration = configuration,
|
||||
TimeProvider = TimeProvider.System,
|
||||
Logger = NullLogger.Instance,
|
||||
EnvironmentName = "Test",
|
||||
PluginConfig = configuration.GetSection("Doctor:Plugins:AI")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="Moq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\StellaOps.Doctor\StellaOps.Doctor.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Doctor.Plugins.AI\StellaOps.Doctor.Plugins.AI.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.TestKit\StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user