build-flow.api/tests/BuildFlow.Architecture.Tests/RagKnowledgeBaseValidatorTests.cs
2026-07-24 12:29:06 +08:00

47 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace BuildFlow.Architecture.Tests;
using Xunit;
/// <summary>
/// RAG 知识库 HTTP 校验器的契约测试。确保 Host 入口允许的策略范围与应用层保持一致。
/// </summary>
public class RagKnowledgeBaseValidatorTests
{
[Theory]
[InlineData("CreateKnowledgeBaseRequestValidator.cs")]
[InlineData("UpdateKnowledgeBaseRequestValidator.cs")]
public void KnowledgeBaseValidatorsShouldAllowAllImplementedChunkingModes(string fileName)
{
var repoRoot = FindRepoRoot();
var validatorPath = Path.Combine(
repoRoot.FullName,
"src",
"BuildFlow.Host",
"Endpoints",
"Rag",
"KnowledgeBase",
fileName);
var source = System.IO.File.ReadAllText(validatorPath);
Assert.Contains(".InclusiveBetween(0, 5)", source);
Assert.DoesNotContain(".InclusiveBetween(0, 2).When(x => x.ChunkingMode.HasValue)", source);
Assert.Contains("0=General,1=Heading,2=ParentChild,3=Separator,4=ByPage,5=Token", source);
}
private static DirectoryInfo FindRepoRoot()
{
var current = new DirectoryInfo(AppContext.BaseDirectory);
while (current is not null)
{
if (System.IO.File.Exists(Path.Combine(current.FullName, "BuildFlow.slnx")))
{
return current;
}
current = current.Parent;
}
throw new InvalidOperationException("无法定位 BuildFlow.slnx,无法验证 RAG 知识库校验器。");
}
}