test: restore green solution baseline

This commit is contained in:
xiangning 2026-07-23 17:49:48 +08:00
parent 6c9cde1e23
commit 09ced1cd32
2 changed files with 25 additions and 20 deletions

View File

@ -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<RagDbContext>(options =>
options.UseInMemoryDatabase(dbName));
services.AddScoped<AiModelRuntimeConfigResolver>();
services.AddSingleton(Options.Create(new AiOptions
services.AddOptions<AiOptions>()
.Configure(options =>
{
BaseUrl = "http://localhost:1234/v1",
ApiKey = "lm-studio",
ChatModel = "fallback-chat",
EmbeddingModel = "fallback-embedding",
DefaultInstructions = "你是 BuildFlow AI 助手。没有知识库上下文时按普通对话直接回答。",
}));
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<RagDbContext>(options =>
options.UseInMemoryDatabase(dbName));
services.AddScoped<AiModelRuntimeConfigResolver>();
services.AddSingleton(Options.Create(new AiOptions
services.AddOptions<AiOptions>()
.Configure(options =>
{
BaseUrl = "https://fallback.example/v1",
ApiKey = "fallback-key",
ChatModel = "fallback-chat",
EmbeddingModel = "fallback-embedding",
DefaultInstructions = "fallback instructions",
}));
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())

View File

@ -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<BusinessException>())
.WithMessage("*禁用*")
.Which.Message.Should().Contain("File");
var exception = (await act.Should().ThrowAsync<BusinessException>())
.WithMessage("*禁用 API*")
.Which;
exception.Code.Should().Be(ErrorCode.Business);
exception.Message.Should().Contain("System.IO");
}
// ── §13 #4: SANDBOX — Reflection 被拦截 ────────────────────────────────