fix: 保留系统字段语义并固化架构示例检查
修正 DataLink 公共 SDK 示例,直接提取 README 中的示例与实际 SDK 一起编译。架构依赖扫描改为 AST,覆盖项目别名、再导出、动态与类型导入,新增单据 Session 传输收口卡点。 收尾回归保留未声明系统键的读取/透传语义,防止 active 被模糊匹配到 inactive 业务标签。同步模块导航、单工具 MCP 与认证说明,记录七项问题的实际修复、兼容选择和验证范围。 验证:bun test 926 通过、0 失败(119 文件、4379 断言);bun run check、bun run check:version、git diff --check 与文档链接检查通过。版本维持 0.8.21,未操作真实企业。
This commit is contained in:
1 parent
55d31e27e6
commit
6249feee23
11 files changed
+195
-71
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { readdirSync, readFileSync, statSync } from "node:fs";
|
||||
import { dirname, join, relative, resolve } from "node:path";
|
||||
import ts from "typescript";
|
||||
|
||||
const SRC_ROOT = join(import.meta.dir, "..");
|
||||
|
||||
@@ -20,25 +21,59 @@ function collectTsFiles(dir: string, includeTests = false): string[] {
|
||||
|
||||
function extractImportSpecifiers(source: string): string[] {
|
||||
const specifiers: string[] = [];
|
||||
const staticImportRe = /(?:import|export)\s+(?:type\s+)?(?:[\s\S]*?\s+from\s+)?["']([^"']+)["']/g;
|
||||
const dynamicImportRe = /import\(\s*["']([^"']+)["']\s*\)/g;
|
||||
|
||||
for (const match of source.matchAll(staticImportRe)) {
|
||||
if (match[1]) specifiers.push(match[1]);
|
||||
}
|
||||
for (const match of source.matchAll(dynamicImportRe)) {
|
||||
if (match[1]) specifiers.push(match[1]);
|
||||
}
|
||||
const ast = ts.createSourceFile("boundary.ts", source, ts.ScriptTarget.Latest, true);
|
||||
const visit = (node: ts.Node) => {
|
||||
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) specifiers.push(node.moduleSpecifier.text);
|
||||
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments[0] && ts.isStringLiteral(node.arguments[0])) specifiers.push(node.arguments[0].text);
|
||||
if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) specifiers.push(node.argument.literal.text);
|
||||
ts.forEachChild(node, visit);
|
||||
};
|
||||
visit(ast);
|
||||
return specifiers;
|
||||
}
|
||||
|
||||
function resolveImportRelativeToSrc(fromFile: string, specifier: string): string | null {
|
||||
if (!specifier.startsWith(".")) return null;
|
||||
const abs = resolve(dirname(fromFile), specifier).replace(/\.[jt]s$/, "");
|
||||
return relative(SRC_ROOT, abs);
|
||||
const path = specifier.startsWith(".") ? resolve(dirname(fromFile), specifier)
|
||||
: specifier.startsWith("@core/") ? join(SRC_ROOT, "core", specifier.slice(6))
|
||||
: specifier.startsWith("@domains/") ? join(SRC_ROOT, "domains", specifier.slice(9)) : undefined;
|
||||
return path ? relative(SRC_ROOT, path.replace(/\.[jt]s$/, "")).replaceAll("\\", "/") : null;
|
||||
}
|
||||
|
||||
describe("Architecture Layering Boundaries", () => {
|
||||
test("dependency extraction covers aliases, re-exports and literal dynamic/type imports", () => {
|
||||
const imports = extractImportSpecifiers(`
|
||||
import { x } from "@core/errors.js";
|
||||
export { y } from "@domains/bill/api.js";
|
||||
const z = import("../domains/bill/api.js");
|
||||
type T = import("@domains/bill/types.js").FormSpecification;
|
||||
const text = 'import("not-a-real-import")';
|
||||
`);
|
||||
expect(imports).toEqual(["@core/errors.js", "@domains/bill/api.js", "../domains/bill/api.js", "@domains/bill/types.js"]);
|
||||
expect(resolveImportRelativeToSrc(join(SRC_ROOT, "cli", "example.ts"), imports[1])).toBe("domains/bill/api");
|
||||
});
|
||||
|
||||
test("bill Session HTTP calls stay in the transport module", () => {
|
||||
const violations: string[] = [];
|
||||
for (const file of collectTsFiles(join(SRC_ROOT, "domains", "bill"))) {
|
||||
if (file.endsWith("api.ts")) continue;
|
||||
const source = readFileSync(file, "utf8");
|
||||
const ast = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
|
||||
const visit = (node: ts.Node) => {
|
||||
if (ts.isCallExpression(node)) {
|
||||
const expr = node.expression;
|
||||
const receiver = ts.isPropertyAccessExpression(expr) || ts.isElementAccessExpression(expr) ? expr.expression.getText(ast) : "";
|
||||
const method = ts.isPropertyAccessExpression(expr) ? expr.name.text
|
||||
: ts.isElementAccessExpression(expr) && ts.isStringLiteral(expr.argumentExpression) ? expr.argumentExpression.text : "";
|
||||
if (/client|^ky$/i.test(receiver) && ["get", "post", "put", "patch", "delete"].includes(method)) {
|
||||
violations.push(`${relative(SRC_ROOT, file)}:${ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1}`);
|
||||
}
|
||||
}
|
||||
ts.forEachChild(node, visit);
|
||||
};
|
||||
visit(ast);
|
||||
}
|
||||
expect(violations).toEqual([]);
|
||||
});
|
||||
test("workflow imports use the module directories after the platform migration", () => {
|
||||
const legacy = /domains\/platform\/(?:analysis|workflow-(?:alert-store|branch|nodes|script|state|watch))$/;
|
||||
const violations: string[] = [];
|
||||
|
||||
Reference in new issue
Block a user