diff --git a/tests/BuildFlow.Rag.Tests/AiModelRuntimeConfigResolverTests.cs b/tests/BuildFlow.Rag.Tests/AiModelRuntimeConfigResolverTests.cs index 5658119..9a9d0f2 100644 --- a/tests/BuildFlow.Rag.Tests/AiModelRuntimeConfigResolverTests.cs +++ b/tests/BuildFlow.Rag.Tests/AiModelRuntimeConfigResolverTests.cs @@ -4,7 +4,6 @@ using BuildFlow.Infrastructure.AI; using BuildFlow.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Xunit; namespace BuildFlow.Rag.Tests; @@ -22,14 +21,16 @@ public class AiModelRuntimeConfigResolverTests services.AddDbContext(options => options.UseInMemoryDatabase(dbName)); services.AddScoped(); - services.AddSingleton(Options.Create(new AiOptions - { - BaseUrl = "http://localhost:1234/v1", - ApiKey = "lm-studio", - ChatModel = "fallback-chat", - EmbeddingModel = "fallback-embedding", - DefaultInstructions = "你是 BuildFlow AI 助手。没有知识库上下文时按普通对话直接回答。", - })); + services.AddOptions() + .Configure(options => + { + options.BaseUrl = "http://localhost:1234/v1"; + options.ApiKey = "lm-studio"; + options.ChatModel = "fallback-chat"; + options.EmbeddingModel = "fallback-embedding"; + options.DefaultInstructions = + "你是 BuildFlow AI 助手。没有知识库上下文时按普通对话直接回答。"; + }); await using var provider = services.BuildServiceProvider(); await using (var scope = provider.CreateAsyncScope()) @@ -72,14 +73,15 @@ public class AiModelRuntimeConfigResolverTests services.AddDbContext(options => options.UseInMemoryDatabase(dbName)); services.AddScoped(); - services.AddSingleton(Options.Create(new AiOptions - { - BaseUrl = "https://fallback.example/v1", - ApiKey = "fallback-key", - ChatModel = "fallback-chat", - EmbeddingModel = "fallback-embedding", - DefaultInstructions = "fallback instructions", - })); + services.AddOptions() + .Configure(options => + { + options.BaseUrl = "https://fallback.example/v1"; + options.ApiKey = "fallback-key"; + options.ChatModel = "fallback-chat"; + options.EmbeddingModel = "fallback-embedding"; + options.DefaultInstructions = "fallback instructions"; + }); await using var provider = services.BuildServiceProvider(); await using (var scope = provider.CreateAsyncScope()) diff --git a/tests/BuildFlow.Scripting.Tests/ScriptExecutionServiceTests.cs b/tests/BuildFlow.Scripting.Tests/ScriptExecutionServiceTests.cs index c5a5d84..3208c59 100644 --- a/tests/BuildFlow.Scripting.Tests/ScriptExecutionServiceTests.cs +++ b/tests/BuildFlow.Scripting.Tests/ScriptExecutionServiceTests.cs @@ -1,4 +1,5 @@ using BuildFlow.Shared.Domain.Common; +using BuildFlow.Shared.Domain.Errors; using BuildFlow.Shared.Domain.Exceptions; using FluentAssertions; using MediatR; @@ -99,9 +100,11 @@ public class ScriptExecutionServiceTests var act = () => svc.ExecuteByIdAsync(script.Id, "{}", CancellationToken.None); - (await act.Should().ThrowAsync()) - .WithMessage("*禁用*") - .Which.Message.Should().Contain("File"); + var exception = (await act.Should().ThrowAsync()) + .WithMessage("*禁用 API*") + .Which; + exception.Code.Should().Be(ErrorCode.Business); + exception.Message.Should().Contain("System.IO"); } // ── §13 #4: SANDBOX — Reflection 被拦截 ────────────────────────────────