test: 固化应用平台下沉前的兼容与分层契约
覆盖任意深度域 API、应用平台子模块方向和跨模块循环检测。 锁定应用列表基础与详情投影、缺省字段、清洗及详情参数的既有差异。 验证:943 项测试、类型和版本检查通过。
This commit is contained in:
1 parent
3345ce9b39
commit
edf300b808
2 files changed
+113
-2
No files matched your search
@@ -39,6 +39,30 @@ function resolveImportRelativeToSrc(fromFile: string, specifier: string): string
|
||||
return path ? relative(SRC_ROOT, path.replace(/\.[jt]s$/, "")).replaceAll("\\", "/") : null;
|
||||
}
|
||||
|
||||
function platformModule(path: string): string | undefined {
|
||||
return path.match(/^domains\/platform\/(applications|datalink|workflow)\//)?.[1];
|
||||
}
|
||||
|
||||
function platformDependencyViolation(from: string, to: string): boolean {
|
||||
const source = platformModule(from), target = platformModule(to);
|
||||
if (!source || !target || source === target) return false;
|
||||
return /\/api$/.test(to) || source === "applications" || (source === "datalink" && target === "workflow");
|
||||
}
|
||||
|
||||
function findCycles(graph: Map<string, Set<string>>): string[][] {
|
||||
const done = new Set<string>(), active: string[] = [], cycles: string[][] = [];
|
||||
const visit = (node: string) => {
|
||||
const index = active.indexOf(node);
|
||||
if (index >= 0) { cycles.push([...active.slice(index), node]); return; }
|
||||
if (done.has(node)) return;
|
||||
active.push(node);
|
||||
for (const next of graph.get(node) ?? []) visit(next);
|
||||
active.pop(); done.add(node);
|
||||
};
|
||||
for (const node of graph.keys()) visit(node);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
describe("Architecture Layering Boundaries", () => {
|
||||
test("dependency extraction covers aliases, re-exports and literal dynamic/type imports", () => {
|
||||
const imports = extractImportSpecifiers(`
|
||||
@@ -52,6 +76,39 @@ describe("Architecture Layering Boundaries", () => {
|
||||
expect(resolveImportRelativeToSrc(join(SRC_ROOT, "cli", "example.ts"), imports[1])).toBe("domains/bill/api");
|
||||
});
|
||||
|
||||
test("nested APIs and platform dependency directions cannot bypass boundaries", () => {
|
||||
const api = /^domains\/(?:[^/]+\/)+api$/;
|
||||
expect(api.test("domains/platform/workflow/api")).toBe(true);
|
||||
expect(api.test("domains/bill/api")).toBe(true);
|
||||
expect(api.test("domains/platform/workflow/services")).toBe(false);
|
||||
expect(platformDependencyViolation("domains/platform/workflow/services", "domains/platform/applications/services")).toBe(false);
|
||||
expect(platformDependencyViolation("domains/platform/workflow/services", "domains/platform/applications/api")).toBe(true);
|
||||
expect(platformDependencyViolation("domains/platform/applications/types", "domains/platform/datalink/types")).toBe(true);
|
||||
expect(platformDependencyViolation("domains/platform/datalink/services", "domains/platform/workflow/services")).toBe(true);
|
||||
expect(findCycles(new Map([["a", new Set(["b"])], ["b", new Set(["a"])]]))).toEqual([["a", "b", "a"]]);
|
||||
expect(findCycles(new Map([["a", new Set(["b"])], ["b", new Set<string>()]]))).toEqual([]);
|
||||
});
|
||||
|
||||
test("platform submodules respect ownership and have no cross-module cycles", () => {
|
||||
const graph = new Map<string, Set<string>>(), violations: string[] = [];
|
||||
for (const file of collectTsFiles(join(SRC_ROOT, "domains", "platform"))) {
|
||||
const from = relative(SRC_ROOT, file).replaceAll("\\", "/").replace(/\.ts$/, "");
|
||||
const source = platformModule(from);
|
||||
for (const specifier of extractImportSpecifiers(readFileSync(file, "utf8"))) {
|
||||
const target = resolveImportRelativeToSrc(file, specifier);
|
||||
if (!target) continue;
|
||||
if (platformDependencyViolation(from, target)) violations.push(`${from} -> ${target}`);
|
||||
const destination = platformModule(target);
|
||||
if (source && destination && source !== destination) {
|
||||
if (!graph.has(source)) graph.set(source, new Set());
|
||||
graph.get(source)!.add(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(violations).toEqual([]);
|
||||
expect(findCycles(graph)).toEqual([]);
|
||||
});
|
||||
|
||||
test("bill Session HTTP calls stay in the transport module", () => {
|
||||
const violations: string[] = [];
|
||||
for (const file of collectTsFiles(join(SRC_ROOT, "domains", "bill"))) {
|
||||
@@ -85,7 +142,7 @@ describe("Architecture Layering Boundaries", () => {
|
||||
}
|
||||
expect(violations).toEqual([]);
|
||||
});
|
||||
test("Entrypoints (src/cli, src/http, server.ts, cli.ts, aipro-cli.ts) must never import domains/*/api directly", () => {
|
||||
test("Entrypoints (src/cli, src/http, server.ts, cli.ts, aipro-cli.ts) must never import domains/**/api directly", () => {
|
||||
const entrypointFiles = [
|
||||
...collectTsFiles(join(SRC_ROOT, "cli")),
|
||||
...collectTsFiles(join(SRC_ROOT, "http")),
|
||||
@@ -100,7 +157,7 @@ describe("Architecture Layering Boundaries", () => {
|
||||
const specifiers = extractImportSpecifiers(content);
|
||||
for (const spec of specifiers) {
|
||||
const targetRel = resolveImportRelativeToSrc(file, spec);
|
||||
if (targetRel && /^domains\/[^/]+\/api$/.test(targetRel)) {
|
||||
if (targetRel && /^domains\/(?:[^/]+\/)+api$/.test(targetRel)) {
|
||||
violations.push(`${relative(SRC_ROOT, file)} -> ${targetRel}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user