Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { readdir, readFile } from "node:fs/promises";
|
||||
import { dirname, extname, join, relative, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const sourceRoot = dirname(fileURLToPath(import.meta.url));
|
||||
const forbiddenImportPattern = /(?:from\s+["']|import\s*\(\s*["'])(~\/|app\/|@toolctrl\/(?:db|config)(?:\/|$)|react(?:\/|$)|react-router(?:\/|$)|stripe(?:\/|$)|@prisma\/client(?:\/|$)|\.prisma\/client(?:\/|$)|prisma(?:\/|$))/;
|
||||
const diagnosticTemplatePattern = /(?:message\s*[:=]|new\s+\w*Error\s*\()[^;\n]*/g;
|
||||
const unsafeDiagnosticPattern = /tenant|customer|user|api[-_\s]?key|subscription[-_\s]?id|secret|sk_[a-z0-9]/i;
|
||||
|
||||
async function collectSourceFiles(directory: string): Promise<readonly string[]> {
|
||||
const entries = await readdir(directory, { withFileTypes: true });
|
||||
const files = await Promise.all(
|
||||
entries.map(async (entry) => {
|
||||
const entryPath = join(directory, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
return collectSourceFiles(entryPath);
|
||||
}
|
||||
|
||||
const isSourceFile = extname(entryPath) === ".ts" && !entryPath.endsWith(".test.ts");
|
||||
|
||||
return isSourceFile ? [entryPath] : [];
|
||||
}),
|
||||
);
|
||||
|
||||
return files.flat();
|
||||
}
|
||||
|
||||
function toPackageRelativePath(absolutePath: string): string {
|
||||
return relative(sourceRoot, absolutePath).split(sep).join("/");
|
||||
}
|
||||
|
||||
describe("entitlements package boundary", () => {
|
||||
it("keeps runtime source files free of app and framework imports", async () => {
|
||||
const sourceFiles = await collectSourceFiles(sourceRoot);
|
||||
|
||||
expect(sourceFiles.map(toPackageRelativePath).sort()).toEqual([
|
||||
"blueprints.ts",
|
||||
"evaluate.ts",
|
||||
"features.ts",
|
||||
"index.ts",
|
||||
"plans.ts",
|
||||
"product-access.ts",
|
||||
]);
|
||||
|
||||
for (const sourceFile of sourceFiles) {
|
||||
const source = await readFile(sourceFile, "utf8");
|
||||
|
||||
expect(source, toPackageRelativePath(sourceFile)).not.toMatch(forbiddenImportPattern);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps exported diagnostic templates free of identifiers and secrets", async () => {
|
||||
const exportedSourceFiles = [join(sourceRoot, "features.ts"), join(sourceRoot, "evaluate.ts")];
|
||||
|
||||
for (const sourceFile of exportedSourceFiles) {
|
||||
const source = await readFile(sourceFile, "utf8");
|
||||
const diagnosticTemplates = source.match(diagnosticTemplatePattern) ?? [];
|
||||
|
||||
expect(diagnosticTemplates.join("\n"), toPackageRelativePath(sourceFile)).not.toMatch(unsafeDiagnosticPattern);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user