namespace BuildFlow.Architecture.Tests; using Xunit; /// /// RAG 知识库 HTTP 校验器的契约测试。确保 Host 入口允许的策略范围与应用层保持一致。 /// 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 = 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 (File.Exists(Path.Combine(current.FullName, "BuildFlow.slnx"))) { return current; } current = current.Parent; } throw new InvalidOperationException("无法定位 BuildFlow.slnx,无法验证 RAG 知识库校验器。"); } }