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

59 lines
2.3 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>
/// BuildFlow 低代码按钮权限架构约束。按钮运行时需要查 platform 权限时,
/// 必须通过目标模块 CQRS Query 调用,不能在 Host 注册 in-process service bridge。
/// </summary>
public class BuildFlowButtonCqrsArchitectureTests
{
[Fact]
public void BuildFlowButtonPermissionShouldNotUseHostServiceBridge()
{
var repoRoot = FindRepoRoot();
var sourceFiles = Directory
.EnumerateFiles(Path.Combine(repoRoot.FullName, "src"), "*.cs", SearchOption.AllDirectories)
.Where(path => !ContainsPathSegment(path, "bin") && !ContainsPathSegment(path, "obj"))
.Select(path => new
{
RelativePath = Path.GetRelativePath(repoRoot.FullName, path).Replace('\\', '/'),
Text = System.IO.File.ReadAllText(path),
})
.Where(file =>
file.Text.Contains("IBuildFlowButtonPermissionChecker", StringComparison.Ordinal) ||
file.Text.Contains("InProcessBuildFlowButtonPermissionChecker", StringComparison.Ordinal))
.Select(file => file.RelativePath)
.Order(StringComparer.Ordinal)
.ToArray();
Assert.True(
sourceFiles.Length == 0,
"BuildFlow 按钮权限不能通过 Host service/interface bridge 串联 platform;请在 workflow 命令处理链路中通过 IMediator 发送 platform Query。当前残留:" +
Environment.NewLine +
string.Join(Environment.NewLine, sourceFiles));
}
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,架构测试无法确定仓库边界。");
}
private static bool ContainsPathSegment(string path, string segment)
{
return path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
.Any(part => string.Equals(part, segment, StringComparison.Ordinal));
}
}