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

58 lines
1.8 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 契约测试。确保文档级策略覆盖范围与知识库策略保持一致。
/// </summary>
public class RagDocumentUploadChunkingTests
{
[Fact]
public void UploadDocumentValidatorShouldAllowAllImplementedChunkingModes()
{
var source = ReadDocumentEndpointSource("UploadDocumentRequestValidator.cs");
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);
}
[Fact]
public void UploadDocumentEndpointShouldMapAllImplementedChunkingModes()
{
var source = ReadDocumentEndpointSource("UploadDocumentEndpoint.cs");
Assert.Contains(">= 0 and <= 5", source);
Assert.DoesNotContain(">= 0 and <= 2", source);
}
private static string ReadDocumentEndpointSource(string fileName)
{
var repoRoot = FindRepoRoot();
var path = Path.Combine(
repoRoot.FullName,
"src",
"BuildFlow.Host",
"Endpoints",
"Rag",
"Document",
fileName);
return System.IO.File.ReadAllText(path);
}
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 文档上传契约。");
}
}